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 7# CLEAN ENVIRONMENT 8- name: Remove domain to VLAN pool binding 9 aci_domain_to_vlan_pool: &binding_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 domain: phys_dom 18 domain_type: phys 19 pool: test_pool 20 pool_allocation_mode: dynamic 21 state: absent 22 23- name: Remove physical domain 24 aci_domain: 25 host: "{{ aci_hostname }}" 26 username: "{{ aci_username }}" 27 password: "{{ aci_password }}" 28 validate_certs: '{{ aci_validate_certs | default(false) }}' 29 use_ssl: '{{ aci_use_ssl | default(true) }}' 30 use_proxy: '{{ aci_use_proxy | default(true) }}' 31 output_level: '{{ aci_output_level | default("info") }}' 32 domain: phys_dom 33 domain_type: phys 34 state: absent 35 36- name: Create VLAN pool 37 aci_vlan_pool: 38 host: "{{ aci_hostname }}" 39 username: "{{ aci_username }}" 40 password: "{{ aci_password }}" 41 validate_certs: '{{ aci_validate_certs | default(false) }}' 42 use_ssl: '{{ aci_use_ssl | default(true) }}' 43 use_proxy: '{{ aci_use_proxy | default(true) }}' 44 output_level: '{{ aci_output_level | default("info") }}' 45 pool: test_pool 46 pool_allocation_mode: dynamic 47 description: Test VLAN pool 48 state: present 49 50 51# ADD BINDING 52- name: Add domain to VLAN pool binding (check_mode) 53 aci_domain_to_vlan_pool: &binding_present 54 host: '{{ aci_hostname }}' 55 username: '{{ aci_username }}' 56 password: '{{ aci_password }}' 57 validate_certs: '{{ aci_validate_certs | default(false) }}' 58 use_ssl: '{{ aci_use_ssl | default(true) }}' 59 use_proxy: '{{ aci_use_proxy | default(true) }}' 60 output_level: '{{ aci_output_level | default("info") }}' 61 domain: phys_dom 62 domain_type: phys 63 pool: test_pool 64 pool_allocation_mode: dynamic 65 state: present 66 check_mode: yes 67 register: cm_add_binding 68 69- name: Add domain to VLAN pool binding (normal mode) 70 aci_domain_to_vlan_pool: *binding_present 71 register: nm_add_binding 72 73- name: Verify add_binding 74 assert: 75 that: 76 - cm_add_binding is changed 77 - nm_add_binding is changed 78 - 'cm_add_binding.sent == nm_add_binding.sent == {"physDomP": {"attributes": {"name": "phys_dom"}, "children": [{"infraRsVlanNs": {"attributes": {"tDn": "uni/infra/vlanns-[test_pool]-dynamic"}}}]}}' 79 - 'cm_add_binding.proposed == nm_add_binding.proposed == {"physDomP": {"attributes": {"name": "phys_dom"}, "children": [{"infraRsVlanNs": {"attributes": {"tDn": "uni/infra/vlanns-[test_pool]-dynamic"}}}]}}' 80 - cm_add_binding.current == cm_add_binding.previous == nm_add_binding.previous == [] 81 - 'nm_add_binding.current == [{"physDomP": {"attributes": {"dn": "uni/phys-phys_dom", "name": "phys_dom", "nameAlias": "", "ownerKey": "", "ownerTag": ""}, "children": [{"infraRsVlanNs": {"attributes": {"tDn": "uni/infra/vlanns-[test_pool]-dynamic"}}}]}}]' 82 83- name: Add domain to VLAN pool binding again (check_mode) 84 aci_domain_to_vlan_pool: *binding_present 85 check_mode: yes 86 register: cm_add_binding_again 87 88- name: Add domain to VLAN pool binding again (normal mode) 89 aci_domain_to_vlan_pool: *binding_present 90 register: nm_add_binding_again 91 92- name: Verify add_binding_again 93 assert: 94 that: 95 - cm_add_binding_again is not changed 96 - nm_add_binding_again is not changed 97 98 99# QUERY ALL BINDINGS 100- name: Query all domain to VLAN pool bindings (check_mode) 101 aci_domain_to_vlan_pool: &binding_query 102 host: '{{ aci_hostname }}' 103 username: '{{ aci_username }}' 104 password: '{{ aci_password }}' 105 validate_certs: '{{ aci_validate_certs | default(false) }}' 106 use_ssl: '{{ aci_use_ssl | default(true) }}' 107 use_proxy: '{{ aci_use_proxy | default(true) }}' 108 output_level: '{{ aci_output_level | default("info") }}' 109 domain_type: phys 110 pool_allocation_mode: dynamic 111 state: query 112 check_mode: yes 113 register: cm_query_all_bindings 114 115- name: Query all domain to VLAN pool bindings (normal mode) 116 aci_domain_to_vlan_pool: *binding_query 117 register: nm_query_all_bindings 118 119- name: Verify query_all_bindings 120 assert: 121 that: 122 - cm_query_all_bindings is not changed 123 - nm_query_all_bindings is not changed 124 - cm_query_all_bindings == nm_query_all_bindings 125 - nm_query_all_bindings.current|length >= 1 126 127 128# QUERY A BINDING 129- name: Query our domain to VLAN pool binding (check_mode) 130 aci_domain_to_vlan_pool: 131 <<: *binding_query 132 domain: phys_dom 133 pool: test_pool 134 pool_allocation_mode: dynamic 135 check_mode: yes 136 register: cm_query_binding 137 138- name: Query our domain to VLAN pool binding (normal mode) 139 aci_domain_to_vlan_pool: 140 <<: *binding_query 141 domain: phys_dom 142 pool: test_pool 143 pool_allocation_mode: dynamic 144 register: nm_query_binding 145 146- name: Verify query_binding 147 assert: 148 that: 149 - cm_query_binding is not changed 150 - nm_query_binding is not changed 151 - cm_query_binding == nm_query_binding 152 - nm_query_binding.current.0.physDomP.attributes.dn == 'uni/phys-phys_dom' 153 - nm_query_binding.current.0.physDomP.attributes.name == 'phys_dom' 154 - nm_query_binding.current.0.physDomP.children.0.infraRsVlanNs.attributes.tCl == 'fvnsVlanInstP' 155 - nm_query_binding.current.0.physDomP.children.0.infraRsVlanNs.attributes.tDn == 'uni/infra/vlanns-[test_pool]-dynamic' 156 157 158# REMOVE BINDING 159- name: Remove domain to VLAN pool binding (check_mode) 160 aci_domain_to_vlan_pool: *binding_absent 161 check_mode: yes 162 register: cm_remove_binding 163 164- name: Remove domain to VLAN pool binding (normal mode) 165 aci_domain_to_vlan_pool: *binding_absent 166 register: nm_remove_binding 167 168- name: Verify remove_binding 169 assert: 170 that: 171 - cm_remove_binding is changed 172 - nm_remove_binding is changed 173 - 'cm_remove_binding.current == cm_remove_binding.previous == nm_remove_binding.previous == [{"physDomP": {"attributes": {"dn": "uni/phys-phys_dom", "name": "phys_dom", "nameAlias": "", "ownerKey": "", "ownerTag": ""}, "children": [{"infraRsVlanNs": {"attributes": {"tDn": "uni/infra/vlanns-[test_pool]-dynamic"}}}]}}]' 174 - nm_remove_binding.current == [] 175 176- name: Remove domain to VLAN pool binding again (check_mode) 177 aci_domain_to_vlan_pool: *binding_absent 178 check_mode: yes 179 register: cm_remove_binding_again 180 181- name: Remove domain to VLAN pool binding again (normal mode) 182 aci_domain_to_vlan_pool: *binding_absent 183 register: nm_remove_binding_again 184 185- name: Verify remove_binding_again 186 assert: 187 that: 188 - cm_remove_binding_again is not changed 189 - nm_remove_binding_again is not changed 190 191 192# QUERY NON-EXISTING BINDING 193- name: Query non-existing domain to VLAN pool binding (check_mode) 194 aci_domain_to_vlan_pool: 195 <<: *binding_query 196 domain: phys_dom 197 pool: test_pool 198 pool_allocation_mode: dynamic 199 check_mode: yes 200 register: cm_query_non_binding 201 202- name: Query non-existing domain to VLAN pool binding (normal mode) 203 aci_domain_to_vlan_pool: 204 <<: *binding_query 205 domain: phys_dom 206 pool: test_pool 207 pool_allocation_mode: dynamic 208 register: nm_query_non_binding 209 210- name: Verify query_non_binding 211 assert: 212 that: 213 - cm_query_non_binding is not changed 214 - nm_query_non_binding is not changed 215 - cm_query_non_binding == nm_query_non_binding 216 - nm_query_non_binding.current == [] 217