Automation

Expand all | Collapse all

How to make the output as format text instead on xml in JSnappy?

Jump to Best Answer
  • 1.  How to make the output as format text instead on xml in JSnappy?

    Posted 02-18-2018 20:20

    Hi all,

     

    Below is the sample script.yml that i found and when i execute the script in jsnappy then the outpout was in format xml. But i want the format into "text". I'm already add script format: 'text' but when execute it still in xml format. Appreciate any help.

     

    BFD-Check:
    - command: show bfd session
    - iterate:
        tests:
        - err: BFD Session With {{post["session-neighbor"]}}, not UP , rather it's {{post["session-state"]}}
          info: All BFD Sessions are 'UP'
          is-equal: session-state, Up
        xpath: bfd-session

    CORE-check:
    - command: show system core-dumps
    - item:
        id: re-name
        tests:
        - err: Core-Dumps found!!!
          info: Core-Dumps Check No Core dumps generated
          no-diff: /total-files
          ignore-null: true
        xpath: multi-routing-engine-item

    Chassis-check:
    - command: show chassis hardware detail
    - iterate:
        id: name
        tests:
        - err: 'The FRU {{pre["chassis-module/name"]}} , Model Name {{pre["chassis-module/model-number"]}} Have
            Problem '
          info: Hardware Chassis check
          list-not-less: null
        xpath: //chassis


    tests_include:
    - BFD-Check
    - Chassis-check
    - CORE-check



  • 2.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-20-2018 20:35

    Hi all,

     

     

    any one can help?

     

     

    Thanks



  • 3.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-20-2018 22:49

     

    Can you elaborate on how you're executing these tests? For instance, here's my full terminal output for a test file I created. 

     

    ~$ jsnapy --snapcheck -f ../jsnapyconfig.yaml -v
    Tests Included : test_applications
    Taking snapshot of RPC: get-config
    ***************************** Device: 127.0.0.1 *****************************
    Tests Included: test_applications
    *************************RPC is get-config*************************
    ----------------------Performing is-equal Test Operation----------------------
    Test Succeeded!!, destination-port is <30589>
    PASS | All "destination-port" is equal to "30589" [ 1 matched ]
    ----------------------Performing is-equal Test Operation----------------------
    Test Succeeded!!, destination-port is <30000>
    PASS | All "destination-port" is equal to "30000" [ 1 matched ]
    ------------------------------- Final Result!! -------------------------------
    test_applications : Passed
    Total No of tests passed: 2
    Total No of tests failed: 0
    Overall Tests passed!!!

     



  • 4.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-21-2018 01:43

    Hi mattoswalt,

     

     

    Can u do "cat file_name" of the  output result? Is it on XML format or not. The result that i want is the "text" format.

     

    Thanks



  • 5.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-21-2018 09:13

    FYI it's usually a lot faster/easier if you post everything you've done so others can try to reproduce and compare results. So I'll make some assumptions about what you're doing as a result. I am assuming by "output" you mean one of the snapshot files. You wish to write the retrieved configuration snapshot out as text rather than XML. This seems to work for me by adding the `format: text` statement to one of my tests as shown below (Note the wiki page covering this):

     

     
    test_applications:
      - rpc: get-config
        format: text
      - item:
          id: ./name
          xpath: 'applications/application[name="k8sfrontend"]'
          tests:
            - is-equal: destination-port, 3058
              info: "Test Succeeded!!, destination-port is <{{post['destination-port']}}>"
              err: "Test Failed!!!, destination-port is <{{post['destination-port']}}>"
    I then take a snapshot:
     
    jsnapy --snap pre -f ../jsnapyconfig.yaml -v
    The result is text:
     
    ~$ cat venv/etc/jsnapy/snapshots/127.0.0.1_pre_get_config.text
    <configuration-text>
    ## Last changed: 2018-02-21 01:30:21 UTC
    version 12.1X47-D15.4;
    system {
        host-name vsrx01;
        root-authentication {
    .......
     


  • 6.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-21-2018 18:10

    Hi mattoswalt,

     

    Yes, the config output is display as "text" but how about such as "show interface terse". Can u try that?

     

     

    Thanks



  • 7.  RE: How to make the output as format text instead on xml in JSnappy?
    Best Answer

    Posted 02-22-2018 15:29

    Absolutely! Here's a test I wrote for this:

     

    test_interfaces_terse:
      - command: show interfaces terse
        format: text
      - iterate:
          xpath: physical-interface
          id: './name'
          tests:
            - no-diff: oper-status       # element in which test is performed
              err: "Test Failed!! oper-status  got changed, before it was <{{pre['oper-status']}}>, now it is <{{post['oper-status']}}>"
              info: "Test Passed!! oper-status is same, before it is <{{pre['oper-status']}}> now it is <{{post['oper-status']}}>"

    And the result after snapshot is the text you'd normally see in the terminal:

     

    ~$ jsnapy --snap pre -f jsnapyconfig.yaml -v
    Tests Included : test_applications
    Taking snapshot of RPC: get-config
    Tests Included: test_interfaces_terse
    Taking snapshot of COMMAND: show interfaces terse
    
    ~$ venv/etc/jsnapy/snapshots/127.0.0.1_pre_show_interfaces_terse.text                                                                                                                                                        [15:27:09]
    <output>
    Interface               Admin Link Proto    Local                 Remote
    ge-0/0/0                up    up
    ge-0/0/0.0              up    up   inet     10.0.2.15/24
    gr-0/0/0                up    up
    ip-0/0/0                up    up
    lsq-0/0/0               up    up
    lt-0/0/0                up    up
    mt-0/0/0                up    up
    sp-0/0/0                up    up
    sp-0/0/0.0              up    up   inet
                                       inet6
    sp-0/0/0.16383          up    up   inet     10.0.0.1            --&gt; 10.0.0.16
                                                10.0.0.6            --&gt; 0/0
                                                128.0.0.1           --&gt; 128.0.1.16
                                                128.0.0.6           --&gt; 0/0
    ..........


  • 8.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-22-2018 19:01

    Hi mattoswalt,

     

     

    Thanks for your feedback. Let's me try the script as per your show in my lab first. I will feedback the result.

     

    Thanks again



  • 9.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-23-2018 00:48

    Hi mattoswalt,

     

    Your script is worked!!. It's look like i miss put wrong location on format: text.

     

     

    Thanks for your help.



  • 10.  RE: How to make the output as format text instead on xml in JSnappy?

    Posted 02-23-2018 12:39

    Excellent - glad to hear!