| 1 |
# Test code for the ACI modules |
| 2 |
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <[email protected]> |
| 3 |
# Copyright: (c) 2020, Cindy Zhao (@cizhao) <[email protected]> |
| 4 |
|
| 5 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
# CLEAN ENVIRONMENT |
| 8 |
- name: Remove firmware source |
| 9 |
cisco.aci.aci_firmware_source: &source_absent |
| 10 |
host: '{{ aci_hostname }}' |
| 11 |
username: '{{ aci_username }}' |
| 12 |
password: '{{ aci_password }}' |
| 13 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 14 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 15 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 16 |
output_level: '{{ aci_output_level | default("info") }}' |
| 17 |
source: '{{ item }}' |
| 18 |
state: absent |
| 19 |
loop: |
| 20 |
- ansible_test_1 |
| 21 |
- ansible_test_2 |
| 22 |
|
| 23 |
# ADD SOURCE |
| 24 |
- name: Add source (check_mode) |
| 25 |
cisco.aci.aci_firmware_source: &source_present |
| 26 |
host: '{{ aci_hostname }}' |
| 27 |
username: '{{ aci_username }}' |
| 28 |
password: '{{ aci_password }}' |
| 29 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 30 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 31 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 32 |
output_level: '{{ aci_output_level | default("info") }}' |
| 33 |
source: ansible_test_1 |
| 34 |
url: foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip |
| 35 |
url_protocol: http |
| 36 |
state: present |
| 37 |
check_mode: true |
| 38 |
register: cm_add_source |
| 39 |
|
| 40 |
- name: Add source (normal mode) |
| 41 |
cisco.aci.aci_firmware_source: |
| 42 |
<<: *source_present |
| 43 |
register: nm_add_source |
| 44 |
|
| 45 |
- name: Verify add_source |
| 46 |
ansible.builtin.assert: |
| 47 |
that: |
| 48 |
- cm_add_source is changed |
| 49 |
- nm_add_source is changed |
| 50 |
- cm_add_source.sent.firmwareOSource.attributes.name == nm_add_source.sent.firmwareOSource.attributes.name == 'ansible_test_1' |
| 51 |
- cm_add_source.sent.firmwareOSource.attributes.proto == nm_add_source.sent.firmwareOSource.attributes.proto == 'http' |
| 52 |
- cm_add_source.sent.firmwareOSource.attributes.url == nm_add_source.sent.firmwareOSource.attributes.url == 'foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip' |
| 53 |
- cm_add_source.proposed.firmwareOSource.attributes.name == nm_add_source.proposed.firmwareOSource.attributes.name == 'ansible_test_1' |
| 54 |
- cm_add_source.proposed.firmwareOSource.attributes.proto == nm_add_source.proposed.firmwareOSource.attributes.proto == 'http' |
| 55 |
- cm_add_source.proposed.firmwareOSource.attributes.url == nm_add_source.proposed.firmwareOSource.attributes.url == 'foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip' |
| 56 |
- cm_add_source.current == cm_add_source.previous == nm_add_source.previous == [] |
| 57 |
- nm_add_source.current.0.firmwareOSource.attributes.name == 'ansible_test_1' |
| 58 |
- nm_add_source.current.0.firmwareOSource.attributes.proto == 'http' |
| 59 |
- nm_add_source.current.0.firmwareOSource.attributes.url == 'foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip' |
| 60 |
- nm_add_source.current.0.firmwareOSource.attributes.annotation == 'orchestrator:ansible' |
| 61 |
|
| 62 |
- name: Add source again (check_mode) |
| 63 |
cisco.aci.aci_firmware_source: *source_present |
| 64 |
check_mode: true |
| 65 |
register: cm_add_source_again |
| 66 |
|
| 67 |
- name: Add source again (normal mode) |
| 68 |
cisco.aci.aci_firmware_source: |
| 69 |
<<: *source_present |
| 70 |
register: nm_add_source_again |
| 71 |
|
| 72 |
- name: Verify add_source_again |
| 73 |
ansible.builtin.assert: |
| 74 |
that: |
| 75 |
- cm_add_source_again is not changed |
| 76 |
|
| 77 |
- name: Add password source |
| 78 |
cisco.aci.aci_firmware_source: &source_pass |
| 79 |
<<: *source_present |
| 80 |
source: ansible_test_pass |
| 81 |
url_password: test |
| 82 |
register: password_source |
| 83 |
|
| 84 |
- name: Add password source again |
| 85 |
cisco.aci.aci_firmware_source: |
| 86 |
<<: *source_pass |
| 87 |
register: password_source_again |
| 88 |
|
| 89 |
- name: Verify add password source |
| 90 |
ansible.builtin.assert: |
| 91 |
that: |
| 92 |
- password_source is changed |
| 93 |
- password_source.previous == [] |
| 94 |
- password_source.current.0.firmwareOSource.attributes.password is undefined |
| 95 |
- password_source.proposed.firmwareOSource.attributes.password == "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" |
| 96 |
# Idempotency is not supported when url_password is set |
| 97 |
- password_source_again is changed |
| 98 |
- password_source_again.previous == password_source.current |
| 99 |
- password_source_again.current.0.firmwareOSource.attributes.password is undefined |
| 100 |
- password_source_again.proposed.firmwareOSource.attributes.password == "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" |
| 101 |
|
| 102 |
- name: Add another source (normal mode) |
| 103 |
cisco.aci.aci_firmware_source: |
| 104 |
<<: *source_present |
| 105 |
source: ansible_test_2 |
| 106 |
register: nm_add_source |
| 107 |
|
| 108 |
# QUERY ALL SOURCES |
| 109 |
- name: Query all sources (check_mode) |
| 110 |
cisco.aci.aci_firmware_source: &source_query |
| 111 |
host: '{{ aci_hostname }}' |
| 112 |
username: '{{ aci_username }}' |
| 113 |
password: '{{ aci_password }}' |
| 114 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 115 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 116 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 117 |
output_level: '{{ aci_output_level | default("info") }}' |
| 118 |
state: query |
| 119 |
check_mode: true |
| 120 |
register: cm_query_all_sources |
| 121 |
|
| 122 |
- name: Query all sources (normal mode) |
| 123 |
cisco.aci.aci_firmware_source: *source_query |
| 124 |
register: nm_query_all_sources |
| 125 |
|
| 126 |
- name: Verify query_all_sources |
| 127 |
ansible.builtin.assert: |
| 128 |
that: |
| 129 |
- cm_query_all_sources is not changed |
| 130 |
- nm_query_all_sources is not changed |
| 131 |
- cm_query_all_sources == nm_query_all_sources |
| 132 |
- nm_query_all_sources.current.0.firmwareRepoP.children | length >= 2 |
| 133 |
|
| 134 |
# QUERY A SOURCE |
| 135 |
- name: Query our source (check_mode) |
| 136 |
cisco.aci.aci_firmware_source: |
| 137 |
<<: *source_query |
| 138 |
source: ansible_test_1 |
| 139 |
check_mode: true |
| 140 |
register: cm_query_source |
| 141 |
|
| 142 |
- name: Query our source (normal mode) |
| 143 |
cisco.aci.aci_firmware_source: |
| 144 |
<<: *source_query |
| 145 |
source: ansible_test_1 |
| 146 |
register: nm_query_source |
| 147 |
|
| 148 |
- name: Verify query_source |
| 149 |
ansible.builtin.assert: |
| 150 |
that: |
| 151 |
- cm_query_source is not changed |
| 152 |
- nm_query_source is not changed |
| 153 |
- cm_query_source == nm_query_source |
| 154 |
- nm_query_source.current.0.firmwareOSource.attributes.dn == 'uni/fabric/fwrepop/osrc-ansible_test_1' |
| 155 |
- nm_query_source.current.0.firmwareOSource.attributes.name == 'ansible_test_1' |
| 156 |
|
| 157 |
# REMOVE SOURCE |
| 158 |
- name: Remove source (check_mode) |
| 159 |
cisco.aci.aci_firmware_source: &source_remove |
| 160 |
<<: *source_query |
| 161 |
source: ansible_test_1 |
| 162 |
state: absent |
| 163 |
check_mode: true |
| 164 |
register: cm_remove_source |
| 165 |
|
| 166 |
- name: Remove source (normal mode) |
| 167 |
cisco.aci.aci_firmware_source: *source_remove |
| 168 |
register: nm_remove_source |
| 169 |
|
| 170 |
- name: Verify remove_source |
| 171 |
ansible.builtin.assert: |
| 172 |
that: |
| 173 |
- cm_remove_source is changed |
| 174 |
- nm_remove_source is changed |
| 175 |
- cm_remove_source.current.0.firmwareOSource.attributes.dn == cm_remove_source.previous.0.firmwareOSource.attributes.dn == nm_remove_source.previous.0.firmwareOSource.attributes.dn == 'uni/fabric/fwrepop/osrc-ansible_test_1' |
| 176 |
- nm_remove_source.current == [] |
| 177 |
|
| 178 |
- name: Remove source again (check_mode) |
| 179 |
cisco.aci.aci_firmware_source: *source_remove |
| 180 |
check_mode: true |
| 181 |
register: cm_remove_source_again |
| 182 |
|
| 183 |
- name: Remove source again (normal mode) |
| 184 |
cisco.aci.aci_firmware_source: *source_remove |
| 185 |
register: nm_remove_source_again |
| 186 |
|
| 187 |
- name: Verify remove_source_again |
| 188 |
ansible.builtin.assert: |
| 189 |
that: |
| 190 |
- cm_remove_source_again is not changed |
| 191 |
- nm_remove_source_again is not changed |
| 192 |
|
| 193 |
# QUERY NON-EXISTING SOURCE |
| 194 |
- name: Query non-existing source (check_mode) |
| 195 |
cisco.aci.aci_firmware_source: |
| 196 |
<<: *source_query |
| 197 |
source: non_existing_source |
| 198 |
check_mode: true |
| 199 |
register: cm_query_non_source |
| 200 |
|
| 201 |
- name: Query non-existing source (normal mode) |
| 202 |
cisco.aci.aci_firmware_source: |
| 203 |
<<: *source_query |
| 204 |
source: non_existing_source |
| 205 |
register: nm_query_non_source |
| 206 |
|
| 207 |
- name: Verify query_non_source |
| 208 |
ansible.builtin.assert: |
| 209 |
that: |
| 210 |
- cm_query_non_source is not changed |
| 211 |
- nm_query_non_source is not changed |
| 212 |
- cm_query_non_source == nm_query_non_source |
| 213 |
- nm_query_non_source.current == [] |
| 214 |
|
| 215 |
# PROVOKE ERRORS |
| 216 |
- name: Error when required parameter is missing |
| 217 |
cisco.aci.aci_firmware_source: |
| 218 |
host: '{{ aci_hostname }}' |
| 219 |
username: '{{ aci_username }}' |
| 220 |
password: '{{ aci_password }}' |
| 221 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 222 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 223 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 224 |
output_level: '{{ aci_output_level | default("info") }}' |
| 225 |
state: present |
| 226 |
ignore_errors: true |
| 227 |
register: error_on_missing_required_param |
| 228 |
|
| 229 |
- name: Verify error_on_missing_required_param |
| 230 |
ansible.builtin.assert: |
| 231 |
that: |
| 232 |
- error_on_missing_required_param is failed |
| 233 |
- 'error_on_missing_required_param.msg == "state is present but all of the following are missing: source, url"' |