Juniper / ansible-junos-stdlib

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

support to save the failed tests to dest_dir for local and pyez connection #678

Closed chidanandpujar closed 1 month ago

chidanandpujar commented 1 month ago

Added to support to save the failed test result files to a user specified directory - dest_dir: "{{ backup_dir }}" with filename format for issue #676

<hostname>_<test_name>.text

Ex:

    - name: "Check after PRE - POST check"
      juniper.device.jsnapy:
        dir: "{{ JSNAPy_dir }}"
        test_files:
          - system_util_baseline.yml
          - verify_ospf_neighbor.yml
          - test_chassis_alarms.yml
        logfile: "{{tlogfile}}"
        action: "snapcheck"
        dest_dir: "{{ backup_dir }}"
      register: test_check
      tags:
        - jsnapy

test file: system_util_baseline.yml

test details:

cat jsnapy_TEST_FILES/system_util_baseline.yml 
tests_include:
  - check_core_dumps
  - check_system_memory_usage
    #- check_system_resource_usage

check_core_dumps:
  - command: show system core-dumps
  - iterate:
      xpath: multi-routing-engine-item
      id: re-name
      tests:
        - no-diff: directory-list/output

check_system_memory_usage:
  - command: show system memory
  - iterate:
      xpath: multi-routing-engine-item 
      id: re-name
      tests:
        # - delta: system-memory-free, 10%
        - in-range: system-memory-information/system-memory-summary-information/system-memory-free-percent, 70,99

Failed test: check_system_memory_usage

backup_dir/x.x.x.x_check_system_memory_usage_False.text

cat backup_dir/x.x.x.x_check_system_memory_usage_False.text 
[{'xpath': 'multi-routing-engine-item', 'testoperation': 'in-range', 'passed': [], 'failed': [{'id': {}, 'pre': {}, 'post': {}, 'actual_node_value': None, 'xpath_error': True}], 'test_name': 'check_system_memory_usage', 'node_name': 'system-memory-information/system-memory-summary-information/system-memory-free-percent', 'expected_node_value': [70.0, 99.0], 'result': False, 'count': {'pass': 0, 'fail': 1}}]