Debian Codegraph @

ansible_collections/cisco/aci/tests/integration/targets/aci_dhcp_option/tasks/main.yml

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[email protected]>
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 ansible.builtin.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 ansible.builtin.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 BEFORE TESTS
23 - name: Remove the ansible_tenant
24 cisco.aci.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 ansible.builtin.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 cisco.aci.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 DHCP option policy
43 cisco.aci.aci_dhcp_option_policy:
44 <<: *aci_info
45 tenant: ansible_tenant
46 dhcp_option_policy: ansible_dhcp_option_policy_1
47 description: DHCP option policy 1 for ansible_tenant tenant
48 state: present
49
50 # CREATE DHCP OPTION
51 - name: Add a DHCP option (check_mode)
52 cisco.aci.aci_dhcp_option: &aci_dhcp_option_present
53 <<: *aci_info
54 tenant: ansible_tenant
55 dhcp_option_policy: ansible_dhcp_option_policy_1
56 dhcp_option: ansible_dhcp_option_1
57 id: 1
58 data: 82
59 state: present
60 check_mode: true
61 register: cm_add_dhcp_option
62
63 - name: Add a DHCP option (normal_mode)
64 cisco.aci.aci_dhcp_option:
65 <<: *aci_dhcp_option_present
66 register: nm_add_dhcp_option
67
68 - name: Add the first DHCP option again - testing idempotency
69 cisco.aci.aci_dhcp_option:
70 <<: *aci_dhcp_option_present
71 register: nm_add_dhcp_option_idempotency
72
73 - name: Add a second DHCP option (normal_mode)
74 cisco.aci.aci_dhcp_option:
75 <<: *aci_info
76 tenant: ansible_tenant
77 dhcp_option_policy: ansible_dhcp_option_policy_1
78 dhcp_option: ansible_dhcp_option_2
79 id: 2
80 data: 252
81 state: present
82 register: nm_add_dhcp_option_2
83
84 - name: Asserts for DHCP option creation tasks
85 ansible.builtin.assert:
86 that:
87 - cm_add_dhcp_option is changed
88 - cm_add_dhcp_option.previous == []
89 - cm_add_dhcp_option.current == []
90 - nm_add_dhcp_option is changed
91 - nm_add_dhcp_option.current.0.dhcpOption.attributes.name == "ansible_dhcp_option_1"
92 - nm_add_dhcp_option.current.0.dhcpOption.attributes.id == "1"
93 - nm_add_dhcp_option.current.0.dhcpOption.attributes.data == "82"
94 - nm_add_dhcp_option_idempotency is not changed
95 - nm_add_dhcp_option_2 is changed
96 - nm_add_dhcp_option_2.previous == []
97 - nm_add_dhcp_option_2.current.0.dhcpOption.attributes.name == "ansible_dhcp_option_2"
98 - nm_add_dhcp_option_2.current.0.dhcpOption.attributes.id == "2"
99 - nm_add_dhcp_option_2.current.0.dhcpOption.attributes.data == "252"
100
101 # QUERY DHCP OPTION
102 - name: Query all DHCP options
103 cisco.aci.aci_dhcp_option:
104 <<: *aci_info
105 state: query
106 register: query_all_dhcp_option
107
108 - name: Query ansible_dhcp_option_1
109 cisco.aci.aci_dhcp_option:
110 <<: *aci_dhcp_option_present
111 state: query
112 register: query_ansible_dhcp_option_1
113
114 - name: Asserts query tasks
115 ansible.builtin.assert:
116 that:
117 - query_all_dhcp_option is not changed
118 - query_all_dhcp_option.current|length >= 2
119 - query_ansible_dhcp_option_1 is not changed
120 - query_ansible_dhcp_option_1.current.0.dhcpOption.attributes.name == "ansible_dhcp_option_1"
121 - query_ansible_dhcp_option_1.current.0.dhcpOption.attributes.id == "1"
122 - query_ansible_dhcp_option_1.current.0.dhcpOption.attributes.data == "82"
123
124 #UPDATING DHCP OPTION
125 - name: Update first DHCP option (check_mode)
126 cisco.aci.aci_dhcp_option: &aci_dhcp_option_update
127 <<: *aci_dhcp_option_present
128 id: 3
129 data: 255
130 state: present
131 check_mode: true
132 register: cm_update_dhcp_option
133
134 - name: Update first DHCP option (normal_mode)
135 cisco.aci.aci_dhcp_option:
136 <<: *aci_dhcp_option_update
137 register: nm_update_dhcp_option
138
139 - name: Update first DHCP option again - testing idempotency
140 cisco.aci.aci_dhcp_option:
141 <<: *aci_dhcp_option_update
142 register: nm_update_dhcp_option_idempotency
143
144 - name: Asserts for DHCP option update tasks
145 ansible.builtin.assert:
146 that:
147 - cm_update_dhcp_option is changed
148 - cm_update_dhcp_option.previous == cm_update_dhcp_option.current
149 - nm_update_dhcp_option is changed
150 - nm_update_dhcp_option.current.0.dhcpOption.attributes.name == "ansible_dhcp_option_1"
151 - nm_update_dhcp_option.current.0.dhcpOption.attributes.id == "3"
152 - nm_update_dhcp_option.current.0.dhcpOption.attributes.data == "255"
153 - nm_update_dhcp_option_idempotency is not changed
154
155 # DELETE DHCP OPTION
156 - name: Remove DHCP option (check_mode)
157 cisco.aci.aci_dhcp_option: &dhcp_option_absent
158 <<: *aci_dhcp_option_update
159 state: absent
160 check_mode: true
161 register: cm_remove_dhcp_option
162
163 - name: Remove DHCP option (normal_mode)
164 cisco.aci.aci_dhcp_option:
165 <<: *dhcp_option_absent
166 register: nm_remove_dhcp_option
167
168 - name: Remove DHCP option - testing idempotency
169 cisco.aci.aci_dhcp_option:
170 <<: *dhcp_option_absent
171 register: nm_remove_dhcp_option_idempotency
172
173 - name: Asserts deletion tasks
174 ansible.builtin.assert:
175 that:
176 - cm_remove_dhcp_option is changed
177 - cm_remove_dhcp_option.proposed == {}
178 - nm_remove_dhcp_option is changed
179 - nm_remove_dhcp_option.previous != []
180 - nm_remove_dhcp_option.method == "DELETE"
181 - nm_remove_dhcp_option_idempotency is not changed
182 - nm_remove_dhcp_option_idempotency.previous == []
183
184 # CLEAN ENVIRONMENT BEFORE ENDING TESTS
185 - name: Remove the ansible_tenant - cleanup before ending tests
186 cisco.aci.aci_tenant:
187 <<: *aci_tenant_present
188 state: absent