Understanding Junos Snapshot Administrator in Python Test Operators
Junos Snapshot Administrator in Python (JSNAPy) enables you to capture and audit runtime
environment snapshots of your Junos devices. The jsnapy configuration file
defines the scope of a snapshot and specifies the test files to use for either a single
snapshot or a comparison of two snapshots. The --snapcheck option takes a
single snapshot and evaluates the results, and the --check option compares
the results of two separate snapshots. Within the test file, you specify the commands to be
run on the Junos device, the XPath from which to start, an optional id value, and the tests to
run against the command output. The test cases use test operators to either evaluate data
elements in a single snapshot or compare data elements in two separate snapshots.
Jsnapy provides numerous relational operators that test for existence, equality, inequality, size, and inclusion in or exclusion from a specific range or list. Specific operators work with different operand types including strings, numbers, and XML elements. You should construct test cases using test operators that pertain to the type of check being performed. For a list of available operators, see Junos Snapshot Administrator in Python Test Operators Summary.
Junos Snapshot Administrator in Python uses a few test operators to compare elements or
element values in two separate snapshots. The operators include: delta,
list-no-less, list-no-more, and no-diff.
Test cases using these test operators are executed when you use the --check
option. When you use the --snapcheck option, which is specific to a single
collection, test cases using these test operators are effectively ignored. Junos Snapshot
Administrator in Python outputs a message when a test case is ignored, as shown in the
following sample output:
--------------------------------------------------------------------------- CHECKING SECTION: ospf-checks --------------------------------------------------------------------------- INFO: snapcheck mode: skipping test: list-not-less INFO: snapcheck mode: skipping test: no-diff + TEST PASSED: All OSPF neighbors are up + TEST PASSED: OSPF neighbors must have the same priority value INFO: snapcheck mode: skipping test: no-diff
When comparing element values across two snapshots, in order to map the first snapshot data
item to the second snapshot data item, you must define elements of the data that create a
unique ID. To create a unique ID for a test case, you include the id
statement followed by an XPath expression that references the unique element.
The following example uses the value of the name element to identify an
item.
id: name
To create a unique ID based on multiple element values, use one of the following methods:
-
Define a list of IDs.
id: [name, ../peer-address]
-
Define a string of comma-separated IDs.
id: name, ../peer-address
You can also construct ID values relative to the content value by using the appropriate XPath expressions. For example:
id: connection-id, ../local-site-id, ancestor::instance/instance-name