ignore-null Flag
Syntax
test-name: - command: command - ignore-null: True - (item | iterate): xpath: xpath-expression tests: - operator: <xpath-expression>, <args> info: "string" err: "string" ignore-null: True
Description
The JSNAPy ignore-null: True
flag instructs the tool to skip tests where
nodes for any of the specified XPaths for the test are absent in the snapshot output. If you
instead omit ignore-null
and a node is absent, the test fails with an error
message that the node is not found.
You can use the ignore-null
flag with both check
and
snapcheck
operations. In the test file, you can apply the
ignore-null
flag at two levels. You can include the global
ignore-null
flag to apply the flag to all test cases within a given
tests:
section. You can also include the ignore-null
flag for individual test cases.
Parameters
ignore-null |
Set to |
Usage Examples
The following JSNAPy test parses show chassis fpc
command output. The
tests check that the cpu-total
value is less than 8 and the
beta-cpu-total
value is greater than 2. In this example, the
beta-cpu-total
element does not exist in the output. By setting
ignore-null
to True
, JSNAPy skips the test case when the
node is absent instead of reporting an error.
check_chassis_fpc: - command: show chassis fpc - ignore-null: True - iterate: xpath: //fpc[normalize-space(slot) = "0"] tests: - is-lt: cpu-total, 8 info: "Test Succeeded!! cpu total is less than 8 and its value is {{post['cpu-total']}}" err: "Test Failed!!! cpu total is greater than or equal to 8 and its value is {{post['cpu-total']}}" - is-gt: beta-cpu-total, 2 info: "Test Succeeded!! cpu total is greater than 2 and its value is {{post['beta-cpu-total']}}" err: "Test Failed!!! cpu total is less than or equal to 2 and its value is {{post['beta-cpu-total']}}"
The following example is identical to the previous example except that it applies the
ignore-null
flag to only the is-gt
test instead of both
tests.
check_chassis_fpc: - command: show chassis fpc - iterate: xpath: //fpc[normalize-space(slot) = "0"] tests: - is-lt: cpu-total, 8 info: "Test Succeeded!! cpu total is less than 8 and its value is {{post['cpu-total']}}" err: "Test Failed!!! cpu total is greater than or equal to 8 and its value is {{post['cpu-total']}}" - is-gt: beta-cpu-total, 2 info: "Test Succeeded!! cpu total is greater than 2 and its value is {{post['cpu-total']}}" err: "Test Failed!!! cpu total is less than or equal to 2 and its value is {{post['cpu-total']}}" ignore-null: True
Sample Output
Output with ignore-null: True
When you include ignore-null: True
, JSNAPy skips the test when the node
is not found. In the following output, JSNAPy skips the is-gt
test
because the beta-cpu-total
node is absent.
user@host:~/jsnapy/testfiles$ jsnapy --snapcheck ignore-null-flag -f jsnapy-ignore-null-conf.yaml
Connecting to device 198.51.100.1 ................ Taking snapshot of COMMAND: show chassis fpc **************************** Device: 198.51.100.1 **************************** Tests Included: check_chassis_fpc ************************* Command: show chassis fpc ************************* PASS | All "cpu-total" is less than 8 [ 1 value matched ] ------------------------------- Final Result!! ------------------------------- check_chassis_fpc : Passed Total No of tests passed: 1 Total No of tests failed: 0 Overall Tests passed!!!
If you include the -v
command option to set the verbosity to include
debug messages, the output includes the SKIPPING!! Node
message for the
is-gt
test.
user@host:~/jsnapy/testfiles$ jsnapy --snapcheck ignore-null-flag -f jsnapy-ignore-null-conf.yaml -v
jsnapy.cfg file location used : /etc/jsnapy Configuration file location used : /etc/jsnapy Connecting to device 198.51.100.1 ................ Tests Included: check_chassis_fpc Taking snapshot of COMMAND: show chassis fpc **************************** Device: 198.51.100.1 *************************** Tests Included: check_chassis_fpc ************************* Command: show chassis fpc ************************* -----------------------Performing is-lt Test Operation----------------------- Test Succeeded!! cpu total is less than 8 and its value is 3 PASS | All "cpu-total" is less than 8 [ 1 value matched ] -----------------------Performing is-gt Test Operation----------------------- SKIPPING!! Node <beta-cpu-total> not found at xpath <//fpc[normalize-space(slot) = "0"]> for IDs: {} ------------------------------- Final Result!! ------------------------------- check_chassis_fpc : Passed Total No of tests passed: 1 Total No of tests failed: 0 Overall Tests passed!!!
Output with ignore-null Flag Omitted
If you omit the ignore-null: True
flag and a node is absent, then the
test case fails and generates an error for the absent node.
user@host:~/jsnapy/testfiles$ jsnapy --snapcheck ignore-null-flag -f jsnapy-ignore-null-conf.yaml
Connecting to device 198.51.100.1 ................ Taking snapshot of COMMAND: show chassis fpc **************************** Device: 198.51.100.1 **************************** Tests Included: check_chassis_fpc ************************* Command: show chassis fpc ************************* PASS | All "cpu-total" is less than 8 [ 1 value matched ] ERROR!! Node <beta-cpu-total> not found at xpath <//fpc[normalize-space(slot) = "0"]> for IDs: {} FAIL | All "beta-cpu-total" is not greater than "2" [ 0 value matched / 1 value failed ] ------------------------------- Final Result!! ------------------------------- check_chassis_fpc : Failed Total No of tests passed: 1 Total No of tests failed: 1 Overall Tests failed!!!
Release Information
Flag introduced in Junos Snapshot Administrator in Python Release 1.1.0.