-
Notifications
You must be signed in to change notification settings - Fork 59
3. Command Line Tool
Jsnapy provides following functionalities for network state verification:
-
--snap : this command lets you to take snapshot.
`jsnapy --snap <file_name> -f <config_file>`
-
--check: this command compares two snapshots based on given test cases.
`jsnapy --check <pre_snap> <post_snap> -f <config_file>`
if test cases are not specified in test files, then it will compare pre and post snap files, node by node
-
--snapcheck: compares the current configuration against pre-defined criteria
`jsnapy --snapcheck <snap_file_name> -f <config_file>`
-
--diff : compares two snapshots (either in xml or text format) word by word
`jsnapy --diff <pre_snap> <post_snap> -f <config_file>`
This operator is supported only in command line mode.
-
--folder :
Added in v1.1
specify custom jsnapy lookup directory.`jsnapy --snapcheck <snap_file_name> -f <config_file> --folder <directory_path>`
Directory specified should maintain the default jsnapy hierarchy:
---dir_specified/ |____ testfiles/ |____ snapshots/
The dir_specified should be present. Config files should be placed in dir_specified , test files in dir_specified/testfiles directory and snapshots of the commands will then be stored in dir_specified/snapshots directory. Specifying this option overrides the configuration mentioned in jsnapy.cfg file. Refer here for pull request
-
--local :
Added in v1.1
Runs the snapcheck on the local snapshot.`jsnapy --snapcheck <snap_name> -f <config_file> --local`
Presence of
--local
option runs the tests on stored <snap_name> snapshot. To use this command one has to first create <snap_name> snapshot using--snap
command. Refer here for pull request. -
--testfiles :
Added in v1.2
takes testfiles(one or multiple) without requirement of config filea) If there is only one testfile
jsnapy --snapcheck <snap_name> --testfiles <test_file1> --hostname <host_name> --login <login> --passwd <passwd>
or ` jsnapy --snapcheck <snap_name> -T <test_file1> -t <host_name> -l <login> -p <passwd>`
b) If there are multiple testfiles
jsnapy --snapcheck <snap_name> --testfiles <test_file1> <test_file2> <test_file3> --hostname <host_name> --login <login> --passwd <passwd>
Output will be displayed using Jinja template.
For printing any node value from snapshot, specify pre or post and then node name
For example:
`{{pre['admin-status']}}` : This will print admin status from pre snapshot
`{{post['admin-status']}}` : This will print admin status from post snapshot
can also specify id using:
{{id_0}} : for id 0
{{id_1}} : for id 1
Input consist of main config file and test files in yaml
Config File Example:
# for one device, can be given like this:
hosts:
- devices: 10.206.1.1
username : abc
passwd: pqr
tests:
- test_no_diff.yml
- test_delta.yml
# can use sqlite to store data and compare them
sqlite:
- store_in_sqlite: True
check_from_sqlite: True
database_name: jbb.db
compare: 1,0
# can send mail by specifying mail
mail: send_mail.yml
Test File Example:
tests_include:
- test_flap_count
test_flap_count:
- rpc: get-bgp-neighbor-information
- iterate:
xpath: '//bgp-information/bgp-peer'
tests:
- all-same: flap-count
err: "Test Succeeded!!! flap count are all same, it is <{{post['flap-count']}}>"
info: "Test Failed!! flap count are all different <{{post['flap-count']}}>"
Output:
[jpriyal-mba13:/etc/jsnapy/testfiles] jpriyal% jsnapy --snapcheck pre -f config_single_snapcheck.yml
Connecting to device 10.209.16.204 ................
Tests Included : test_rpc_bgp
Taking snapshot of RPC: get-bgp-neighbor-information
*************************** Device: 10.209.16.204 ***************************
Tests Included: test_rpc_bgp
*************************RPC is get-bgp-neighbor-information*************************
----------------------Performing all-same Test Operation----------------------
Passed!! all flap count are same, it is <0>
PASS | Value of all "flap-count" at xpath "//bgp-information/bgp-peer" is same [ 1 matched ]
------------------------------- Final Result!! -------------------------------
Total No of tests passed: 1
Total No of tests failed: 0
Overall Tests passed!!!