| 1 |
# Test code for the ACI modules |
| 2 |
# Copyright: (c) 2020, Cindy Zhao (@cizhao) <[email protected]> |
| 3 |
# Copyright: (c) 2024, Samita Bhattacharjee (@samitab) <[email protected]> |
| 4 |
|
| 5 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
- name: Test that we have an ACI APIC host, ACI username and ACI password |
| 8 |
ansible.builtin.fail: |
| 9 |
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.' |
| 10 |
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined |
| 11 |
|
| 12 |
# SET VARS |
| 13 |
- name: Set vars |
| 14 |
ansible.builtin.set_fact: |
| 15 |
aci_info: &aci_info |
| 16 |
host: "{{ aci_hostname }}" |
| 17 |
username: "{{ aci_username }}" |
| 18 |
password: "{{ aci_password }}" |
| 19 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 20 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 21 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 22 |
output_level: '{{ aci_output_level | default("info") }}' |
| 23 |
|
| 24 |
- name: Verify Cloud and Non-Cloud Sites in use. |
| 25 |
ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml |
| 26 |
|
| 27 |
- name: Execute tasks only for cloud sites |
| 28 |
when: query_cloud.current | length > 0 # This condition will execute only cloud sites |
| 29 |
block: # block specifies execution of tasks within, based on conditions |
| 30 |
- name: Ensure tenant doesn't exist |
| 31 |
cisco.aci.aci_tenant: |
| 32 |
<<: *aci_info |
| 33 |
state: absent |
| 34 |
tenant: ansible_test |
| 35 |
register: tenant_absent |
| 36 |
|
| 37 |
# CLEAN ENVIRONMENT |
| 38 |
|
| 39 |
- name: Remove aci cloud context profile |
| 40 |
cisco.aci.aci_cloud_ctx_profile: |
| 41 |
<<: *aci_info |
| 42 |
tenant: ansible_test |
| 43 |
name: ctx_profile_1 |
| 44 |
state: absent |
| 45 |
|
| 46 |
- name: Remove ansible_test |
| 47 |
cisco.aci.aci_tenant: &aci_tenant_absent |
| 48 |
<<: *aci_info |
| 49 |
tenant: ansible_test |
| 50 |
state: absent |
| 51 |
|
| 52 |
- name: Create ansible_test |
| 53 |
cisco.aci.aci_tenant: &aci_tenant |
| 54 |
<<: *aci_tenant_absent |
| 55 |
state: present |
| 56 |
|
| 57 |
- name: Create aci cloud context profile |
| 58 |
cisco.aci.aci_cloud_ctx_profile: |
| 59 |
<<: *aci_tenant |
| 60 |
cloud: "{{ cloud_type }}" |
| 61 |
name: ctx_profile_1 |
| 62 |
vrf: ctx_profile_vrf_1 |
| 63 |
region: "{{ region_2 }}" |
| 64 |
primary_cidr: '10.50.0.0/16' |
| 65 |
state: present |
| 66 |
|
| 67 |
# CREATION TASKS |
| 68 |
|
| 69 |
- name: Create aci cloud subnet (check_mode) |
| 70 |
cisco.aci.aci_cloud_subnet: &aci_cloud_subnet |
| 71 |
<<: *aci_tenant |
| 72 |
cloud_context_profile: ctx_profile_1 |
| 73 |
cidr: '10.50.0.0/16' |
| 74 |
availability_zone: "{{ availability_zone | default(omit) }}" |
| 75 |
azure_region: "{{ az_region | default(omit) }}" |
| 76 |
vnet_gateway: "{{ vnet_gateway | default(omit) }}" |
| 77 |
address: 10.50.0.1 |
| 78 |
description: test description |
| 79 |
check_mode: true |
| 80 |
register: cm_add_subnet |
| 81 |
|
| 82 |
- name: Create aci cloud subnet (normal_mode) |
| 83 |
cisco.aci.aci_cloud_subnet: |
| 84 |
<<: *aci_cloud_subnet |
| 85 |
register: nm_add_subnet |
| 86 |
|
| 87 |
- name: Create aci cloud subnet again (normal_mode) |
| 88 |
cisco.aci.aci_cloud_subnet: |
| 89 |
<<: *aci_cloud_subnet |
| 90 |
register: nm_add_subnet_again |
| 91 |
|
| 92 |
- name: Create aci cloud subnet with invalid zone/region |
| 93 |
cisco.aci.aci_cloud_subnet: |
| 94 |
<<: *aci_cloud_subnet |
| 95 |
availability_zone: us-west-1a |
| 96 |
azure_region: westus2 |
| 97 |
ignore_errors: true |
| 98 |
register: nm_invalid_subnet_zone |
| 99 |
|
| 100 |
- name: Verify create tasks |
| 101 |
ansible.builtin.assert: |
| 102 |
that: |
| 103 |
- cm_add_subnet is changed |
| 104 |
- cm_add_subnet.current == [] |
| 105 |
- cm_add_subnet.previous == [] |
| 106 |
- cm_add_subnet.proposed.cloudSubnet.attributes.ip == "10.50.0.1" |
| 107 |
- cm_add_subnet.proposed.cloudSubnet.attributes.descr == "test description" |
| 108 |
- cm_add_subnet.proposed.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 109 |
- cm_add_subnet.proposed.cloudSubnet.attributes.annotation == "orchestrator:ansible" |
| 110 |
- cm_add_subnet.proposed.cloudSubnet.attributes.scope == "private" |
| 111 |
- nm_add_subnet is changed |
| 112 |
- nm_add_subnet.current.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 113 |
- nm_add_subnet.current.0.cloudSubnet.attributes.descr == "test description" |
| 114 |
- nm_add_subnet.current.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 115 |
- nm_add_subnet.current.0.cloudSubnet.attributes.annotation == "orchestrator:ansible" |
| 116 |
- nm_add_subnet.current.0.cloudSubnet.attributes.scope == "private" |
| 117 |
- nm_add_subnet.previous == [] |
| 118 |
- nm_add_subnet_again is not changed |
| 119 |
- nm_add_subnet_again.current.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 120 |
- nm_add_subnet_again.current.0.cloudSubnet.attributes.descr == "test description" |
| 121 |
- nm_add_subnet_again.current.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 122 |
- nm_add_subnet_again.current.0.cloudSubnet.attributes.annotation == "orchestrator:ansible" |
| 123 |
- nm_add_subnet_again.current.0.cloudSubnet.attributes.scope == "private" |
| 124 |
- nm_add_subnet_again.previous.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 125 |
- nm_add_subnet_again.previous.0.cloudSubnet.attributes.descr == "test description" |
| 126 |
- nm_add_subnet_again.previous.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 127 |
- nm_add_subnet_again.previous.0.cloudSubnet.attributes.annotation == "orchestrator:ansible" |
| 128 |
- nm_add_subnet_again.previous.0.cloudSubnet.attributes.scope == "private" |
| 129 |
- nm_invalid_subnet_zone.msg == "parameters are mutually exclusive{{":"}} aws_availability_zone|azure_region" |
| 130 |
|
| 131 |
- name: Verify create tasks for Azure |
| 132 |
ansible.builtin.assert: |
| 133 |
that: |
| 134 |
- cm_add_subnet.proposed.cloudSubnet.attributes.usage == "gateway" |
| 135 |
- cm_add_subnet.proposed.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-azure/region-westus2/zone-default" |
| 136 |
- nm_add_subnet.current.0.cloudSubnet.attributes.usage == "gateway" |
| 137 |
- nm_add_subnet.current.0.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-azure/region-westus2/zone-default" |
| 138 |
- nm_add_subnet_again.current.0.cloudSubnet.attributes.usage == "gateway" |
| 139 |
- nm_add_subnet_again.current.0.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-azure/region-westus2/zone-default" |
| 140 |
- nm_add_subnet_again.previous.0.cloudSubnet.attributes.usage == "gateway" |
| 141 |
- nm_add_subnet_again.previous.0.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-azure/region-westus2/zone-default" |
| 142 |
when: az_region is defined and vnet_gateway is defined |
| 143 |
|
| 144 |
- name: Verify create tasks for AWS |
| 145 |
ansible.builtin.assert: |
| 146 |
that: |
| 147 |
- cm_add_subnet.proposed.cloudSubnet.attributes.usage == "user" |
| 148 |
- cm_add_subnet.proposed.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-aws/region-us-west-1/zone-a" |
| 149 |
- nm_add_subnet.current.0.cloudSubnet.attributes.usage == "user" |
| 150 |
- nm_add_subnet.current.0.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-aws/region-us-west-1/zone-a" |
| 151 |
- nm_add_subnet_again.current.0.cloudSubnet.attributes.usage == "user" |
| 152 |
- nm_add_subnet_again.current.0.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-aws/region-us-west-1/zone-a" |
| 153 |
- nm_add_subnet_again.previous.0.cloudSubnet.attributes.usage == "user" |
| 154 |
- nm_add_subnet_again.previous.0.cloudSubnet.children.0.cloudRsZoneAttach.attributes.tDn == "uni/clouddomp/provp-aws/region-us-west-1/zone-a" |
| 155 |
when: availability_zone is defined |
| 156 |
|
| 157 |
# UPDATE TASKS |
| 158 |
|
| 159 |
- name: Update aci cloud subnet |
| 160 |
cisco.aci.aci_cloud_subnet: |
| 161 |
<<: *aci_cloud_subnet |
| 162 |
description: test description 2 |
| 163 |
register: nm_update_subnet |
| 164 |
|
| 165 |
- name: Verify aci cloud subnet update |
| 166 |
ansible.builtin.assert: |
| 167 |
that: |
| 168 |
- nm_update_subnet is changed |
| 169 |
- nm_update_subnet.current.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 170 |
- nm_update_subnet.current.0.cloudSubnet.attributes.descr == "test description 2" |
| 171 |
- nm_update_subnet.current.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 172 |
- nm_update_subnet.current.0.cloudSubnet.attributes.annotation == "orchestrator:ansible" |
| 173 |
- nm_update_subnet.current.0.cloudSubnet.attributes.scope == "private" |
| 174 |
- nm_update_subnet.previous.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 175 |
- nm_update_subnet.previous.0.cloudSubnet.attributes.descr == "test description" |
| 176 |
- nm_update_subnet.previous.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 177 |
- nm_update_subnet.previous.0.cloudSubnet.attributes.annotation == "orchestrator:ansible" |
| 178 |
- nm_update_subnet.previous.0.cloudSubnet.attributes.scope == "private" |
| 179 |
|
| 180 |
# QUERY TASKS |
| 181 |
|
| 182 |
- name: Create extra subnets for query |
| 183 |
cisco.aci.aci_cloud_subnet: |
| 184 |
<<: *aci_cloud_subnet |
| 185 |
cidr: 10.50.0.0/16 |
| 186 |
vnet_gateway: false |
| 187 |
address: "{{ item }}" |
| 188 |
loop: |
| 189 |
- 10.50.0.2 |
| 190 |
- 10.50.0.3 |
| 191 |
|
| 192 |
- name: Query all subnets |
| 193 |
cisco.aci.aci_cloud_subnet: |
| 194 |
<<: *aci_tenant |
| 195 |
cloud_context_profile: ctx_profile_1 |
| 196 |
cidr: '10.50.0.0/16' |
| 197 |
state: query |
| 198 |
register: query_all |
| 199 |
|
| 200 |
- name: Verify query_all |
| 201 |
ansible.builtin.assert: |
| 202 |
that: |
| 203 |
- query_all is not changed |
| 204 |
- query_all.current.0.cloudCidr.attributes.addr == "10.50.0.0/16" |
| 205 |
- query_all.current.0.cloudCidr.children | length == 3 |
| 206 |
- query_all.current.0.cloudCidr.children.0.cloudSubnet.attributes.ip == "10.50.0.3" |
| 207 |
- query_all.current.0.cloudCidr.children.1.cloudSubnet.attributes.ip == "10.50.0.2" |
| 208 |
- query_all.current.0.cloudCidr.children.2.cloudSubnet.attributes.ip == "10.50.0.1" |
| 209 |
|
| 210 |
- name: Query a specific subnet |
| 211 |
cisco.aci.aci_cloud_subnet: |
| 212 |
<<: *aci_info |
| 213 |
tenant: ansible_test |
| 214 |
cloud_context_profile: ctx_profile_1 |
| 215 |
cidr: '10.50.0.0/16' |
| 216 |
address: 10.50.0.1 |
| 217 |
state: query |
| 218 |
register: query_subnet_1 |
| 219 |
|
| 220 |
- name: Verify query_subnet_1 |
| 221 |
ansible.builtin.assert: |
| 222 |
that: |
| 223 |
- query_subnet_1 is not changed |
| 224 |
- query_subnet_1.current.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 225 |
- query_subnet_1.current.0.cloudSubnet.attributes.scope == "private" |
| 226 |
- query_subnet_1.current.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 227 |
|
| 228 |
# DELETE TASKS |
| 229 |
|
| 230 |
- name: Remove cloud subnet (check_mode) |
| 231 |
cisco.aci.aci_cloud_subnet: |
| 232 |
<<: *aci_cloud_subnet |
| 233 |
state: absent |
| 234 |
check_mode: true |
| 235 |
register: cm_remove_subnet |
| 236 |
|
| 237 |
- name: Remove cloud subnet (normal_mode) |
| 238 |
cisco.aci.aci_cloud_subnet: |
| 239 |
<<: *aci_cloud_subnet |
| 240 |
state: absent |
| 241 |
register: nm_remove_subnet |
| 242 |
|
| 243 |
- name: Remove cloud subnet again (normal_mode) |
| 244 |
cisco.aci.aci_cloud_subnet: |
| 245 |
<<: *aci_cloud_subnet |
| 246 |
state: absent |
| 247 |
register: nm_remove_subnet_again |
| 248 |
|
| 249 |
- name: Verify remove cloud subnet |
| 250 |
ansible.builtin.assert: |
| 251 |
that: |
| 252 |
- cm_remove_subnet is changed |
| 253 |
- cm_remove_subnet.proposed == {} |
| 254 |
- cm_remove_subnet.previous.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 255 |
- cm_remove_subnet.previous.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 256 |
- nm_remove_subnet is changed |
| 257 |
- nm_remove_subnet.current == [] |
| 258 |
- nm_remove_subnet.previous.0.cloudSubnet.attributes.ip == "10.50.0.1" |
| 259 |
- nm_remove_subnet.previous.0.cloudSubnet.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.50.0.0/16]/subnet-[10.50.0.1]" |
| 260 |
- nm_remove_subnet_again is not changed |
| 261 |
- nm_remove_subnet_again.previous == [] |
| 262 |
- nm_remove_subnet_again.current == [] |
| 263 |
|
| 264 |
# CLEAN ENVIRONMENT |
| 265 |
- name: Remove ansible_test |
| 266 |
cisco.aci.aci_tenant: |
| 267 |
<<: *aci_tenant_absent |