| 1 |
# Test code for the ACI modules |
| 2 |
# Copyright: (c) 2018, Dag Wieers (dagwieers) <[email protected]> |
| 3 |
|
| 4 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
# CLEAN ENVIRONMENT |
| 7 |
- name: Remove static vlan pool |
| 8 |
cisco.aci.aci_vlan_pool: &static_vlan_pool_absent |
| 9 |
host: '{{ aci_hostname }}' |
| 10 |
username: '{{ aci_username }}' |
| 11 |
password: '{{ aci_password }}' |
| 12 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 13 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 14 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 15 |
output_level: '{{ aci_output_level | default("info") }}' |
| 16 |
pool: anstest |
| 17 |
pool_allocation_mode: static |
| 18 |
state: absent |
| 19 |
|
| 20 |
# ADD VLAN POOL |
| 21 |
- name: Add static vlan pool (check_mode) |
| 22 |
cisco.aci.aci_vlan_pool: &static_vlan_pool_present |
| 23 |
host: '{{ aci_hostname }}' |
| 24 |
username: '{{ aci_username }}' |
| 25 |
password: '{{ aci_password }}' |
| 26 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 27 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 28 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 29 |
output_level: '{{ aci_output_level | default("info") }}' |
| 30 |
pool: anstest |
| 31 |
pool_allocation_mode: static |
| 32 |
state: present |
| 33 |
check_mode: true |
| 34 |
register: cm_add_static_vlan_pool |
| 35 |
|
| 36 |
- name: Add static vlan pool (normal mode) |
| 37 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_present |
| 38 |
register: nm_add_static_vlan_pool |
| 39 |
|
| 40 |
- name: Verify add_static_vlan_pool |
| 41 |
ansible.builtin.assert: |
| 42 |
that: |
| 43 |
- cm_add_static_vlan_pool is changed |
| 44 |
- nm_add_static_vlan_pool is changed |
| 45 |
- cm_add_static_vlan_pool.sent.fvnsVlanInstP.attributes.allocMode == nm_add_static_vlan_pool.sent.fvnsVlanInstP.attributes.allocMode == 'static' |
| 46 |
- cm_add_static_vlan_pool.sent.fvnsVlanInstP.attributes.name == nm_add_static_vlan_pool.sent.fvnsVlanInstP.attributes.name == 'anstest' |
| 47 |
- cm_add_static_vlan_pool.proposed.fvnsVlanInstP.attributes.allocMode == nm_add_static_vlan_pool.proposed.fvnsVlanInstP.attributes.allocMode == 'static' |
| 48 |
- cm_add_static_vlan_pool.proposed.fvnsVlanInstP.attributes.name == nm_add_static_vlan_pool.proposed.fvnsVlanInstP.attributes.name == 'anstest' |
| 49 |
- cm_add_static_vlan_pool.previous == nm_add_static_vlan_pool.previous == [] |
| 50 |
# NOTE: We cannot fix this easily |
| 51 |
- cm_add_static_vlan_pool.current == [] |
| 52 |
- nm_add_static_vlan_pool.current.0.fvnsVlanInstP.attributes.allocMode == 'static' |
| 53 |
- nm_add_static_vlan_pool.current.0.fvnsVlanInstP.attributes.descr == '' |
| 54 |
- nm_add_static_vlan_pool.current.0.fvnsVlanInstP.attributes.dn == 'uni/infra/vlanns-[anstest]-static' |
| 55 |
- nm_add_static_vlan_pool.current.0.fvnsVlanInstP.attributes.name == 'anstest' |
| 56 |
- nm_add_static_vlan_pool.current.0.fvnsVlanInstP.attributes.annotation == 'orchestrator:ansible' |
| 57 |
|
| 58 |
- name: Add static_vlan_pool again (check_mode) |
| 59 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_present |
| 60 |
check_mode: true |
| 61 |
register: cm_add_static_vlan_pool_again |
| 62 |
|
| 63 |
- name: Add static vlan pool again (normal mode) |
| 64 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_present |
| 65 |
register: nm_add_static_vlan_pool_again |
| 66 |
|
| 67 |
- name: Verify add_static_vlan_pool_again |
| 68 |
ansible.builtin.assert: |
| 69 |
that: |
| 70 |
- cm_add_static_vlan_pool_again is not changed |
| 71 |
- nm_add_static_vlan_pool_again is not changed |
| 72 |
- cm_add_static_vlan_pool_again.current == nm_add_static_vlan_pool_again.current == nm_add_static_vlan_pool.current |
| 73 |
|
| 74 |
|
| 75 |
# CHANGE VLAN POOL |
| 76 |
- name: Change description of static vlan pool (check_mode) |
| 77 |
cisco.aci.aci_vlan_pool: |
| 78 |
<<: *static_vlan_pool_present |
| 79 |
description: Ansible test static vlan pool |
| 80 |
check_mode: true |
| 81 |
register: cm_add_static_vlan_pool_descr |
| 82 |
|
| 83 |
- name: Change description of static vlan pool (normal mode) |
| 84 |
cisco.aci.aci_vlan_pool: |
| 85 |
<<: *static_vlan_pool_present |
| 86 |
description: Ansible test static vlan pool |
| 87 |
register: nm_add_static_vlan_pool_descr |
| 88 |
|
| 89 |
- name: Verify add_static_vlan_pool_descr |
| 90 |
ansible.builtin.assert: |
| 91 |
that: |
| 92 |
- cm_add_static_vlan_pool_descr is changed |
| 93 |
- nm_add_static_vlan_pool_descr is changed |
| 94 |
- cm_add_static_vlan_pool_descr.sent.fvnsVlanInstP.attributes.descr == nm_add_static_vlan_pool_descr.sent.fvnsVlanInstP.attributes.descr == 'Ansible test static vlan pool' |
| 95 |
- cm_add_static_vlan_pool_descr.proposed.fvnsVlanInstP.attributes.allocMode == nm_add_static_vlan_pool_descr.proposed.fvnsVlanInstP.attributes.allocMode == 'static' |
| 96 |
- cm_add_static_vlan_pool_descr.proposed.fvnsVlanInstP.attributes.descr == nm_add_static_vlan_pool_descr.proposed.fvnsVlanInstP.attributes.descr == 'Ansible test static vlan pool' |
| 97 |
- cm_add_static_vlan_pool_descr.proposed.fvnsVlanInstP.attributes.name == nm_add_static_vlan_pool_descr.proposed.fvnsVlanInstP.attributes.name == 'anstest' |
| 98 |
- cm_add_static_vlan_pool_descr.previous == nm_add_static_vlan_pool_descr.previous == cm_add_static_vlan_pool_descr.current == nm_add_static_vlan_pool.current |
| 99 |
- nm_add_static_vlan_pool_descr.current.0.fvnsVlanInstP.attributes.allocMode == 'static' |
| 100 |
- nm_add_static_vlan_pool_descr.current.0.fvnsVlanInstP.attributes.descr == 'Ansible test static vlan pool' |
| 101 |
- nm_add_static_vlan_pool_descr.current.0.fvnsVlanInstP.attributes.dn == 'uni/infra/vlanns-[anstest]-static' |
| 102 |
- nm_add_static_vlan_pool_descr.current.0.fvnsVlanInstP.attributes.name == 'anstest' |
| 103 |
|
| 104 |
- name: Change description of static vlan pool again (check_mode) |
| 105 |
cisco.aci.aci_vlan_pool: |
| 106 |
<<: *static_vlan_pool_present |
| 107 |
description: Ansible test static vlan pool |
| 108 |
check_mode: true |
| 109 |
register: cm_add_static_vlan_pool_descr_again |
| 110 |
|
| 111 |
- name: Change description of static vlan pool again (normal mode) |
| 112 |
cisco.aci.aci_vlan_pool: |
| 113 |
<<: *static_vlan_pool_present |
| 114 |
description: Ansible test static vlan pool |
| 115 |
register: nm_add_static_vlan_pool_descr_again |
| 116 |
|
| 117 |
- name: Verify add_static_vlan_pool_descr_again |
| 118 |
ansible.builtin.assert: |
| 119 |
that: |
| 120 |
- cm_add_static_vlan_pool_descr_again is not changed |
| 121 |
- nm_add_static_vlan_pool_descr_again is not changed |
| 122 |
- cm_add_static_vlan_pool_descr_again.current == nm_add_static_vlan_pool_descr_again.current == nm_add_static_vlan_pool_descr.current |
| 123 |
|
| 124 |
|
| 125 |
# ADD VLAN POOL AGAIN |
| 126 |
- name: Add static vlan pool again with no description (check_mode) |
| 127 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_present |
| 128 |
check_mode: true |
| 129 |
register: cm_add_static_vlan_pool_again_no_descr |
| 130 |
|
| 131 |
- name: Add static vlan pool again with no description (normal mode) |
| 132 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_present |
| 133 |
register: nm_add_static_vlan_pool_again_no_descr |
| 134 |
|
| 135 |
- name: Verify add_static_vlan_pool_again_no_descr |
| 136 |
ansible.builtin.assert: |
| 137 |
that: |
| 138 |
- cm_add_static_vlan_pool_again_no_descr is not changed |
| 139 |
- nm_add_static_vlan_pool_again_no_descr is not changed |
| 140 |
- cm_add_static_vlan_pool_again_no_descr.current == nm_add_static_vlan_pool_again_no_descr.current == nm_add_static_vlan_pool_descr.current |
| 141 |
|
| 142 |
|
| 143 |
# QUERY ALL VLAN POOLS |
| 144 |
- name: Query all static vlan pools (check_mode) |
| 145 |
cisco.aci.aci_vlan_pool: &static_vlan_pool_query |
| 146 |
host: '{{ aci_hostname }}' |
| 147 |
username: '{{ aci_username }}' |
| 148 |
password: '{{ aci_password }}' |
| 149 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 150 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 151 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 152 |
output_level: '{{ aci_output_level | default("info") }}' |
| 153 |
state: query |
| 154 |
check_mode: true |
| 155 |
register: cm_query_all_static_vlan_pools |
| 156 |
|
| 157 |
- name: Query all static vlan pools (normal mode) |
| 158 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_query |
| 159 |
register: nm_query_all_static_vlan_pools |
| 160 |
|
| 161 |
- name: Verify query_all_static_vlan_pools |
| 162 |
ansible.builtin.assert: |
| 163 |
that: |
| 164 |
- cm_query_all_static_vlan_pools is not changed |
| 165 |
- nm_query_all_static_vlan_pools is not changed |
| 166 |
- cm_query_all_static_vlan_pools == nm_query_all_static_vlan_pools |
| 167 |
- cm_query_all_static_vlan_pools.current|length >= 1 |
| 168 |
|
| 169 |
|
| 170 |
# QUERY A VLAN POOL |
| 171 |
- name: Query our static vlan pool |
| 172 |
cisco.aci.aci_vlan_pool: |
| 173 |
<<: *static_vlan_pool_query |
| 174 |
pool: anstest |
| 175 |
pool_allocation_mode: static |
| 176 |
check_mode: true |
| 177 |
register: cm_query_static_vlan_pool |
| 178 |
|
| 179 |
- name: Query our static vlan pool |
| 180 |
cisco.aci.aci_vlan_pool: |
| 181 |
<<: *static_vlan_pool_query |
| 182 |
pool: anstest |
| 183 |
pool_allocation_mode: static |
| 184 |
register: nm_query_static_vlan_pool |
| 185 |
|
| 186 |
- name: Verify query_static_vlan_pool |
| 187 |
ansible.builtin.assert: |
| 188 |
that: |
| 189 |
- cm_query_static_vlan_pool is not changed |
| 190 |
- nm_query_static_vlan_pool is not changed |
| 191 |
- cm_query_static_vlan_pool == nm_query_static_vlan_pool |
| 192 |
- nm_query_static_vlan_pool.current.0.fvnsVlanInstP.attributes.allocMode == 'static' |
| 193 |
- nm_query_static_vlan_pool.current.0.fvnsVlanInstP.attributes.descr == 'Ansible test static vlan pool' |
| 194 |
- nm_query_static_vlan_pool.current.0.fvnsVlanInstP.attributes.dn == 'uni/infra/vlanns-[anstest]-static' |
| 195 |
- nm_query_static_vlan_pool.current.0.fvnsVlanInstP.attributes.name == 'anstest' |
| 196 |
|
| 197 |
|
| 198 |
# REMOVE VLAN POOL |
| 199 |
- name: Remove static vlan pool (check_mode) |
| 200 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_absent |
| 201 |
check_mode: true |
| 202 |
register: cm_remove_static_vlan_pool |
| 203 |
|
| 204 |
- name: Remove static vlan pool (normal mode) |
| 205 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_absent |
| 206 |
register: nm_remove_static_vlan_pool |
| 207 |
|
| 208 |
- name: Verify remove_static_vlan_pool |
| 209 |
ansible.builtin.assert: |
| 210 |
that: |
| 211 |
- cm_remove_static_vlan_pool is changed |
| 212 |
- nm_remove_static_vlan_pool is changed |
| 213 |
- cm_remove_static_vlan_pool.current.0.fvnsVlanInstP.attributes.allocMode == cm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.allocMode == nm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.allocMode == 'static' |
| 214 |
- cm_remove_static_vlan_pool.current.0.fvnsVlanInstP.attributes.descr == cm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.descr == nm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.descr == 'Ansible test static vlan pool' |
| 215 |
- cm_remove_static_vlan_pool.current.0.fvnsVlanInstP.attributes.dn == cm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.dn == nm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.dn == 'uni/infra/vlanns-[anstest]-static' |
| 216 |
- cm_remove_static_vlan_pool.current.0.fvnsVlanInstP.attributes.name == cm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.name == nm_remove_static_vlan_pool.previous.0.fvnsVlanInstP.attributes.name == 'anstest' |
| 217 |
- nm_remove_static_vlan_pool.current == [] |
| 218 |
|
| 219 |
- name: Remove static vlan pool again (check_mode) |
| 220 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_absent |
| 221 |
check_mode: true |
| 222 |
register: cm_remove_static_vlan_pool_again |
| 223 |
|
| 224 |
- name: Remove static vlan pool again (normal mode) |
| 225 |
cisco.aci.aci_vlan_pool: *static_vlan_pool_absent |
| 226 |
register: nm_remove_static_vlan_pool_again |
| 227 |
|
| 228 |
- name: Verify remove_static_vlan_pool_again |
| 229 |
ansible.builtin.assert: |
| 230 |
that: |
| 231 |
- cm_remove_static_vlan_pool_again is not changed |
| 232 |
- nm_remove_static_vlan_pool_again is not changed |
| 233 |
- cm_remove_static_vlan_pool_again.proposed == nm_remove_static_vlan_pool_again.proposed == {} |
| 234 |
- cm_remove_static_vlan_pool_again.sent == nm_remove_static_vlan_pool_again.sent == {} |
| 235 |
- cm_remove_static_vlan_pool_again.previous == nm_remove_static_vlan_pool_again.previous == [] |
| 236 |
- cm_remove_static_vlan_pool_again.current == nm_remove_static_vlan_pool_again.current == [] |
| 237 |
|
| 238 |
|
| 239 |
# QUERY NON-EXISTING VLAN POOL |
| 240 |
- name: Query non-existing static vlan pool (check_mode) |
| 241 |
cisco.aci.aci_vlan_pool: |
| 242 |
<<: *static_vlan_pool_query |
| 243 |
pool: anstest |
| 244 |
pool_allocation_mode: static |
| 245 |
check_mode: true |
| 246 |
register: cm_query_non_static_vlan_pool |
| 247 |
|
| 248 |
- name: Query non-existing static vlan pool (normal mode) |
| 249 |
cisco.aci.aci_vlan_pool: |
| 250 |
<<: *static_vlan_pool_query |
| 251 |
pool: anstest |
| 252 |
pool_allocation_mode: static |
| 253 |
register: nm_query_non_static_vlan_pool |
| 254 |
|
| 255 |
# TODO: Implement more tests |
| 256 |
- name: Verify query_non_static_vlan_pool |
| 257 |
ansible.builtin.assert: |
| 258 |
that: |
| 259 |
- cm_query_non_static_vlan_pool is not changed |
| 260 |
- nm_query_non_static_vlan_pool is not changed |
| 261 |
- cm_remove_static_vlan_pool_again.previous == nm_remove_static_vlan_pool_again.previous == [] |
| 262 |
- cm_remove_static_vlan_pool_again.current == nm_remove_static_vlan_pool_again.current == [] |
| 263 |
|
| 264 |
|
| 265 |
# PROVOKE ERRORS |
| 266 |
- name: Error when required parameter is missing |
| 267 |
cisco.aci.aci_vlan_pool: |
| 268 |
host: '{{ aci_hostname }}' |
| 269 |
username: '{{ aci_username }}' |
| 270 |
password: '{{ aci_password }}' |
| 271 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 272 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 273 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 274 |
output_level: '{{ aci_output_level | default("info") }}' |
| 275 |
state: present |
| 276 |
ignore_errors: true |
| 277 |
register: error_on_missing_required_param |
| 278 |
|
| 279 |
- name: Verify error_on_missing_required_param |
| 280 |
ansible.builtin.assert: |
| 281 |
that: |
| 282 |
- error_on_missing_required_param is failed |
| 283 |
- 'error_on_missing_required_param.msg == "state is present but all of the following are missing: pool, pool_allocation_mode"' |
| 284 |
|
| 285 |
- name: Error when together parameter is missing |
| 286 |
cisco.aci.aci_vlan_pool: |
| 287 |
host: '{{ aci_hostname }}' |
| 288 |
username: '{{ aci_username }}' |
| 289 |
password: '{{ aci_password }}' |
| 290 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 291 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 292 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 293 |
output_level: '{{ aci_output_level | default("info") }}' |
| 294 |
pool: anstest |
| 295 |
state: present |
| 296 |
ignore_errors: true |
| 297 |
register: error_on_missing_together_param |
| 298 |
|
| 299 |
- name: Verify error_on_missing_together_param |
| 300 |
ansible.builtin.assert: |
| 301 |
that: |
| 302 |
- error_on_missing_together_param is failed |
| 303 |
- 'error_on_missing_together_param.msg == "state is present but all of the following are missing: pool_allocation_mode"' |