From 50d148a7d6bda1f4f67388ea9cef4ca4e914d3a1 Mon Sep 17 00:00:00 2001 From: rahushen Date: Fri, 1 Sep 2017 05:44:24 -0400 Subject: [PATCH] Add nxos_config IT (#28853) * recalibrate tests and add new ones * add new cli tests * add new nxapi tests * Add new tests for cli and nxapi --- .../nxos_config/tests/common/backup.yaml | 11 +++- .../nxos_config/tests/common/defaults.yaml | 17 +++++- .../nxos_config/tests/common/sanity.yaml | 41 +++++++++++++ .../nxos_config/tests/common/save.yaml | 12 ++-- .../nxos_config/tests/common/src_basic.yaml | 17 +++++- .../tests/{cli => common}/src_match_none.yaml | 27 ++++++--- .../tests/{cli => common}/sublevel_block.yaml | 14 ++--- .../nxos_config/tests/nxapi/backup.yaml | 50 ---------------- .../tests/nxapi/src_match_none.yaml | 40 ------------- .../tests/nxapi/sublevel_block.yaml | 59 ------------------- 10 files changed, 112 insertions(+), 176 deletions(-) create mode 100644 test/integration/targets/nxos_config/tests/common/sanity.yaml rename test/integration/targets/nxos_config/tests/{cli => common}/src_match_none.yaml (54%) rename test/integration/targets/nxos_config/tests/{cli => common}/sublevel_block.yaml (79%) delete mode 100644 test/integration/targets/nxos_config/tests/nxapi/backup.yaml delete mode 100644 test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml delete mode 100644 test/integration/targets/nxos_config/tests/nxapi/sublevel_block.yaml diff --git a/test/integration/targets/nxos_config/tests/common/backup.yaml b/test/integration/targets/nxos_config/tests/common/backup.yaml index 6f7cd37b41..04325b64fb 100644 --- a/test/integration/targets/nxos_config/tests/common/backup.yaml +++ b/test/integration/targets/nxos_config/tests/common/backup.yaml @@ -1,13 +1,16 @@ --- - debug: msg="START {{ connection.transport }}/backup.yaml" +# Select interface for test +- set_fact: intname="{{ nxos_int1 }}" + - name: setup nxos_config: commands: - no description - no shutdown parents: - - interface Ethernet2/5 + - "interface {{ intname }}" match: none provider: "{{ connection }}" @@ -26,7 +29,11 @@ - name: configure device with config nxos_config: - src: basic/config.j2 + commands: + - description this is a test + - shutdown + parents: + - "interface {{ intname }}" backup: yes provider: "{{ connection }}" register: result diff --git a/test/integration/targets/nxos_config/tests/common/defaults.yaml b/test/integration/targets/nxos_config/tests/common/defaults.yaml index 84b8614b61..f6df4f7404 100644 --- a/test/integration/targets/nxos_config/tests/common/defaults.yaml +++ b/test/integration/targets/nxos_config/tests/common/defaults.yaml @@ -1,19 +1,26 @@ --- - debug: msg="START {{ connection.transport }}/defaults.yaml" +# Select interface for test +- set_fact: intname="{{ nxos_int1 }}" + - name: setup nxos_config: commands: - no description - shutdown parents: - - interface Ethernet2/5 + - "interface {{ intname }}" match: none provider: "{{ connection }}" - name: configure device with defaults included nxos_config: - src: defaults/config.j2 + commands: + - description this is a test + - no shutdown + parents: + - "interface {{ intname }}" defaults: yes provider: "{{ connection }}" register: result @@ -27,7 +34,11 @@ - name: check device with defaults included nxos_config: - src: defaults/config.j2 + commands: + - description this is a test + - no shutdown + parents: + - "interface {{ intname }}" defaults: yes provider: "{{ connection }}" register: result diff --git a/test/integration/targets/nxos_config/tests/common/sanity.yaml b/test/integration/targets/nxos_config/tests/common/sanity.yaml new file mode 100644 index 0000000000..6d1ea0b8ed --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/sanity.yaml @@ -0,0 +1,41 @@ +--- +- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_config sanity test" + +- name: setup + nxos_config: + lines: ip access-list test + provider: "{{ connection }}" + match: none + +- name: "TRANSPORT:CLI nxos_config sanity test" + nxos_config: + lines: + - 10 permit ip 1.1.1.1/32 any log + - 20 permit ip 2.2.2.2/32 any log + - 30 permit ip 3.3.3.3/32 any log + - 40 permit ip 4.4.4.4/32 any log + - 50 permit ip 5.5.5.5/32 any log + parents: ip access-list test + before: no ip access-list test + match: exact + provider: "{{ connection }}" + +- name: "TRANSPORT:CLI nxos_config sanity test - replace block" + nxos_config: + lines: + - 10 permit ip 1.1.1.1/32 any log + - 20 permit ip 2.2.2.2/32 any log + - 30 permit ip 3.3.3.3/32 any log + - 40 permit ip 4.4.4.4/32 any log + parents: ip access-list test + before: no ip access-list test + replace: block + provider: "{{ connection }}" + +- name: teardown + nxos_config: + lines: no ip access-list test + provider: "{{ connection }}" + match: none + +- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_config sanity test" diff --git a/test/integration/targets/nxos_config/tests/common/save.yaml b/test/integration/targets/nxos_config/tests/common/save.yaml index 7f15f6c677..bada8d4bf8 100644 --- a/test/integration/targets/nxos_config/tests/common/save.yaml +++ b/test/integration/targets/nxos_config/tests/common/save.yaml @@ -1,20 +1,23 @@ --- - debug: msg="START {{ connection.transport }}/save.yaml" +# Select interface for test +- set_fact: intname="{{ nxos_int1 }}" + - name: setup nxos_config: commands: - no description - no shutdown parents: - - interface Ethernet2/5 + - "interface {{ intname }}" match: none provider: "{{ connection }}" - - name: save config nxos_config: - save: true + save_when: always + timeout: 300 provider: "{{ connection }}" register: result @@ -24,7 +27,8 @@ - name: save should always run nxos_config: - save: true + save_when: always + timeout: 300 provider: "{{ connection }}" register: result diff --git a/test/integration/targets/nxos_config/tests/common/src_basic.yaml b/test/integration/targets/nxos_config/tests/common/src_basic.yaml index e2d3287b6e..c1fcea7239 100644 --- a/test/integration/targets/nxos_config/tests/common/src_basic.yaml +++ b/test/integration/targets/nxos_config/tests/common/src_basic.yaml @@ -1,19 +1,26 @@ --- - debug: msg="START {{ connection.transport }}/src_basic.yaml" +# Select interface for test +- set_fact: intname="{{ nxos_int1 }}" + - name: setup nxos_config: commands: - no description - no shutdown parents: - - interface Ethernet2/5 + - "interface {{ intname }}" match: none provider: "{{ connection }}" - name: configure device with config nxos_config: - src: basic/config.j2 + commands: + - description this is a test + - shutdown + parents: + - "interface {{ intname }}" defaults: yes provider: "{{ connection }}" register: result @@ -26,7 +33,11 @@ - name: check device with config nxos_config: - src: basic/config.j2 + commands: + - description this is a test + - shutdown + parents: + - "interface {{ intname }}" defaults: yes provider: "{{ connection }}" register: result diff --git a/test/integration/targets/nxos_config/tests/cli/src_match_none.yaml b/test/integration/targets/nxos_config/tests/common/src_match_none.yaml similarity index 54% rename from test/integration/targets/nxos_config/tests/cli/src_match_none.yaml rename to test/integration/targets/nxos_config/tests/common/src_match_none.yaml index 121517a42b..b3843ad70a 100644 --- a/test/integration/targets/nxos_config/tests/cli/src_match_none.yaml +++ b/test/integration/targets/nxos_config/tests/common/src_match_none.yaml @@ -1,5 +1,8 @@ --- -- debug: msg="START cli/src_match_none.yaml" +- debug: msg="START {{ connection.transport }}/src_match_none.yaml" + +# Select interface for test +- set_fact: intname="{{ nxos_int1 }}" - name: setup nxos_config: @@ -7,14 +10,18 @@ - no description - no shutdown parents: - - interface Ethernet2/5 + - "interface {{ intname }}" match: none - provider: "{{ cli }}" + provider: "{{ connection }}" - name: configure device with config nxos_config: - src: basic/config.j2 - provider: "{{ cli }}" + commands: + - description this is a test + - shutdown + parents: + - "interface {{ intname }}" + provider: "{{ connection }}" match: none defaults: yes register: result @@ -27,8 +34,12 @@ - name: check device with config nxos_config: - src: basic/config.j2 - provider: "{{ cli }}" + commands: + - description this is a test + - shutdown + parents: + - "interface {{ intname }}" + provider: "{{ connection }}" defaults: yes register: result @@ -39,4 +50,4 @@ - "result.changed == false" - "result.updates is not defined" -- debug: msg="END cli/src_match_none.yaml" +- debug: msg="END {{ connection.transport }}/src_match_none.yaml" diff --git a/test/integration/targets/nxos_config/tests/cli/sublevel_block.yaml b/test/integration/targets/nxos_config/tests/common/sublevel_block.yaml similarity index 79% rename from test/integration/targets/nxos_config/tests/cli/sublevel_block.yaml rename to test/integration/targets/nxos_config/tests/common/sublevel_block.yaml index fc53543da3..9cdd4fc48d 100644 --- a/test/integration/targets/nxos_config/tests/cli/sublevel_block.yaml +++ b/test/integration/targets/nxos_config/tests/common/sublevel_block.yaml @@ -1,5 +1,5 @@ --- -- debug: msg='START cli/sublevel_block.yaml' +- debug: msg='START {{ connection.transport }}/sublevel_block.yaml' - name: setup nxos_config: @@ -8,10 +8,10 @@ - 20 permit ip 2.2.2.2/32 any log - 30 permit ip 3.3.3.3/32 any log parents: ip access-list test - provider: "{{ cli }}" + provider: "{{ connection }}" match: none -- name: configure sub level command using block resplace +- name: configure sub level command using block replace nxos_config: lines: - 10 permit ip 1.1.1.1/32 any log @@ -20,7 +20,7 @@ - 40 permit ip 4.4.4.4/32 any log parents: ip access-list test replace: block - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -41,7 +41,7 @@ - 40 permit ip 4.4.4.4/32 any log parents: ip access-list test replace: block - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -51,7 +51,7 @@ - name: teardown nxos_config: lines: no ip access-list test - provider: "{{ cli }}" + provider: "{{ connection }}" match: none -- debug: msg='END cli/sublevel_block.yaml' +- debug: msg='END {{ connection.transport }}/sublevel_block.yaml' diff --git a/test/integration/targets/nxos_config/tests/nxapi/backup.yaml b/test/integration/targets/nxos_config/tests/nxapi/backup.yaml deleted file mode 100644 index bc7a511da8..0000000000 --- a/test/integration/targets/nxos_config/tests/nxapi/backup.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- -- debug: msg="START nxapi/backup.yaml" - -- name: setup - nxos_config: - commands: - - no description - - no shutdown - parents: - - interface Ethernet2/5 - match: none - provider: "{{ nxapi }}" - -- name: collect any backup files - find: - paths: "{{ role_path }}/backup" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_files - delegate_to: localhost - -- name: delete backup files - file: - path: "{{ item.path }}" - state: absent - with_items: "{{backup_files.files|default([])}}" - -- name: configure device with config - nxos_config: - src: basic/config.j2 - backup: yes - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - "result.changed == true" - - "result.updates is defined" - -- name: collect any backup files - find: - paths: "{{ role_path }}/backup" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_files - delegate_to: localhost - -- assert: - that: - - "backup_files.files is defined" - -- debug: msg="END nxapi/backup.yaml" diff --git a/test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml b/test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml deleted file mode 100644 index f0ab6f3158..0000000000 --- a/test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml +++ /dev/null @@ -1,40 +0,0 @@ ---- -- debug: msg="START nxapi/src_match_none.yaml" - -- name: setup - nxos_config: - commands: - - no description - - no shutdown - parents: - - interface Ethernet2/5 - match: none - provider: "{{ nxapi }}" - -- name: configure device with config - nxos_config: - src: basic/config.j2 - provider: "{{ nxapi }}" - match: none - register: result - -- assert: - that: - - "result.changed == true" -# https://github.com/ansible/ansible-modules-core/issues/4807 - - "result.updates is defined" - -- name: check device with config - nxos_config: - src: basic/config.j2 - provider: "{{ nxapi }}" - register: result - -- assert: - that: - # Idempotent test -# https://github.com/ansible/ansible-modules-core/issues/4807 - - "result.changed == false" - - "result.updates is not defined" - -- debug: msg="END nxapi/src_match_none.yaml" diff --git a/test/integration/targets/nxos_config/tests/nxapi/sublevel_block.yaml b/test/integration/targets/nxos_config/tests/nxapi/sublevel_block.yaml deleted file mode 100644 index b247c38712..0000000000 --- a/test/integration/targets/nxos_config/tests/nxapi/sublevel_block.yaml +++ /dev/null @@ -1,59 +0,0 @@ ---- -- debug: msg="START nxapi/sublevel_block.yaml" - -- name: setup - nxos_config: - lines: - - 10 permit ip 1.1.1.1/32 any log - - 20 permit ip 2.2.2.2/32 any log - - 30 permit ip 3.3.3.3/32 any log - parents: ip access-list test - before: no ip access-list test - provider: "{{ nxapi }}" - match: none - ignore_errors: yes - -- name: configure sub level command using block resplace - nxos_config: - lines: - - 10 permit ip 1.1.1.1/32 any log - - 20 permit ip 2.2.2.2/32 any log - - 30 permit ip 3.3.3.3/32 any log - - 40 permit ip 4.4.4.4/32 any log - parents: ip access-list test - replace: block - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - "result.changed == true" - - "'ip access-list test' in result.updates" - - "'10 permit ip 1.1.1.1/32 any log' in result.updates" - - "'20 permit ip 2.2.2.2/32 any log' in result.updates" - - "'30 permit ip 3.3.3.3/32 any log' in result.updates" - - "'40 permit ip 4.4.4.4/32 any log' in result.updates" - -- name: check sub level command using block replace - nxos_config: - lines: - - 10 permit ip 1.1.1.1/32 any log - - 20 permit ip 2.2.2.2/32 any log - - 30 permit ip 3.3.3.3/32 any log - - 40 permit ip 4.4.4.4/32 any log - parents: ip access-list test - replace: block - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - "result.changed == false" - -- name: teardown - nxos_config: - lines: no ip access-list test - provider: "{{ nxapi }}" - match: none - -- debug: msg="END nxapi/sublevel_block.yaml"