|
| 1 | +# Test code for the ACI modules |
| 2 | +# Copyright: (c) 2023, Gaspard Micol (@gmicol) |
| 3 | + |
| 4 | +# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 | + |
| 6 | +- name: Test that we have an ACI APIC host, ACI username and ACI password |
| 7 | + fail: |
| 8 | + msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.' |
| 9 | + when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined |
| 10 | + |
| 11 | +- name: Set vars |
| 12 | + set_fact: |
| 13 | + aci_info: &aci_info |
| 14 | + host: "{{ aci_hostname }}" |
| 15 | + username: "{{ aci_username }}" |
| 16 | + password: "{{ aci_password }}" |
| 17 | + validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 18 | + use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 19 | + use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 20 | + output_level: debug |
| 21 | + |
| 22 | +# CLEAN ENVIRONMENT |
| 23 | +- name: Remove the ansible_tenant |
| 24 | + aci_tenant: &aci_tenant_absent |
| 25 | + <<: *aci_info |
| 26 | + tenant: ansible_tenant |
| 27 | + state: absent |
| 28 | + |
| 29 | +- name: Verify Cloud and Non-Cloud Sites in use. |
| 30 | + include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml |
| 31 | + |
| 32 | +- name: Execute tasks only for non-cloud sites |
| 33 | + when: query_cloud.current == [] # This condition will execute only non-cloud sites |
| 34 | + block: # block specifies execution of tasks within, based on conditions |
| 35 | + - name: Add a new tenant |
| 36 | + aci_tenant: &aci_tenant_present |
| 37 | + <<: *aci_info |
| 38 | + tenant: ansible_tenant |
| 39 | + description: Ansible tenant |
| 40 | + state: present |
| 41 | + |
| 42 | + - name: Add a new L3Out |
| 43 | + aci_l3out: |
| 44 | + <<: *aci_info |
| 45 | + tenant: ansible_tenant |
| 46 | + l3out: ansible_l3out |
| 47 | + description: L3Out for ansible_tenant tenant |
| 48 | + domain: ansible_dom |
| 49 | + vrf: ansible_vrf |
| 50 | + state: present |
| 51 | + |
| 52 | + - name: Add route control profile for l3out (check_mode) |
| 53 | + aci_route_control_profile: &aci_route_control_profile_present |
| 54 | + <<: *aci_info |
| 55 | + tenant: ansible_tenant |
| 56 | + l3out: ansible_l3out |
| 57 | + route_control_profile: ansible_rtctrl_profile_l3out |
| 58 | + description: Route Control Profile for ansible_l3out L3Out |
| 59 | + auto_continue: no |
| 60 | + policy_type: combinable |
| 61 | + state: present |
| 62 | + check_mode: true |
| 63 | + register: cm_add_route_control_profile |
| 64 | + |
| 65 | + - name: Add route control profile for l3out (normal_mode) |
| 66 | + aci_route_control_profile: |
| 67 | + <<: *aci_route_control_profile_present |
| 68 | + register: nm_add_route_control_profile |
| 69 | + |
| 70 | + - name: Add route control profile for l3out again - testing idempotency |
| 71 | + aci_route_control_profile: |
| 72 | + <<: *aci_route_control_profile_present |
| 73 | + register: nm_add_route_control_profile_idempotency |
| 74 | + |
| 75 | + - name: Add route control profile for tenant (normal_mode) |
| 76 | + aci_route_control_profile: |
| 77 | + <<: *aci_info |
| 78 | + tenant: ansible_tenant |
| 79 | + route_control_profile: ansible_rtctrl_profile_tenant |
| 80 | + description: Route Control Profile for ansible_tenant tenant |
| 81 | + state: present |
| 82 | + register: nm_add_route_control_profile_2 |
| 83 | + |
| 84 | + - name: Asserts for route control profiles creation tasks |
| 85 | + assert: |
| 86 | + that: |
| 87 | + - cm_add_route_control_profile is changed |
| 88 | + - cm_add_route_control_profile.previous == [] |
| 89 | + - cm_add_route_control_profile.current == [] |
| 90 | + - nm_add_route_control_profile is changed |
| 91 | + - nm_add_route_control_profile_idempotency is not changed |
| 92 | + - nm_add_route_control_profile_2 is changed |
| 93 | + - nm_add_route_control_profile_2.previous == [] |
| 94 | + |
| 95 | + - name: Query all route control profiles |
| 96 | + aci_route_control_profile: |
| 97 | + <<: *aci_info |
| 98 | + state: query |
| 99 | + register: query_all_route_control_profile |
| 100 | + |
| 101 | + - name: Query ansible_rtctrl_profile_l3out |
| 102 | + aci_route_control_profile: |
| 103 | + <<: *aci_route_control_profile_present |
| 104 | + state: query |
| 105 | + register: query_ansible_rtctrl_profile_l3out |
| 106 | + |
| 107 | + - name: Asserts query tasks |
| 108 | + assert: |
| 109 | + that: |
| 110 | + - query_all_route_control_profile is not changed |
| 111 | + - query_all_route_control_profile.current|length >= 2 |
| 112 | + |
| 113 | + - name: Remove route control profile for l3out (check_mode) |
| 114 | + aci_route_control_profile: &route_control_profile_absent |
| 115 | + <<: *aci_route_control_profile_present |
| 116 | + state: absent |
| 117 | + check_mode: true |
| 118 | + register: cm_remove_route_control_profile |
| 119 | + |
| 120 | + - name: Remove route control profile for l3out (normal_mode) |
| 121 | + aci_route_control_profile: |
| 122 | + <<: *route_control_profile_absent |
| 123 | + register: nm_remove_route_control_profile |
| 124 | + |
| 125 | + - name: Remove route control profile for l3out - testing idempotency |
| 126 | + aci_route_control_profile: |
| 127 | + <<: *route_control_profile_absent |
| 128 | + register: nm_remove_route_control_profile_idempotency |
| 129 | + |
| 130 | + - name: Asserts deletion tasks |
| 131 | + assert: |
| 132 | + that: |
| 133 | + - cm_remove_route_control_profile is changed |
| 134 | + - cm_remove_route_control_profile.proposed == {} |
| 135 | + - nm_remove_route_control_profile is changed |
| 136 | + - nm_remove_route_control_profile.previous != [] |
| 137 | + - nm_remove_route_control_profile.method == "DELETE" |
| 138 | + - nm_remove_route_control_profile_idempotency is not changed |
| 139 | + - nm_remove_route_control_profile_idempotency.previous == [] |
| 140 | + |
| 141 | + - name: Remove the ansible_tenant - cleanup before ending tests |
| 142 | + aci_tenant: |
| 143 | + <<: *aci_tenant_present |
| 144 | + state: absent |
0 commit comments