Skip to content

Probe/yang compliant choice encoding (Targeting PR #168) - #173

Open
vinpatel24 wants to merge 3 commits into
Juniper:masterfrom
vinpatel24:probe/yang-compliant-choice-encoding
Open

vinpatel24 wants to merge 3 commits into
Juniper:masterfrom
vinpatel24:probe/yang-compliant-choice-encoding

Conversation

@vinpatel24

Copy link
Copy Markdown
Collaborator

Refs #168, not Closes #168

Summary

Adds tools/choice-probe/, a NETCONF probe that validates the core assumption
behind #168 against real devices. No provider or generator code is changed —
this is validation tooling plus the evidence it produced.

Refs #168

Why

#168 proposes dropping the build-time jtaf-provider --yang-compliant flag and
instead having the generic provider normalise YANG choices at runtime: accept
either encoding on read, and always write the paired form
(<choice-ident>exact</choice-ident><choice-value/>) instead of the native form
(<exact/>).

That rule is only safe if every platform and release accepts a paired write and
means the same thing by it
. The original proposal was tested on a single
vMX-class device at 26.2R1.7, by hand, never through terraform apply. The main
risk raised in review was release-to-release drift: if paired writes were a newer
capability, the rule would break on older software.

This PR exists to settle that question with data.

Evidence gathered

Platform Junos Knob supported Paired write Native vs paired Read (knob off)
MX240 (physical) 21.1R1.11 yes accepted identical native
vMX 23.2R2.21 yes accepted identical native
MX960 25.2R1.9 yes accepted identical native

The assumption holds, on considerably older software than originally tested —
including physical hardware at 21.1R1.11, roughly five years older than 26.2R1.7.
The yang-compliant knob itself also exists well before 26.2.

Crucially, the probe does not stop at "the device accepted it". A device can
accept XML and silently produce different or no configuration. For each case it
loads the native form, captures the resulting candidate diff, loads the paired
form, and compares. Both forms produced byte-identical configuration on all
three releases, for:

  • route-filter ... exact
  • route-filter ... prefix-length-range /24-/24
  • route-filter ... orlonger + trailing reject
  • route-filter ... upto /24
  • then community add <name>
  • martians ... orlonger allow

With the knob on (tested on vMX 23.2R2.21):

  • reads return the paired form
  • a delete naming only the address is rejected: syntax error, expecting <choice-ident>
  • a delete carrying the full compound key is accepted

That reproduces the original 26.2 findings on 23.2, so the behaviour is not
release-specific.

Safety model

By default the probe commits nothing. Each case is loaded into a locked
candidate, inspected, then discarded, and it refuses any device whose candidate
already holds uncommitted changes.

The knob-on stage is opt-in behind --commit-knob, because the knob only takes
effect for NETCONF sessions started after a commit. It uses commit confirmed
so the device reverts itself even if the script is killed, then reverts
explicitly and verifies. All devices used were confirmed afterwards: knob off,
no JTAF-CHOICE-PROBE policy in the committed config, clean candidate.

Credentials are supplied at runtime via a gitignored devices.json, the
JTAF_PROBE_PASSWORD environment variable, or an interactive prompt. No secrets
are committed.

Still open

Family coverage. Every result above is MX-family. No SRX, PTX, QFX or EX was
reachable from the test environment. Since route-filter, martians and
community are routing-policy constructs, SRX and PTX are the platforms most
worth confirming
before the rule is treated as universal.
tools/choice-probe/NITA-PROMPT.md is a ready-to-run brief for exactly that.

Knob-on breadth. The knob-on path was exercised on one vMX only.

No end-to-end Terraform run. Read-side behaviour was observed via the patch
engine and NETCONF directly, not through terraform apply.

Not yet implemented — handoff notes

The proposal itself is not implemented in this PR. Anyone picking it up
should know these four things, each verified against current master:

  1. The runtime adapter does not exist. ConfigToValue/ValueToConfig in
    terraform_provider/generic/convert.go filter device XML through the schema,
    so a flattened build silently drops paired fields and a --yang-compliant
    build silently drops native case elements. device.config()
    (generic/device.go) applies this filtering before diffing.

  2. The compiled schema discards what the adapter needs. schemaRecord in
    terraform_provider/patch/schema.go keeps name/kind/key/flags only — not the
    choice enum/case→value mapping required to convert <exact/> into
    choice-ident=exact.

  3. State migration is a trap. UpgradeResourceState (generic/server.go)
    decodes with IgnoreUndefinedAttributes, so existing
    choice_ident/choice_value state from a --yang-compliant build is
    silently dropped rather than converted. This needs explicit migration.

  4. Native same-prefix entries share an identity. In the native form,
    route-filter 0/0 exact and route-filter 0/0 longer both reduce to an
    address-only key in keyPredicates (patch/leafmap.go). The compound-key
    path handles this correctly only once the entry is already in paired form,
    so normalisation must happen before diffing.

Trailing siblings (accept, reject, allow, community-name) must remain
independent attributes — they are not cases of the choice, and the YANG enums
list ~50 values that never appear as a choice-ident.

Running it

cd tools/choice-probe
python3 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
cp devices.example.json devices.json   # gitignored; fill in targets

python choice_probe.py --devices devices.json                 # read-only
python choice_probe.py --devices devices.json --targets <name> --commit-knob

vinpatel24 and others added 3 commits October 28, 2026 16:43
Issue Juniper#168 proposes dropping the build-time --yang-compliant flag and having
the generic provider normalise choices at runtime, always writing the paired
form (<choice-ident>exact</choice-ident><choice-value/>) instead of the native
form (<exact/>). That rule is only safe if every platform and release accepts a
paired write and means the same thing by it as by the native form.

The original evidence was one vMX-class device at 26.2R1.7. This probe checks
the claim on any device: whether the yang-compliant knob is supported, whether
each form is accepted, whether the two produce an identical candidate diff,
what encoding comes back on read, and whether a delete then needs the full
compound key.

Running it on a physical MX240 (21.1R1.11), a vMX (23.2R2.21) and an MX960
(25.2R1.9) showed paired writes accepted with the knob off on all three, and
native and paired producing byte-identical configuration for route-filter
exact, prefix-length-range, orlonger with a trailing action, community add and
martians. With the knob on, reads return the paired form and a delete naming
only the address is rejected. SRX and PTX are still untested, which is what
this tool is for.

Nothing is committed by default: each case is loaded into a locked candidate
and discarded, and a device whose candidate already holds uncommitted changes
is skipped. The knob stage is opt-in and uses commit confirmed so the device
reverts itself even if the probe dies.

Credentials are supplied at runtime from an inventory file, an environment
variable or a prompt; devices.json is gitignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the choice form (native vs yang-compliant) a runtime concern of the generic provider, not a build-time flag

1 participant