|
1 | 1 | ---
|
2 | 2 | - debug: msg="START connection={{ ansible_connection }} nxos_file_copy sanity test"
|
3 | 3 |
|
| 4 | +# This test uses a file that is committed to the Ansible core repository. |
| 5 | +# The file name and relative path is test/integration/targets/network-integration.cfg |
| 6 | +- set_fact: test_source_file="network-integration.cfg" |
| 7 | +- set_fact: test_destination_file="test_destination_file" |
| 8 | + |
4 | 9 | - name: "Setup - Remove existing file"
|
5 | 10 | nxos_command: &remove_file
|
6 | 11 | commands:
|
7 | 12 | - terminal dont-ask
|
8 |
| - - delete network-integration.cfg |
9 |
| - - delete bootflash:/dir1/dir2/dir3/network-integration_copy.cfg |
| 13 | + - "delete {{ test_source_file }}" |
| 14 | + - "delete {{ test_destination_file }}" |
| 15 | + - "delete bootflash:/dir1/dir2/dir3/*" |
10 | 16 | - rmdir dir1/dir2/dir3
|
11 | 17 | - rmdir dir1/dir2
|
12 | 18 | - rmdir dir1
|
13 | 19 | ignore_errors: yes
|
14 | 20 |
|
15 | 21 | - name: "Setup - Turn on feature scp-server"
|
16 |
| - nxos_feature: |
| 22 | + nxos_feature: |
17 | 23 | feature: scp-server
|
18 | 24 | state: enabled
|
19 | 25 |
|
20 | 26 | - block:
|
21 |
| - - name: "Copy network-integration.cfg to bootflash" |
| 27 | + - name: "Copy {{ test_source_file }} file from Ansible controller to bootflash" |
22 | 28 | nxos_file_copy: ©_file_same_name
|
23 |
| - local_file: "./network-integration.cfg" |
| 29 | + local_file: "./{{ test_source_file }}" |
24 | 30 | file_system: "bootflash:"
|
25 | 31 | connect_ssh_port: "{{ ansible_ssh_port }}"
|
26 | 32 | register: result
|
27 | 33 |
|
28 |
| - - assert: &true |
| 34 | + - assert: |
29 | 35 | that:
|
30 | 36 | - "result.changed == true"
|
| 37 | + - "'bootflash:' in result.file_system" |
| 38 | + - "'./{{ test_source_file }}' in result.local_file" |
| 39 | + - "'network-integration.cfg' in result.remote_file" |
| 40 | + - "'Sent: File copied to remote device.' in result.transfer_status" |
31 | 41 |
|
32 |
| - - name: "Check Idempotence - Copy network-integration.cfg to bootflash" |
| 42 | + - name: "Idempotence - Copy {{ test_source_file }} file from Ansible controller to bootflash" |
33 | 43 | nxos_file_copy: *copy_file_same_name
|
34 | 44 | register: result
|
35 | 45 |
|
|
41 | 51 | nxos_command: *remove_file
|
42 | 52 | register: result
|
43 | 53 |
|
44 |
| - - name: "Copy inventory.networking.template to bootflash as another name" |
| 54 | + - name: "Copy {{ test_source_file }} file from Ansible controller to bootflash renamed as {{ test_destination_file }}" |
45 | 55 | nxos_file_copy: ©_file_different_name
|
46 |
| - local_file: "./inventory.networking.template" |
47 |
| - remote_file: "network-integration.cfg" |
| 56 | + local_file: "./{{ test_source_file }}" |
| 57 | + remote_file: "{{ test_destination_file }}" |
48 | 58 | file_system: "bootflash:"
|
49 | 59 | connect_ssh_port: "{{ ansible_ssh_port }}"
|
50 | 60 | register: result
|
51 | 61 |
|
52 |
| - - assert: *true |
| 62 | + - assert: |
| 63 | + that: |
| 64 | + - "result.changed == true" |
| 65 | + - "'bootflash:' in result.file_system" |
| 66 | + - "'./{{ test_source_file }}' in result.local_file" |
| 67 | + - "'{{ test_destination_file }}' in result.remote_file" |
| 68 | + - "'Sent: File copied to remote device.' in result.transfer_status" |
53 | 69 |
|
54 |
| - - name: "Check Idempotence - Copy inventory.networking.template to bootflash as another name" |
| 70 | + - name: "Idempotence - Copy {{ test_source_file }} file from Ansible controller to bootflash renamed as {{ test_destination_file }}" |
55 | 71 | nxos_file_copy: *copy_file_different_name
|
56 | 72 | register: result
|
57 | 73 |
|
| 74 | + - name: "Verify file_pull true options have no impact when file_true is false" |
| 75 | + nxos_file_copy: |
| 76 | + file_pull: False |
| 77 | + file_pull_timeout: 1200 |
| 78 | + file_pull_compact: True |
| 79 | + file_pull_kstack: True |
| 80 | + local_file_directory: "dir1/dir2/dir3" |
| 81 | + remote_scp_server: "{{ inventory_hostname_short }}" |
| 82 | + remote_scp_server_user: "{{ ansible_ssh_user }}" |
| 83 | + remote_scp_server_password: "{{ ansible_ssh_pass }}" |
| 84 | + # Parameters above are only used when file_pull is True |
| 85 | + local_file: "./{{ test_source_file }}" |
| 86 | + remote_file: "{{ test_destination_file }}" |
| 87 | + file_system: "bootflash:" |
| 88 | + connect_ssh_port: "{{ ansible_ssh_port }}" |
| 89 | + register: result |
| 90 | + |
58 | 91 | - assert: *false
|
59 | 92 |
|
60 |
| - - block: |
61 |
| - - name: "Copy file using file_pull" |
62 |
| - nxos_file_copy: ©_pull |
63 |
| - file_pull: True |
64 |
| - file_pull_timeout: 1200 |
65 |
| - remote_file: "/network-integration.cfg" |
66 |
| - local_file: "network-integration_copy.cfg" |
67 |
| - local_file_directory: "dir1/dir2/dir3" |
68 |
| - remote_scp_server: "{{ inventory_hostname_short }}" |
69 |
| - remote_scp_server_user: "{{ ansible_ssh_user }}" |
70 |
| - remote_scp_server_password: "{{ ansible_ssh_pass }}" |
71 |
| - register: result |
72 |
| - |
73 |
| - - assert: *true |
74 |
| - |
75 |
| - - name: "Overwrite the file" |
76 |
| - nxos_file_copy: *copy_pull |
77 |
| - register: result |
78 |
| - |
79 |
| - - assert: *true |
80 |
| - ignore_errors: yes |
| 93 | + # This step validates the ability to initiate the copy from the nxos device |
| 94 | + # to pull a file from a remote file server to the nxos bootflash device. |
| 95 | + # |
| 96 | + # In this case we are using the nxos device as the remote file server so we |
| 97 | + # copy a file from bootflash: to bootflash:dir1/dir2/dir3 |
| 98 | + - name: "Initiate copy from nxos device to copy {{ test_destination_file }} to bootflash:dir1/dir2/dir3/{{ test_destination_file }}_copy" |
| 99 | + nxos_file_copy: ©_pull |
| 100 | + file_pull: True |
| 101 | + file_pull_timeout: 30 |
| 102 | + remote_file: "/{{ test_destination_file }}" |
| 103 | + local_file: "{{ test_destination_file }}_copy" |
| 104 | + local_file_directory: "dir1/dir2/dir3" |
| 105 | + remote_scp_server: "{{ inventory_hostname_short }}" |
| 106 | + remote_scp_server_user: "{{ ansible_ssh_user }}" |
| 107 | + remote_scp_server_password: "{{ ansible_ssh_pass }}" |
| 108 | + register: result |
81 | 109 |
|
82 |
| - rescue: |
| 110 | + - assert: &overwrite |
| 111 | + that: |
| 112 | + - "result.changed == true" |
| 113 | + - "'copy scp:' in result.copy_cmd" |
| 114 | + - "'bootflash:' in result.file_system" |
| 115 | + - "'bootflash:dir1/dir2/dir3/{{ test_destination_file }}_copy' in result.local_file" |
| 116 | + - "'/{{ test_destination_file }}' in result.remote_file" |
| 117 | + - "'Received: File copied/pulled to nxos device from remote scp server.' in result.transfer_status" |
| 118 | + - "'{{ inventory_hostname_short }}' in result.remote_scp_server" |
| 119 | + |
| 120 | + - name: "Overwrite the file" |
| 121 | + nxos_file_copy: *copy_pull |
| 122 | + register: result |
83 | 123 |
|
84 |
| - - debug: msg="TRANSPORT:CLI nxos_file_copy failure detected" |
| 124 | + - assert: *overwrite |
85 | 125 |
|
86 | 126 | always:
|
87 | 127 |
|
|
0 commit comments