diff options
Diffstat (limited to 'test')
7 files changed, 278 insertions, 49 deletions
diff --git a/test/integration/targets/nxos_file_copy/meta/main.yml b/test/integration/targets/nxos_file_copy/meta/main.yml index ae741cbdc7..1530e79eed 100644 --- a/test/integration/targets/nxos_file_copy/meta/main.yml +++ b/test/integration/targets/nxos_file_copy/meta/main.yml @@ -1,2 +1,5 @@ dependencies: - - prepare_nxos_tests + # prepare_nxos_tests is not needed for this test and simply adds overhead. + # This can be uncommented in the future if needed. + # + # - prepare_nxos_tests diff --git a/test/integration/targets/nxos_file_copy/tasks/cli.yaml b/test/integration/targets/nxos_file_copy/tasks/cli.yaml index ac06cd7ea7..9243812668 100644 --- a/test/integration/targets/nxos_file_copy/tasks/cli.yaml +++ b/test/integration/targets/nxos_file_copy/tasks/cli.yaml @@ -25,9 +25,3 @@ with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run - -- name: run test cases (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_file_copy/tests/cli/input_validation.yaml b/test/integration/targets/nxos_file_copy/tests/cli/input_validation.yaml new file mode 100644 index 0000000000..606633f0b1 --- /dev/null +++ b/test/integration/targets/nxos_file_copy/tests/cli/input_validation.yaml @@ -0,0 +1,65 @@ +--- +- debug: msg="START nxos_file_copy input_validation test" + +- name: "Input Validation - param should be type <str>" + nxos_file_copy: + remote_file: 500 + register: result + ignore_errors: true + +- assert: + that: + - result is search('Playbook parameter <remote_file> value should be of type <str>') + +- name: "Input Validation - param should be type <int>" + nxos_file_copy: + file_pull_timeout: 'foobar' + register: result + ignore_errors: true + +- assert: + that: + - result is search('Playbook parameter <file_pull_timeout> value should be of type <int>') + +- name: "Input Validation - param should be type <bool>" + nxos_file_copy: + file_pull: 'foobar' + register: result + ignore_errors: true + +- assert: + that: + - result is search('Playbook parameter <file_pull> value should be of type <bool>') + +- name: "Input Validation - param <file_pull> <remote_file> dependency" + nxos_file_copy: + file_pull: True + register: result + ignore_errors: true + +- assert: + that: + - result is search('Playbook parameter <remote_file> required when <file_pull> is True') + +- name: "Input Validation - param <file_pull> <remote_scp_server> dependency" + nxos_file_copy: + file_pull: True + remote_file: "/network-integration.cfg" + register: result + ignore_errors: true + +- assert: + that: + - result is search('Playbook parameter <remote_scp_server> required when <file_pull> is True') + +- name: "Input Validation - remote_scp_server params together" + nxos_file_copy: + remote_scp_server: "{{ inventory_hostname_short }}" + register: result + ignore_errors: true + +- assert: + that: + - result is search('Playbook parameters <remote_scp_server>, <remote_scp_server_user>, ,remote_scp_server_password> must all be set together') + +- debug: msg="END nxos_file_copy input_validation test" diff --git a/test/integration/targets/nxos_file_copy/tests/cli/negative.yaml b/test/integration/targets/nxos_file_copy/tests/cli/negative.yaml new file mode 100644 index 0000000000..58d091663c --- /dev/null +++ b/test/integration/targets/nxos_file_copy/tests/cli/negative.yaml @@ -0,0 +1,133 @@ +--- +- debug: msg="START nxos_file_copy negative test" + +# This test uses a file that is committed to the Ansible core repository. +# The file name and relative path is test/integration/targets/network-integration.cfg +- set_fact: test_source_file="network-integration.cfg" +- set_fact: test_destination_file="test_destination_file" + +# ------------------------- +# Tests for file_pull False +# ------------------------- +- name: "Attempt to copy file to invalid file_system" + nxos_file_copy: + file_pull: False + local_file: "./{{ test_source_file }}" + file_system: "invalid_media_type:" + connect_ssh_port: "{{ ansible_ssh_port }}" + register: result + ignore_errors: true + +- assert: + that: + - result is search('Invalid nxos filesystem invalid_media_type:') + +- name: "Attempt to copy source file that does not exist on Ansible controller" + nxos_file_copy: + file_pull: False + local_file: "./{{ test_source_file }}_does_not_exist" + file_system: "bootflash:" + connect_ssh_port: "{{ ansible_ssh_port }}" + register: result + ignore_errors: true + +- assert: + that: + - result is search('Local file ./network-integration.cfg_does_not_exist not found') + +# ------------------------- +# Tests for file_pull True +# ------------------------- +- name: "Try and copy file using an invalid remote scp server name" + nxos_file_copy: + file_pull: True + file_pull_timeout: 10 + remote_file: "/{{ test_destination_file }}" + local_file: "{{ test_destination_file }}_copy" + local_file_directory: "dir1/dir2/dir3" + remote_scp_server: "scp_server_gone.example.com" + remote_scp_server_user: "{{ ansible_ssh_user }}" + remote_scp_server_password: "{{ ansible_ssh_pass }}" + register: result + ignore_errors: true + +- assert: + that: + - "result.changed == false" + - "'copy scp:' in result.copy_cmd" + - "'bootflash:' in result.file_system" + - "'No Transfer' in result.transfer_status" + +- assert: + that: + - result.error_data is search("ERROR Could not resolve hostname|Copying to.*from this server name is not permitted") + +- name: "Try and copy file using an invalid remote scp server ip address" + nxos_file_copy: + file_pull: True + file_pull_timeout: 300 + remote_file: "/{{ test_destination_file }}" + local_file: "{{ test_destination_file }}_copy" + local_file_directory: "dir1/dir2/dir3" + remote_scp_server: "192.168.55.55" + remote_scp_server_user: "{{ ansible_ssh_user }}" + remote_scp_server_password: "{{ ansible_ssh_pass }}" + register: result + ignore_errors: true + +- assert: + that: + - "result.changed == false" + - "'copy scp:' in result.copy_cmd" + - "'timed out' in result.error_data" + - "'bootflash:' in result.file_system" + - "'No Transfer' in result.transfer_status" + +# Sometimes the previous negative test needs a few seconds after the timeout +# failure before the next negative test is executed. +- pause: + seconds: 10 + +- name: "Try and copy file using an invalid username" + nxos_file_copy: + file_pull: True + file_pull_timeout: 10 + remote_file: "/{{ test_destination_file }}" + local_file: "{{ test_destination_file }}_copy" + local_file_directory: "dir1/dir2/dir3" + remote_scp_server: "{{ inventory_hostname_short }}" + remote_scp_server_user: "invalid_user_name" + remote_scp_server_password: "{{ ansible_ssh_pass }}" + register: result + ignore_errors: true + +- assert: + that: + - "result.changed == false" + - "'copy scp:' in result.copy_cmd" + - "'Too many authentication failures' in result.error_data" + - "'bootflash:' in result.file_system" + - "'No Transfer' in result.transfer_status" + +- name: "Try and copy file using an invalid password" + nxos_file_copy: + file_pull: True + file_pull_timeout: 10 + remote_file: "/{{ test_destination_file }}" + local_file: "{{ test_destination_file }}_copy" + local_file_directory: "dir1/dir2/dir3" + remote_scp_server: "{{ inventory_hostname_short }}" + remote_scp_server_user: "{{ ansible_ssh_user }}" + remote_scp_server_password: "invalid_password" + register: result + ignore_errors: true + +- assert: + that: + - "result.changed == false" + - "'copy scp:' in result.copy_cmd" + - "'Too many authentication failures' in result.error_data" + - "'bootflash:' in result.file_system" + - "'No Transfer' in result.transfer_status" + +- debug: msg="END nxos_file_copy negative test" diff --git a/test/integration/targets/nxos_file_copy/tests/cli/sanity.yaml b/test/integration/targets/nxos_file_copy/tests/cli/sanity.yaml index e8494e59a3..3fa3ea84f3 100644 --- a/test/integration/targets/nxos_file_copy/tests/cli/sanity.yaml +++ b/test/integration/targets/nxos_file_copy/tests/cli/sanity.yaml @@ -1,35 +1,45 @@ --- - debug: msg="START connection={{ ansible_connection }} nxos_file_copy sanity test" +# This test uses a file that is committed to the Ansible core repository. +# The file name and relative path is test/integration/targets/network-integration.cfg +- set_fact: test_source_file="network-integration.cfg" +- set_fact: test_destination_file="test_destination_file" + - name: "Setup - Remove existing file" nxos_command: &remove_file commands: - terminal dont-ask - - delete network-integration.cfg - - delete bootflash:/dir1/dir2/dir3/network-integration_copy.cfg + - "delete {{ test_source_file }}" + - "delete {{ test_destination_file }}" + - "delete bootflash:/dir1/dir2/dir3/*" - rmdir dir1/dir2/dir3 - rmdir dir1/dir2 - rmdir dir1 ignore_errors: yes - name: "Setup - Turn on feature scp-server" - nxos_feature: + nxos_feature: feature: scp-server state: enabled - block: - - name: "Copy network-integration.cfg to bootflash" + - name: "Copy {{ test_source_file }} file from Ansible controller to bootflash" nxos_file_copy: ©_file_same_name - local_file: "./network-integration.cfg" + local_file: "./{{ test_source_file }}" file_system: "bootflash:" connect_ssh_port: "{{ ansible_ssh_port }}" register: result - - assert: &true + - assert: that: - "result.changed == true" + - "'bootflash:' in result.file_system" + - "'./{{ test_source_file }}' in result.local_file" + - "'network-integration.cfg' in result.remote_file" + - "'Sent: File copied to remote device.' in result.transfer_status" - - name: "Check Idempotence - Copy network-integration.cfg to bootflash" + - name: "Idempotence - Copy {{ test_source_file }} file from Ansible controller to bootflash" nxos_file_copy: *copy_file_same_name register: result @@ -41,47 +51,77 @@ nxos_command: *remove_file register: result - - name: "Copy inventory.networking.template to bootflash as another name" + - name: "Copy {{ test_source_file }} file from Ansible controller to bootflash renamed as {{ test_destination_file }}" nxos_file_copy: ©_file_different_name - local_file: "./inventory.networking.template" - remote_file: "network-integration.cfg" + local_file: "./{{ test_source_file }}" + remote_file: "{{ test_destination_file }}" file_system: "bootflash:" connect_ssh_port: "{{ ansible_ssh_port }}" register: result - - assert: *true + - assert: + that: + - "result.changed == true" + - "'bootflash:' in result.file_system" + - "'./{{ test_source_file }}' in result.local_file" + - "'{{ test_destination_file }}' in result.remote_file" + - "'Sent: File copied to remote device.' in result.transfer_status" - - name: "Check Idempotence - Copy inventory.networking.template to bootflash as another name" + - name: "Idempotence - Copy {{ test_source_file }} file from Ansible controller to bootflash renamed as {{ test_destination_file }}" nxos_file_copy: *copy_file_different_name register: result + - name: "Verify file_pull true options have no impact when file_true is false" + nxos_file_copy: + file_pull: False + file_pull_timeout: 1200 + file_pull_compact: True + file_pull_kstack: True + local_file_directory: "dir1/dir2/dir3" + remote_scp_server: "{{ inventory_hostname_short }}" + remote_scp_server_user: "{{ ansible_ssh_user }}" + remote_scp_server_password: "{{ ansible_ssh_pass }}" + # Parameters above are only used when file_pull is True + local_file: "./{{ test_source_file }}" + remote_file: "{{ test_destination_file }}" + file_system: "bootflash:" + connect_ssh_port: "{{ ansible_ssh_port }}" + register: result + - assert: *false - - block: - - name: "Copy file using file_pull" - nxos_file_copy: ©_pull - file_pull: True - file_pull_timeout: 1200 - remote_file: "/network-integration.cfg" - local_file: "network-integration_copy.cfg" - local_file_directory: "dir1/dir2/dir3" - remote_scp_server: "{{ inventory_hostname_short }}" - remote_scp_server_user: "{{ ansible_ssh_user }}" - remote_scp_server_password: "{{ ansible_ssh_pass }}" - register: result - - - assert: *true - - - name: "Overwrite the file" - nxos_file_copy: *copy_pull - register: result - - - assert: *true - ignore_errors: yes + # This step validates the ability to initiate the copy from the nxos device + # to pull a file from a remote file server to the nxos bootflash device. + # + # In this case we are using the nxos device as the remote file server so we + # copy a file from bootflash: to bootflash:dir1/dir2/dir3 + - name: "Initiate copy from nxos device to copy {{ test_destination_file }} to bootflash:dir1/dir2/dir3/{{ test_destination_file }}_copy" + nxos_file_copy: ©_pull + file_pull: True + file_pull_timeout: 30 + remote_file: "/{{ test_destination_file }}" + local_file: "{{ test_destination_file }}_copy" + local_file_directory: "dir1/dir2/dir3" + remote_scp_server: "{{ inventory_hostname_short }}" + remote_scp_server_user: "{{ ansible_ssh_user }}" + remote_scp_server_password: "{{ ansible_ssh_pass }}" + register: result - rescue: + - assert: &overwrite + that: + - "result.changed == true" + - "'copy scp:' in result.copy_cmd" + - "'bootflash:' in result.file_system" + - "'bootflash:dir1/dir2/dir3/{{ test_destination_file }}_copy' in result.local_file" + - "'/{{ test_destination_file }}' in result.remote_file" + - "'Received: File copied/pulled to nxos device from remote scp server.' in result.transfer_status" + - "'{{ inventory_hostname_short }}' in result.remote_scp_server" + + - name: "Overwrite the file" + nxos_file_copy: *copy_pull + register: result - - debug: msg="TRANSPORT:CLI nxos_file_copy failure detected" + - assert: *overwrite always: diff --git a/test/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml b/test/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml index de0693d51a..7cd44709ea 100644 --- a/test/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml +++ b/test/integration/targets/nxos_file_copy/tests/nxapi/badtransport.yaml @@ -12,6 +12,6 @@ - assert: that: - - result.failed and result.msg is search('Transport') + - result.failed and result.msg is search('Connection type must be <network_cli>') - debug: msg="END nxapi/badtransport.yaml" diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index 3d32bb24b9..22ed554e7c 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -4221,12 +4221,6 @@ lib/ansible/modules/network/nxos/nxos_feature.py validate-modules:doc-default-do lib/ansible/modules/network/nxos/nxos_feature.py validate-modules:doc-default-incompatible-type lib/ansible/modules/network/nxos/nxos_feature.py validate-modules:parameter-type-not-in-doc lib/ansible/modules/network/nxos/nxos_feature.py validate-modules:doc-missing-type -lib/ansible/modules/network/nxos/nxos_file_copy.py future-import-boilerplate -lib/ansible/modules/network/nxos/nxos_file_copy.py metaclass-boilerplate -lib/ansible/modules/network/nxos/nxos_file_copy.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/nxos/nxos_file_copy.py validate-modules:doc-default-incompatible-type -lib/ansible/modules/network/nxos/nxos_file_copy.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/nxos/nxos_file_copy.py validate-modules:doc-missing-type lib/ansible/modules/network/nxos/nxos_gir.py future-import-boilerplate lib/ansible/modules/network/nxos/nxos_gir.py metaclass-boilerplate lib/ansible/modules/network/nxos/nxos_gir.py validate-modules:doc-default-does-not-match-spec |