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