Skip to content

3. Command Line Tool

Priyal Jain edited this page Mar 26, 2016 · 15 revisions

JSNAPy As a Command Line Tool:


Jsnapy provides following functionalities for network state verification:

  1. --snap : this command lets you to take snapshot.

       jsnapy --snap <file_name> -f <config_file>
    
  2. --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

  3. --snapcheck: compares the current configuration against pre defined criteria

       jsnapy --snapcheck <snap_fila_name> -f <config_file>
    
  4. --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.

###Output format:

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

Example:

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:git_jsnap_py/latest/jsnap_test] jpriyal% jsnap --snapcheck pre -f config_single_snapcheck.yml
 Connecting to device 10.209.1.1 ................

 Taking snapshot for get-bgp-neighbor-information................
****************************************
 Performing test on Device: router 
****************************************
 Tests Included: test_interfaces_terse 
****************************************
 rpc is get-bgp-neighbor-information
****************************************
----------------------Performing all-same Test Operation----------------------
Test Succeeded !! flap count are all same, it is <0> 
Final result of all-same: PASSED 
------------------------------- Final Result!! -------------------------------
Total No of tests passed: 1 
Total No of tests failed: 0 
Overall Tests passed!!! 
Clone this wiki locally