|
1 | 1 | --- |
2 | 2 | # _run_check.yml — executes one test case file. |
3 | 3 | # Called in a loop from network_qa.yml with test_case_path as the loop var. |
| 4 | +# |
| 5 | +# Supports two test patterns: |
| 6 | +# 1. Read-only: NETCONF GET + assert (e.g. route_to_a2a) |
| 7 | +# 2. Configure-assert-teardown: push config via CLI, wait, assert via |
| 8 | +# NETCONF, then tear down config. Teardown always runs, even on failure. |
| 9 | +# |
| 10 | +# NETCONF queries support two methods: |
| 11 | +# - netconf_get (default): subtree filter with <get> or <get-config> |
| 12 | +# - netconf_rpc: vendor-specific RPC (e.g. JunOS get-route-information) |
| 13 | +# |
| 14 | +# Each test case specifies its own NETCONF filter/RPC, assertion type, and |
| 15 | +# expected value. Config/teardown phases are optional. |
4 | 16 |
|
5 | 17 | - name: "Load scenario: {{ test_case_path | basename }}" |
6 | 18 | ansible.builtin.include_vars: |
|
11 | 23 | when: scenario_filter == '' or scenario_filter == scenario.scenario |
12 | 24 | block: |
13 | 25 |
|
14 | | - - name: "{{ scenario.scenario }} | NETCONF GET routing table" |
| 26 | + - name: "{{ scenario.scenario }} | Push pre-test config" |
| 27 | + ansible.netcommon.cli_config: |
| 28 | + config: "{{ scenario.config_commands | default('') }}" |
| 29 | + delegate_to: "{{ scenario.config_device | default('localhost') }}" |
| 30 | + vars: |
| 31 | + ansible_connection: ansible.netcommon.network_cli |
| 32 | + ansible_network_os: "{{ scenario.config_network_os | default('') }}" |
| 33 | + ansible_port: 22 |
| 34 | + ansible_ssh_host_key_checking: false |
| 35 | + when: scenario.config_commands is defined |
| 36 | + |
| 37 | + - name: "{{ scenario.scenario }} | Wait for convergence" |
| 38 | + ansible.builtin.pause: |
| 39 | + seconds: "{{ scenario.convergence_wait | default(0) }}" |
| 40 | + when: scenario.convergence_wait is defined |
| 41 | + |
| 42 | + - name: "{{ scenario.scenario }} | NETCONF GET" |
15 | 43 | ansible.netcommon.netconf_get: |
16 | | - filter: >- |
17 | | - <routing-state xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> |
18 | | - <routing-instance><name>{{ scenario.vrf | default('default') }}</name></routing-instance> |
19 | | - </routing-state> |
| 44 | + filter: "{{ scenario.netconf_filter }}" |
| 45 | + source: "{{ scenario.netconf_source | default(omit) }}" |
20 | 46 | display: xml |
21 | 47 | delegate_to: "{{ scenario.device }}" |
22 | 48 | register: netconf_result |
| 49 | + when: scenario.netconf_rpc is not defined |
| 50 | + |
| 51 | + - name: "{{ scenario.scenario }} | NETCONF RPC" |
| 52 | + ansible.netcommon.netconf_rpc: |
| 53 | + rpc: "{{ scenario.netconf_rpc }}" |
| 54 | + content: "{{ scenario.netconf_rpc_content | default(omit) }}" |
| 55 | + display: xml |
| 56 | + delegate_to: "{{ scenario.device }}" |
| 57 | + register: netconf_rpc_result |
| 58 | + when: scenario.netconf_rpc is defined |
| 59 | + |
| 60 | + - name: "{{ scenario.scenario }} | Unify result" |
| 61 | + ansible.builtin.set_fact: |
| 62 | + _netconf_output: "{{ (netconf_rpc_result.output | default(netconf_result.output | default(''))) }}" |
23 | 63 |
|
24 | 64 | - name: "{{ scenario.scenario }} | Debug XML" |
25 | 65 | ansible.builtin.debug: |
26 | | - msg: "{{ netconf_result.output | truncate(500) }}" |
| 66 | + msg: "{{ _netconf_output | truncate(500) }}" |
27 | 67 | when: ansible_verbosity >= 1 |
28 | 68 |
|
29 | | - - name: "{{ scenario.scenario }} | Assert route exists" |
| 69 | + - name: "{{ scenario.scenario }} | Assert" |
30 | 70 | ansible.builtin.set_fact: |
31 | | - _assertion_passed: "{{ netconf_result.output | route_exists(scenario.assert_route_exists) }}" |
32 | | - _assertion_output: "{{ netconf_result.output | truncate(500) }}" |
| 71 | + _assertion_passed: "{{ _netconf_output | assert_check(scenario.assertion, scenario.assert_value) }}" |
| 72 | + _assertion_output: "{{ _netconf_output | truncate(500) }}" |
33 | 73 |
|
34 | 74 | rescue: |
35 | 75 |
|
|
40 | 80 |
|
41 | 81 | always: |
42 | 82 |
|
| 83 | + - name: "{{ scenario.scenario }} | Teardown config" |
| 84 | + ansible.netcommon.cli_config: |
| 85 | + config: "{{ scenario.teardown_commands | default('') }}" |
| 86 | + delegate_to: "{{ scenario.config_device | default('localhost') }}" |
| 87 | + vars: |
| 88 | + ansible_connection: ansible.netcommon.network_cli |
| 89 | + ansible_network_os: "{{ scenario.config_network_os | default('') }}" |
| 90 | + ansible_port: 22 |
| 91 | + ansible_ssh_host_key_checking: false |
| 92 | + when: scenario.teardown_commands is defined |
| 93 | + ignore_errors: true |
| 94 | + |
43 | 95 | - name: "{{ scenario.scenario }} | Record result" |
44 | 96 | ansible.builtin.set_fact: |
45 | 97 | qa_results: >- |
|
0 commit comments