From 38fa1d0b15cd77ef2d7b1b26733e105081f52121 Mon Sep 17 00:00:00 2001 From: David Newswanger Date: Wed, 4 Apr 2018 10:46:30 -0400 Subject: [PATCH] added iosxr_smoke (#37828) * added iosxr_smoke tests * finalized netconf tests * cleaning up files --- .../targets/iosxr_smoke/defaults/main.yaml | 3 + .../targets/iosxr_smoke/meta/main.yaml | 2 + .../targets/iosxr_smoke/tasks/cli.yaml | 24 +++++ .../targets/iosxr_smoke/tasks/main.yaml | 3 + .../targets/iosxr_smoke/tasks/netconf.yaml | 24 +++++ .../iosxr_smoke/tests/cli/common_config.yaml | 100 ++++++++++++++++++ .../iosxr_smoke/tests/cli/common_utils.yaml | 37 +++++++ .../tests/netconf/common_netconf.yaml | 53 ++++++++++ .../iosxr_smoke/tests/netconf/misc_tests.yaml | 39 +++++++ 9 files changed, 285 insertions(+) create mode 100644 test/integration/targets/iosxr_smoke/defaults/main.yaml create mode 100644 test/integration/targets/iosxr_smoke/meta/main.yaml create mode 100644 test/integration/targets/iosxr_smoke/tasks/cli.yaml create mode 100644 test/integration/targets/iosxr_smoke/tasks/main.yaml create mode 100644 test/integration/targets/iosxr_smoke/tasks/netconf.yaml create mode 100644 test/integration/targets/iosxr_smoke/tests/cli/common_config.yaml create mode 100644 test/integration/targets/iosxr_smoke/tests/cli/common_utils.yaml create mode 100644 test/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml create mode 100644 test/integration/targets/iosxr_smoke/tests/netconf/misc_tests.yaml diff --git a/test/integration/targets/iosxr_smoke/defaults/main.yaml b/test/integration/targets/iosxr_smoke/defaults/main.yaml new file mode 100644 index 0000000000..9ef5ba5165 --- /dev/null +++ b/test/integration/targets/iosxr_smoke/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/iosxr_smoke/meta/main.yaml b/test/integration/targets/iosxr_smoke/meta/main.yaml new file mode 100644 index 0000000000..d4da833dd5 --- /dev/null +++ b/test/integration/targets/iosxr_smoke/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_iosxr_tests diff --git a/test/integration/targets/iosxr_smoke/tasks/cli.yaml b/test/integration/targets/iosxr_smoke/tasks/cli.yaml new file mode 100644 index 0000000000..97dfa2c3f7 --- /dev/null +++ b/test/integration/targets/iosxr_smoke/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + +# Only one of the Testcase would be run to check if `connection: local` +# is established. Full suite is run with `connection:network_cli` or `connection:netconf` +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_smoke/tasks/main.yaml b/test/integration/targets/iosxr_smoke/tasks/main.yaml new file mode 100644 index 0000000000..af08869c92 --- /dev/null +++ b/test/integration/targets/iosxr_smoke/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: netconf.yaml, tags: ['netconf'] } diff --git a/test/integration/targets/iosxr_smoke/tasks/netconf.yaml b/test/integration/targets/iosxr_smoke/tasks/netconf.yaml new file mode 100644 index 0000000000..904db03205 --- /dev/null +++ b/test/integration/targets/iosxr_smoke/tasks/netconf.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all netconf test cases + find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=netconf) + include: "{{ test_case_to_run }} ansible_connection=netconf" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + +# Only one of the Testcase would be run to check if `connection: local` +# is established. Full suite is run with `connection:network_cli` or `connection:netconf` +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_smoke/tests/cli/common_config.yaml b/test/integration/targets/iosxr_smoke/tests/cli/common_config.yaml new file mode 100644 index 0000000000..d77a4246e1 --- /dev/null +++ b/test/integration/targets/iosxr_smoke/tests/cli/common_config.yaml @@ -0,0 +1,100 @@ +--- +- debug: msg="START cli/common_config.yaml on connection={{ ansible_connection }}" + +# Sublevel / Block +- name: setup + iosxr_config: + commands: + - 10 permit ipv4 host 1.1.1.1 any log + - 20 permit ipv4 host 2.2.2.2 any log + - 30 permit ipv4 host 3.3.3.3 any log + parents: ['ipv4 access-list test'] + before: ['no ipv4 access-list test'] + match: none + +- name: configure sub level command using block resplace + iosxr_config: + commands: + - 10 permit ipv4 host 1.1.1.1 any log + - 20 permit ipv4 host 2.2.2.2 any log + - 30 permit ipv4 host 3.3.3.3 any log + - 40 permit ipv4 host 4.4.4.4 any log + parents: ['ipv4 access-list test'] + replace: block + register: result + +- assert: + that: + - "result.changed == true" + - "'ipv4 access-list test' in result.commands" + - "'10 permit ipv4 host 1.1.1.1 any log' in result.commands" + - "'20 permit ipv4 host 2.2.2.2 any log' in result.commands" + - "'30 permit ipv4 host 3.3.3.3 any log' in result.commands" + - "'40 permit ipv4 host 4.4.4.4 any log' in result.commands" + +- name: check sub level command using block replace + iosxr_config: + commands: + - 10 permit ipv4 host 1.1.1.1 any log + - 20 permit ipv4 host 2.2.2.2 any log + - 30 permit ipv4 host 3.3.3.3 any log + - 40 permit ipv4 host 4.4.4.4 any log + parents: ['ipv4 access-list test'] + replace: block + register: result + +- assert: + that: + - "result.changed == false" + +- name: teardown + iosxr_config: + commands: ['no ipv4 access-list test'] + match: none + +# diff exact, strict, line +- name: setup + iosxr_config: + commands: + - 'hostname {{ inventory_hostname_short }}' + register: result + +- name: set hostname + iosxr_config: + commands: + - hostname testhost + match: strict + register: result + +- iosxr_command: + commands: + - show configuration running-config hostname + register: configured_hostname + +- assert: + that: + - "'testhost' in configured_hostname.stdout[0]" + +- name: set hostname + iosxr_config: + commands: + - hostname testhost2 + match: exact + register: result + +- iosxr_command: + commands: + - show configuration running-config hostname + register: configured_hostname + +- assert: + that: + - "'testhost2' in configured_hostname.stdout[0]" + +- name: teardown + iosxr_config: + commands: + - 'hostname {{ inventory_hostname_short }}' + register: result + +- debug: msg="END cli/common_config.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_smoke/tests/cli/common_utils.yaml b/test/integration/targets/iosxr_smoke/tests/cli/common_utils.yaml new file mode 100644 index 0000000000..f1dfeffbab --- /dev/null +++ b/test/integration/targets/iosxr_smoke/tests/cli/common_utils.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg="START iosxr cli/common_utils.yaml on connection={{ ansible_connection }}" + +# Functions used by iosxr: conditional, remove_default_spec + +# hit conditional() and remove_default_spec() +- name: Check intent arguments + iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: up + tx_rate: ge(0) + rx_rate: ge(0) + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.failed == false" + +- name: Check intent arguments (failed condition) + iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: down + tx_rate: gt(0) + rx_rate: lt(0) + provider: "{{ cli }}" + ignore_errors: yes + register: result + +- assert: + that: + - "result.failed == true" + - "'state eq(down)' in result.failed_conditions" + - "'tx_rate gt(0)' in result.failed_conditions" + - "'rx_rate lt(0)' in result.failed_conditions" + +- debug: msg="END iosxr cli/common_utils.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml b/test/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml new file mode 100644 index 0000000000..3463cc2bb4 --- /dev/null +++ b/test/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml @@ -0,0 +1,53 @@ +--- +- debug: msg="START iosxr netconf/common_netconf.yaml on connection={{ ansible_connection }}" + +# hit general code +- name: setup - remove login + iosxr_banner: + banner: login + provider: "{{ netconf }}" + state: absent + +- name: Set login + iosxr_banner: + banner: login + text: | + this is my login banner + that has a multiline + string + provider: "{{ netconf }}" + state: present + register: result + +- debug: + msg: "{{ result }}" + +- assert: + that: + - "result.changed == true" + - "'this is my login banner' in result.xml" + - "'that has a multiline' in result.xml" + +# hit etree_findall() +- name: remove host logging + iosxr_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: "{{ netconf }}" + +- name: set up syslog host logging + iosxr_logging: &addhostlog + dest: host + name: 172.16.0.1 + level: errors + state: present + provider: "{{ netconf }}" + register: result + +- assert: + that: + - 'result.changed == true' + - '"172.16.0.1" in result.xml[0]' + +- debug: msg="END iosxr netconf/common_netconf.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_smoke/tests/netconf/misc_tests.yaml b/test/integration/targets/iosxr_smoke/tests/netconf/misc_tests.yaml new file mode 100644 index 0000000000..fc5df1fb5d --- /dev/null +++ b/test/integration/targets/iosxr_smoke/tests/netconf/misc_tests.yaml @@ -0,0 +1,39 @@ +- debug: msg="START iosxr netconf/misc_tests.yaml on connection={{ ansible_connection }}" + + +# hit module_utils.network.iosxr -> get_oper() +- name: Setup (interface is up) + iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test_interface_1 + enabled: True + state: present + provider: "{{ netconf }}" + register: result + +- name: Check intent arguments + iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: up + delay: 10 + provider: "{{ netconf }}" + register: result + +- assert: + that: + - "result.failed == false" + +- name: Check intent arguments (failed condition) + iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: down + provider: "{{ netconf }}" + ignore_errors: yes + register: result + +- assert: + that: + - "result.failed == true" + - "'state eq(down)' in result.failed_conditions" + +- debug: msg="END iosxr netconf/misc_tests.yaml on connection={{ ansible_connection }}"