3. Command Line Tool

sidhujasminder edited this page Jun 16, 2017 · 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_file_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.

Optional arguments:

  1. --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:

              |____ 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

  2. --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.

  3. --testfiles : Added in v1.2 takes testfiles(one or multiple) without requirement of config file

    a) If there is only one testfile:

        jsnapy --snapcheck <snap_name> --testfiles <test_file1> --hostname <host_name> --login <login> --passwd <passwd>  
       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>

    Note: If ssh key based authentication is configured in system, then no need to give username and password, user can omit these two parameters. But if key based authentication is not configured, then it will throw error. It will not prompt for username, password or any parameter, if its required and not given.
    Refer here for pull request

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


Input consist of main config file and test files in yaml

Config File Example:

    # for one device, can be given like this:
      - devices: 
            username : abc
            passwd: pqr
      - test_no_diff.yml 
      - test_delta.yml
    # can use sqlite to store data and compare them  
      - 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:

       - test_flap_count

         - rpc: get-bgp-neighbor-information
         - iterate:
             xpath: '//bgp-information/bgp-peer'
               - 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']}}>"


    [jpriyal-mba13:/etc/jsnapy/testfiles] jpriyal% jsnapy --snapcheck pre -f config_single_snapcheck.yml
    Connecting to device ................
    Tests Included : test_flap_count 
    Taking snapshot of RPC: get-bgp-neighbor-information
    *************************** Device: ***************************
    Tests Included: test_flap_count 
    *************************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!!! 
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.