diff options
Diffstat (limited to 'test/integration/targets/nxos_config/tests/common')
7 files changed, 262 insertions, 0 deletions
diff --git a/test/integration/targets/nxos_config/tests/common/backup.yaml b/test/integration/targets/nxos_config/tests/common/backup.yaml new file mode 100644 index 0000000000..6f7cd37b41 --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/backup.yaml @@ -0,0 +1,50 @@ +--- +- debug: msg="START {{ connection.transport }}/backup.yaml" + +- name: setup + nxos_config: + commands: + - no description + - no shutdown + parents: + - interface Ethernet2/5 + match: none + provider: "{{ connection }}" + +- 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: "{{ connection }}" + 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 {{ connection.transport }}/backup.yaml" diff --git a/test/integration/targets/nxos_config/tests/common/defaults.yaml b/test/integration/targets/nxos_config/tests/common/defaults.yaml new file mode 100644 index 0000000000..84b8614b61 --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/defaults.yaml @@ -0,0 +1,42 @@ +--- +- debug: msg="START {{ connection.transport }}/defaults.yaml" + +- name: setup + nxos_config: + commands: + - no description + - shutdown + parents: + - interface Ethernet2/5 + match: none + provider: "{{ connection }}" + +- name: configure device with defaults included + nxos_config: + src: defaults/config.j2 + defaults: yes + provider: "{{ connection }}" + register: result + +- debug: var=result + +- assert: + that: + - "result.changed == true" + - "result.updates is defined" + +- name: check device with defaults included + nxos_config: + src: defaults/config.j2 + defaults: yes + provider: "{{ connection }}" + register: result + +- debug: var=result + +- assert: + that: + - "result.changed == false" + - "result.updates is not defined" + +- debug: msg="END {{ connection.transport }}/defaults.yaml" diff --git a/test/integration/targets/nxos_config/tests/common/save.yaml b/test/integration/targets/nxos_config/tests/common/save.yaml new file mode 100644 index 0000000000..7f15f6c677 --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/save.yaml @@ -0,0 +1,35 @@ +--- +- debug: msg="START {{ connection.transport }}/save.yaml" + +- name: setup + nxos_config: + commands: + - no description + - no shutdown + parents: + - interface Ethernet2/5 + match: none + provider: "{{ connection }}" + + +- name: save config + nxos_config: + save: true + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == true" + +- name: save should always run + nxos_config: + save: true + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == true" + +- debug: msg="END {{ connection.transport }}/save.yaml" diff --git a/test/integration/targets/nxos_config/tests/common/src_basic.yaml b/test/integration/targets/nxos_config/tests/common/src_basic.yaml new file mode 100644 index 0000000000..e2d3287b6e --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/src_basic.yaml @@ -0,0 +1,40 @@ +--- +- debug: msg="START {{ connection.transport }}/src_basic.yaml" + +- name: setup + nxos_config: + commands: + - no description + - no shutdown + parents: + - interface Ethernet2/5 + match: none + provider: "{{ connection }}" + +- name: configure device with config + nxos_config: + src: basic/config.j2 + defaults: yes + provider: "{{ connection }}" + 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 + defaults: yes + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == false" +# https://github.com/ansible/ansible-modules-core/issues/4807 + - "result.updates is not defined" + +- debug: msg="END {{ connection.transport }}/src_basic.yaml" diff --git a/test/integration/targets/nxos_config/tests/common/src_invalid.yaml b/test/integration/targets/nxos_config/tests/common/src_invalid.yaml new file mode 100644 index 0000000000..e7400e5789 --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/src_invalid.yaml @@ -0,0 +1,19 @@ +--- +- debug: msg="START {{ connection.transport }}/src_invalid.yaml" + + +# Defend https://github.com/ansible/ansible-modules-core/issues/4797 +- name: configure with invalid src + nxos_config: + src: basic/foobar.j2 + provider: "{{ connection }}" + register: result + ignore_errors: yes + +- assert: + that: + - "result.changed == false" + - "result.failed == true" + - "result.msg == 'path specified in src not found'" + +- debug: msg="END {{ connection.transport }}/src_invalid.yaml" diff --git a/test/integration/targets/nxos_config/tests/common/toplevel.yaml b/test/integration/targets/nxos_config/tests/common/toplevel.yaml new file mode 100644 index 0000000000..0ff6b0b3bd --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/toplevel.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg='START {{ connection.transport }}/toplevel.yaml' + +- name: setup + nxos_config: + lines: hostname {{ inventory_hostname_short }} + provider: "{{ connection }}" + match: none + +- name: configure top level command + nxos_config: + lines: hostname foo + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == true" + - "'hostname foo' in result.updates" + +- name: configure top level command idempotent check + nxos_config: + lines: hostname foo + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == false" + +- name: teardown + nxos_config: + lines: hostname {{ inventory_hostname_short }} + provider: "{{ connection }}" + match: none + +- debug: msg='END {{ connection.transport }}/toplevel.yaml' diff --git a/test/integration/targets/nxos_config/tests/common/toplevel_nonidempotent.yaml b/test/integration/targets/nxos_config/tests/common/toplevel_nonidempotent.yaml new file mode 100644 index 0000000000..e950a97430 --- /dev/null +++ b/test/integration/targets/nxos_config/tests/common/toplevel_nonidempotent.yaml @@ -0,0 +1,39 @@ +--- +- debug: msg="START {{ connection.transport }}/nonidempotent.yaml" + +- name: setup + nxos_config: + lines: hostname {{ inventory_hostname_short }} + provider: "{{ connection }}" + match: none + +- name: configure top level command + nxos_config: + lines: hostname foo + provider: "{{ connection }}" + match: strict + register: result + +- assert: + that: + - "result.changed == true" + - "'hostname foo' in result.updates" + +- name: configure top level command idempotent check + nxos_config: + lines: hostname foo + provider: "{{ connection }}" + match: strict + register: result + +- assert: + that: + - "result.changed == true" + +- name: teardown + nxos_config: + lines: hostname {{ inventory_hostname_short }} + provider: "{{ connection }}" + match: none + +- debug: msg="END {{ connection.transport }}/nonidempotent.yaml" |