Juniper / ansible-junos-stdlib

Junos modules for Ansible
Apache License 2.0
302 stars 156 forks source link

juniper.device.jsnapy fails with config_file option and juniper.device.pyez #671

Open chidanandpujar opened 2 months ago

chidanandpujar commented 2 months ago

Issue Type

Module Name

juniper.device.jsnapy

juniper.device collection and Python libraries version

Collection                               Version
---------------------------------------- -------
ansible.netcommon                        4.1.0  
ansible.utils                            2.8.0  
juniper.device                           1.0.5  

jsnapy                1.3.8.dev0

junos-eznc            2.7.1+9.ga64698b

OS / Environment

JUNOS Evolved

Summary

juniper.device.jsnapy fails with config_file option and juniper.device.pyez

Steps to reproduce

cat TEST_FILES/jsnapy_main.yml 
tests:
  - TEST_FILES/test_interface.yml 

cat TEST_FILES/test_interface.yml 
tests_include:
  - test_interface

# use '/' in your test cases apart from xpath if u want to search all elements irrespective of hierarchy, ex: in id if u use /name instead of name
# then it will search in all the names in given xpath irrespective of their position
# for simple, one test using command

test_interface:
  - command: show interfaces terse 
  - 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: "oper-status is same before it was <{{pre['oper-status']}}>, now it is <{{post['oper-status']}}>"

        - list-not-less: oper-status
          err: "name list changed, oper-state: <{{pre['oper-state']}}> with name <{{id_0}}> is not present in post-snap"
          info: "name list is same, oper-state is present in pre-snap: <{{pre['oper-status']}}> and post-snap: <{{post['oper-status']}}>"

        - list-not-more: name
          err: "<{{post['name']}}> name is not present in pre snapshot"
          info: "name is same, before it was <{{pre['name']}}>, now it is <{{post['name']}}>"

 cat pb.config_file_test_issue.yml 
---
- name: Test juniper.device.jsnapy module
  hosts: all
  gather_facts: false
  tasks:
##################################################
####    TEST 4                                  ##
##################################################
    - name: "TEST 4 - SNAP_PRE"
      juniper.device.jsnapy:
        config_file: TEST_FILES/jsnapy_main.yml 
        action: snap_pre
      register: test4
      ignore_errors: true
      tags: [test4]

    - debug: var=test4

    - name: Check TEST 4
      ansible.builtin.assert:
        that:
          - test4.msg == "The snap_pre action successfully executed."
      tags: [test4]

ansible-playbook pb.config_file_test_issue.yml 

PLAY [Test juniper.device.jsnapy module] **********************************************************************************************************************************

TASK [TEST 4 - SNAP_PRE] **************************************************************************************************************************************************
<unknown>:1812: SyntaxWarning: invalid escape sequence '\*'
ok: [pyez_connection_testcases]

TASK [debug] **************************************************************************************************************************************************************
ok: [pyez_connection_testcases] => {
    "test4": {
        "action": "snap_pre",
        "changed": false,
        "failed": false,
        "msg": "The snap_pre action successfully executed."
    }
}

TASK [Check TEST 4] *******************************************************************************************************************************************************
ok: [pyez_connection_testcases] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP ****************************************************************************************************************************************************************
pyez_connection_testcases  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

snapshot files are not created :

ls ~/ansible_jsnapy_issue/venv/etc/jsnapy/snapshots/
README

Expected results

snapshot files gets created .

ls ~/ansible_jsnapy_issue/venv/etc/jsnapy/snapshots/
10.220.24.28_PRE_show_interfaces_terse.xml  README

Actual results

ls ~/ansible_jsnapy_issue/venv/etc/jsnapy/snapshots/
README
chidanandpujar commented 1 month ago

issue is when jsnapy test yaml files are missing or path is incorrect, ansible jsnapy module fails to report errors .

TASK [Collect Pre Snapshot] ***********************************************************************************************************************************************
ok: [x.x.x.x]

TASK [Print the full test response] ***************************************************************************************************************************************
ok: [x.x.x.x] => {
    "test_pre": {
        "action": "snap_pre",
        "changed": false,
        "failed": false,
        "msg": "The snap_pre action successfully executed."
    }
}

TASK [Check Pre Snapshot] *************************************************************************************************************************************************
ok: [x.x.x.x] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP ****************************************************************************************************************************************************************
x.x.x.x              : ok=9    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

 cat jsnapy_TEST_FILES/jsnapy_main.yml
  tests:
    - /root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/test_chassis_alarms.yml

~/ansible_jsnapy_issue/ansible-junos-stdlib/tests# ls -lrt /root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/test_chassis_alarms.yml
ls: cannot access '/root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/test_chassis_alarms.yml': No such file or directory

ls ~/ansible_jsnapy_issue/venv/etc/jsnapy/snapshots/
README

This can be checked using jsnapy python module.

python test_config_pre.py 
ERROR!! File /root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/test_chassis_alarms.yml is not found for extracting test case
ERROR!! File /root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/test_chassis_alarms.yml is not found for extracting test case
ERROR!! File /root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/test_chassis_alarms.yml not found for testing
------------------------------- Final Result!! -------------------------------
Total No of tests passed: 0
Total No of tests failed: 0 
None of the test cases executed !!! 

 -----------check----------
Tested on 10.220.15.151
Final result:  None
Total passed:  0
Total failed: 0

After providing the correcting tests yaml file path.

cat jsnapy_TEST_FILES/jsnapy_main.yml
  tests:
    - /root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/jsnapy_TEST_FILES/test_chassis_alarms.yml

~/ansible_jsnapy_issue/ansible-junos-stdlib/tests# ls -l /root/ansible_jsnapy_issue/ansible-junos-stdlib/tests/jsnapy_TEST_FILES/test_chassis_alarms.yml

TASK [Collect Pre Snapshot] ***********************************************************************************************************************************************
ok: [x.x.x.x]

TASK [Print the full test response] ***************************************************************************************************************************************
ok: [x.x.x.x] => {
    "test_pre": {
        "action": "snap_pre",
        "changed": false,
        "failed": false,
        "msg": "The snap_pre action successfully executed."
    }
}

TASK [Check Pre Snapshot] *************************************************************************************************************************************************
ok: [x.x.x.x] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP ****************************************************************************************************************************************************************
x.x.x.x              : ok=9    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

~/ansible_jsnapy_issue/ansible-junos-stdlib/tests# ls ~/ansible_jsnapy_issue/venv/etc/jsnapy/snapshots/
x.x.x.x_PRE_show_chassis_alarms.xml  README