Repository navigation
Conversation
…s in object files
… and clarify reference errors
Deploying infrahub-sdk-python with
|
| Latest commit: |
89a513c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0d0bc6ab.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://atg-strict-waves-stop.infrahub-sdk-python.pages.dev |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## stable #1432 +/- ##
==========================================
+ Coverage 85.06% 85.18% +0.12%
==========================================
Files 148 148
Lines 13303 13347 +44
Branches 1960 1965 +5
==========================================
+ Hits 11316 11370 +54
+ Misses 1422 1411 -11
- Partials 565 566 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 7 files with indirect coverage changes 🚀 New features to boost your workflow:
|
SummaryHFID-only references to a generic peer fail with a Bugs introduced by this PR1. An HFID-only reference to a
|
|
Infrahub CI passed against this branch: opsmill/infrahub#11303 (Infrahub
|
- Search only node kinds, so profile and template kinds in the generic's used_by no longer make client.get raise a ValueError. - Send the id of the matching node, so released servers fill computed attributes and do not look the node up again. - Send a plain string as before when the generic has a default_filter. - Name the list item in errors for cardinality-many relationships. - Mention data: when a dict has kind and other keys but no hfid. - Remove the unused normalize_hfid_references helper. - Mock GraphQL with httpx_mock in the HFID-only tests.
|
Reply to #1432 (comment). All findings were checked against the code, and all six are correct. Fixed in 31faec0 and 89a513c.
Clean-up
Test coverage: the HFID-only tests now answer the GraphQL requests with SDK or server: we keep HFID-only resolution in the SDK for now, because it works with Infrahub servers that are already released. Moving it to the server, in |
|
Infrahub CI passed against the review fixes: opsmill/infrahub#11303, with Infrahub
|
Why
Some relationships point to a generic rather than to one node kind. An example is a sub-interface's
parent_interface, which can be a physical interface or a port-channel. When the generic has no human-friendly ID (HFID) but the node kinds that inherit from it do, an object file cannot reference an existing peer by its HFID. The SDK sends the HFID without a kind, and the server looks it up on the generic and fails with "schema '' does not have a HFID defined".The workarounds change the schema only to suit the loader:
Goal: object file authors can reference these peers without changing the schema.
Non-goals: no change to the Infrahub server, and no synchronous version of the object file API, which is asynchronous only today.
What changed
What users will notice:
A reference can name the node kind and the HFID:
This works for cardinality-one and cardinality-many relationships. The SDK passes
kindwithhfidto the server, which usesRelatedNodeInput.kindto look up HFIDs on generic relationships.When the generic has no HFID, a reference can be the HFID alone, as in
parent_interface: [router1, Gi0/0/3]. The loader searches the kinds in the generic'sused_bywhose HFID has the same number of values. It links the node when exactly one matches. When none or more than one matches, the load stops with an error that names the kinds and asks forkind:.infrahubctl object validatereports the reference errors that the schema alone can detect:kindandhfidValidation does not check that the peer exists, because the peer can be created earlier in the same load. A missing or ambiguous peer is reported at load time.
What stays the same:
kindplusdata) behave as before. A unit test covers nested objects on a generic peer.How to review
infrahub_sdk/spec/object.py, which holds all logic changes:get_relationship_info(how values are classified)_validate_kind_hfid_reference(schema checks)_clean_referenceand_resolve_generic_hfid(load-time resolution)tests/unit/sdk/spec/test_object.pyandTestSpecObjectGenericPeerintests/integration/test_spec_object.py.docs/docs/python-sdk/topics/object_file.mdxhas the new section "Reference a node through a generic relationship".dev/specs/002-generic-peer-hfid/holds the spec, plan, tasks and implementation report. These files are not code.Parts that need extra scrutiny:
id. It is now resolved as an HFID and fails if nothing matches. It is not known whether the server accepted the old form.Alternatives considered (see research.md):
Kind:router1/Gi0/0/3. Rejected because names can contain/and:.How to test
Local results after the review fixes:
GenericPeertests passed.test_spec_object.pypassed (16 tests).Impact & rollout
kind, and HFID-alone references to generics, need Infrahub 1.1.0 or later. That release addedRelatedNodeInput.kind(server commitc4fa580582). The compatibility page still lists 0.16.x and 1.0.x, and this PR does not change it.Checklist
changelog/+generic-peer-hfid.added.md)docs/docs/python-sdk/topics/object_file.mdx)Summary by cubic
Lets object files reference existing nodes through relationships whose peer is a generic, by giving the node's
kindandhfidtogether. Previously these peers could only be referenced through schema workarounds: narrowing the relationship to one node kind or adding an HFID to the generic.Behavior
{kind: <NodeKind>, hfid: [...]}on cardinality-one and cardinality-many relationships;kindis passed withhfidso the server resolves the generic peer against the named kind.used_byare skipped.infrahubctl object validatereports schema-detectable errors: a kind that does not inherit from the peer, an unknown kind, a kind without an HFID, a wrong number of HFID values, and keys other thankindandhfid.Rollout and compatibility
id.RelatedNodeInput.kind; HFID-alone references on generics do not, because the SDK sends the resolved id.Written for commit 89a513c. Summary will update on new commits.