Assertions
Assertions define expected network state in YAML format.
Basic structure
Section titled “Basic structure”assertions: - target: device:port path: path/to/leaf expect: expected_valueShort path syntax
Section titled “Short path syntax”netsert uses a short path syntax that expands to full OpenConfig paths:
| Short path | Expands to |
|---|---|
interfaces[Ethernet1]/state/oper-status | /interfaces/interface[name=Ethernet1]/state/oper-status |
bgp[default]/neighbors[10.0.0.1]/state/session-state | /network-instances/network-instance[name=default]/protocols/protocol[identifier=BGP][name=BGP]/bgp/neighbors/neighbor[neighbor-address=10.0.0.1]/state/session-state |
system/state/hostname | /system/state/hostname |
Rule: Leading / = full path (passthrough). No leading / = short path (expanded).
Targeting devices
Section titled “Targeting devices”Single device
Section titled “Single device”assertions: - target: spine1.example.com:6030 path: interfaces[Ethernet1]/state/oper-status expect: UPMultiple devices (inline)
Section titled “Multiple devices (inline)”assertions: - target: - spine1:6030 - spine2:6030 path: interfaces[Ethernet1]/state/oper-status expect: UPInventory groups
Section titled “Inventory groups”Define groups in your config file, then reference them with @:
inventory: groups: spines: - spine1:6030 - spine2:6030 leaves: - leaf1:6030 - leaf2:6030assertions: - target: "@spines" path: interfaces[Ethernet1]/state/oper-status expect: UPComparison operators
Section titled “Comparison operators”| Operator | Usage | Example |
|---|---|---|
| equals | Exact match (default) | expect: UP |
| contains | Substring match | expect: "contains:Ethernet" |
| regex | Regular expression | expect: "regex:^4\\.2[89]\\." |
| exists | Path exists | expect: exists |
| not_exists | Path doesn’t exist | expect: not_exists |
| > | Greater than | expect: ">100" |
| < | Less than | expect: "<500" |
Examples
Section titled “Examples”Interface status
Section titled “Interface status”assertions: - target: "@all" path: interfaces[Ethernet1]/state/oper-status expect: UPBGP sessions
Section titled “BGP sessions”assertions: - target: "@leaves" path: bgp[default]/neighbors[10.0.0.1]/state/session-state expect: ESTABLISHEDOSPF neighbors
Section titled “OSPF neighbors”assertions: - target: "@core" path: ospf[default][0]/neighbors[10.0.0.2]/state/adjacency-state expect: FULLSystem info with regex
Section titled “System info with regex”assertions: - target: "@all" path: system/state/software-version expect: "regex:^4\\.2[89]\\."