Debian Codegraph @

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

raw
1 # Test code for the ACI modules
2 # Copyright: (c) 2024, 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: '{{ aci_output_level | default("info") }}'
21
22 - name: Verify Cloud and Non-Cloud Sites in use.
23 ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml
24
25 - name: Execute tasks only for non-cloud sites
26 when: query_cloud.current == [] # This condition will execute only non-cloud sites
27 block: # block specifies execution of tasks within, based on conditions
28 # CLEAN ENVIRONMENT
29 - name: Remove the ansible_access_spine_switch_profile
30 cisco.aci.aci_access_spine_switch_profile: &aci_access_spine_switch_profile_absent
31 <<: *aci_info
32 switch_profile: ansible_access_spine_switch_profile
33 state: absent
34
35 - name: Remove the ansible_access_leaf_switch_profile
36 cisco.aci.aci_switch_policy_leaf_profile: &aci_access_leaf_switch_profile_absent
37 <<: *aci_info
38 leaf_profile: ansible_access_leaf_switch_profile
39 state: absent
40
41 # CREATE ACCESS SWITCH POLICY PROFILES
42 - name: Add a new Access Spine Switch profile
43 cisco.aci.aci_access_spine_switch_profile: &aci_access_spine_switch_profile_present
44 <<: *aci_access_spine_switch_profile_absent
45 state: present
46
47 - name: Add a new Access Leaf Switch profile
48 cisco.aci.aci_switch_policy_leaf_profile: &aci_access_leaf_switch_profile_present
49 <<: *aci_access_leaf_switch_profile_absent
50 state: present
51
52 # CREATE ACCESS SWITCH POLICY SELECTORS
53 - name: Add a new Access Spine Switch selector
54 cisco.aci.aci_access_spine_switch_selector:
55 <<: *aci_access_spine_switch_profile_present
56 switch_selector: ansible_access_spine_switch_selector
57 selector_type: range
58 state: present
59
60 - name: Add a new Access Leaf Switch selector
61 cisco.aci.aci_switch_leaf_selector:
62 <<: *aci_access_leaf_switch_profile_present
63 leaf: ansible_access_leaf_switch_selector
64 state: present
65
66 # CREATE NODE BLOCK FOR SWITCH POLICY LEAF SELECTOR
67 - name: Add a new Node Block for Switch policy leaf selector (check_mode)
68 cisco.aci.aci_node_block: &aci_node_block_leaf_present
69 <<: *aci_info
70 switch_profile: ansible_access_leaf_switch_profile
71 port_selector: ansible_access_leaf_switch_selector
72 node_block: ansible_node_block_leaf_1
73 from: 1011
74 to: 1011
75 description: Node Block for Switch policy leaf selector 1
76 type_node: leaf
77 state: present
78 check_mode: true
79 register: cm_add_node_block_leaf
80
81 - name: Add a new Node Block for Switch policy leaf selector (normal_mode)
82 cisco.aci.aci_node_block:
83 <<: *aci_node_block_leaf_present
84 register: nm_add_node_block_leaf
85
86 - name: Add the first Node Block for Switch policy leaf selector again - testing idempotency
87 cisco.aci.aci_node_block:
88 <<: *aci_node_block_leaf_present
89 register: nm_add_node_block_leaf_idempotency
90
91 - name: Add a second Node Block for Switch policy leaf selector (normal_mode)
92 cisco.aci.aci_node_block: &aci_node_block_leaf_2_present
93 <<: *aci_info
94 switch_profile: ansible_access_leaf_switch_profile
95 port_selector: ansible_access_leaf_switch_selector
96 node_block: ansible_node_block_leaf_2
97 from: 1012
98 to: 1012
99 description: Node Block for Switch policy leaf selector 2
100 type_node: leaf
101 state: present
102 register: nm_add_node_block_leaf_2
103
104 - name: Add a Node Block for Switch policy spine selector (normal_mode)
105 cisco.aci.aci_node_block: &aci_node_block_spine_present
106 <<: *aci_info
107 switch_profile: ansible_access_spine_switch_profile
108 port_selector: ansible_access_spine_switch_selector
109 node_block: ansible_node_block_spine
110 from: 1014
111 to: 1014
112 description: Node Block for Switch policy spine selector
113 type_node: spine
114 state: present
115 register: nm_add_node_block_spine
116
117 - name: Asserts for Node Blocks creation tasks
118 ansible.builtin.assert:
119 that:
120 - cm_add_node_block_leaf is changed
121 - cm_add_node_block_leaf.previous == []
122 - cm_add_node_block_leaf.current == []
123 - cm_add_node_block_leaf.proposed.infraNodeBlk.attributes.name == "ansible_node_block_leaf_1"
124 - cm_add_node_block_leaf.proposed.infraNodeBlk.attributes.descr == "Node Block for Switch policy leaf selector 1"
125 - cm_add_node_block_leaf.proposed.infraNodeBlk.attributes.from_ == "1011"
126 - cm_add_node_block_leaf.proposed.infraNodeBlk.attributes.to_ == "1011"
127 - cm_add_node_block_leaf.proposed.infraNodeBlk.attributes.dn == "uni/infra/nprof-ansible_access_leaf_switch_profile/leaves-ansible_access_leaf_switch_selector-typ-range/nodeblk-ansible_node_block_leaf_1"
128 - nm_add_node_block_leaf is changed
129 - nm_add_node_block_leaf.previous == []
130 - nm_add_node_block_leaf.current.0.infraNodeBlk.attributes.name == "ansible_node_block_leaf_1"
131 - nm_add_node_block_leaf.current.0.infraNodeBlk.attributes.descr == "Node Block for Switch policy leaf selector 1"
132 - nm_add_node_block_leaf.current.0.infraNodeBlk.attributes.from_ == "1011"
133 - nm_add_node_block_leaf.current.0.infraNodeBlk.attributes.to_ == "1011"
134 - nm_add_node_block_leaf.current.0.infraNodeBlk.attributes.dn == "uni/infra/nprof-ansible_access_leaf_switch_profile/leaves-ansible_access_leaf_switch_selector-typ-range/nodeblk-ansible_node_block_leaf_1"
135 - nm_add_node_block_leaf_idempotency is not changed
136 - nm_add_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.name == "ansible_node_block_leaf_1"
137 - nm_add_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.descr == "Node Block for Switch policy leaf selector 1"
138 - nm_add_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.from_ == "1011"
139 - nm_add_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.to_ == "1011"
140 - nm_add_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.dn == "uni/infra/nprof-ansible_access_leaf_switch_profile/leaves-ansible_access_leaf_switch_selector-typ-range/nodeblk-ansible_node_block_leaf_1"
141 - nm_add_node_block_leaf_2 is changed
142 - nm_add_node_block_leaf_2.previous == []
143 - nm_add_node_block_leaf_2.current.0.infraNodeBlk.attributes.name == "ansible_node_block_leaf_2"
144 - nm_add_node_block_leaf_2.current.0.infraNodeBlk.attributes.descr == "Node Block for Switch policy leaf selector 2"
145 - nm_add_node_block_leaf_2.current.0.infraNodeBlk.attributes.from_ == "1012"
146 - nm_add_node_block_leaf_2.current.0.infraNodeBlk.attributes.to_ == "1012"
147 - nm_add_node_block_leaf_2.current.0.infraNodeBlk.attributes.dn == "uni/infra/nprof-ansible_access_leaf_switch_profile/leaves-ansible_access_leaf_switch_selector-typ-range/nodeblk-ansible_node_block_leaf_2"
148 - nm_add_node_block_leaf_2 is changed
149 - nm_add_node_block_leaf_2.previous == []
150 - nm_add_node_block_spine.current.0.infraNodeBlk.attributes.name == "ansible_node_block_spine"
151 - nm_add_node_block_spine.current.0.infraNodeBlk.attributes.descr == "Node Block for Switch policy spine selector"
152 - nm_add_node_block_spine.current.0.infraNodeBlk.attributes.from_ == "1014"
153 - nm_add_node_block_spine.current.0.infraNodeBlk.attributes.to_ == "1014"
154 - nm_add_node_block_spine.current.0.infraNodeBlk.attributes.dn == "uni/infra/spprof-ansible_access_spine_switch_profile/spines-ansible_access_spine_switch_selector-typ-range/nodeblk-ansible_node_block_spine"
155
156 # QUERY NODE BLOCKS
157 - name: Query all Node Block for Switch policy leaf selectors
158 cisco.aci.aci_node_block:
159 <<: *aci_info
160 state: query
161 register: query_all_node_block
162
163 - name: Query ansible_node_block_leaf_1
164 cisco.aci.aci_node_block:
165 <<: *aci_node_block_leaf_present
166 state: query
167 register: query_ansible_node_block_leaf_1
168
169 - name: Query ansible_node_block_spine
170 cisco.aci.aci_node_block:
171 <<: *aci_node_block_spine_present
172 state: query
173 register: query_ansible_node_block_spine
174
175 - name: Asserts query tasks
176 ansible.builtin.assert:
177 that:
178 - query_all_node_block is not changed
179 - query_all_node_block.current|length >= 3
180 - query_ansible_node_block_leaf_1 is not changed
181 - query_ansible_node_block_leaf_1.current|length == 1
182 - query_ansible_node_block_leaf_1.current.0.infraNodeBlk.attributes.name == "ansible_node_block_leaf_1"
183 - query_ansible_node_block_leaf_1.current.0.infraNodeBlk.attributes.descr == "Node Block for Switch policy leaf selector 1"
184 - query_ansible_node_block_leaf_1.current.0.infraNodeBlk.attributes.from_ == "1011"
185 - query_ansible_node_block_leaf_1.current.0.infraNodeBlk.attributes.to_ == "1011"
186 - query_ansible_node_block_leaf_1.current.0.infraNodeBlk.attributes.dn == "uni/infra/nprof-ansible_access_leaf_switch_profile/leaves-ansible_access_leaf_switch_selector-typ-range/nodeblk-ansible_node_block_leaf_1"
187 - query_ansible_node_block_spine is not changed
188 - query_ansible_node_block_spine.current|length == 1
189 - query_ansible_node_block_spine.current.0.infraNodeBlk.attributes.name == "ansible_node_block_spine"
190 - query_ansible_node_block_spine.current.0.infraNodeBlk.attributes.descr == "Node Block for Switch policy spine selector"
191 - query_ansible_node_block_spine.current.0.infraNodeBlk.attributes.from_ == "1014"
192 - query_ansible_node_block_spine.current.0.infraNodeBlk.attributes.to_ == "1014"
193 - query_ansible_node_block_spine.current.0.infraNodeBlk.attributes.dn == "uni/infra/spprof-ansible_access_spine_switch_profile/spines-ansible_access_spine_switch_selector-typ-range/nodeblk-ansible_node_block_spine"
194
195 # UPDATE NODE BLOCKS
196 - name: Update first Node Block for Switch policy leaf selector (check_mode)
197 cisco.aci.aci_node_block: &aci_node_block_leaf_update
198 <<: *aci_node_block_leaf_present
199 description: Updated description for first ansible Node Block for Switch policy leaf selector
200 from: 1013
201 to: 1013
202 check_mode: true
203 register: cm_update_node_block
204
205 - name: Update first Node Block for Switch policy leaf selector (normal_mode)
206 cisco.aci.aci_node_block:
207 <<: *aci_node_block_leaf_update
208 register: nm_update_node_block
209
210 - name: Update first Node Block for Switch policy leaf selector again - testing idempotency
211 cisco.aci.aci_node_block:
212 <<: *aci_node_block_leaf_update
213 register: nm_udpate_node_block_leaf_idempotency
214
215 - name: Asserts for Node Blocks update tasks
216 ansible.builtin.assert:
217 that:
218 - cm_update_node_block is changed
219 - cm_update_node_block.previous == cm_update_node_block.current
220 - cm_update_node_block.proposed.infraNodeBlk.attributes.descr == "Updated description for first ansible Node Block for Switch policy leaf selector"
221 - cm_update_node_block.proposed.infraNodeBlk.attributes.from_ == "1013"
222 - cm_update_node_block.proposed.infraNodeBlk.attributes.to_ == "1013"
223 - nm_update_node_block is changed
224 - nm_update_node_block.current.0.infraNodeBlk.attributes.name == "ansible_node_block_leaf_1"
225 - nm_update_node_block.current.0.infraNodeBlk.attributes.descr == "Updated description for first ansible Node Block for Switch policy leaf selector"
226 - nm_update_node_block.current.0.infraNodeBlk.attributes.from_ == "1013"
227 - nm_update_node_block.current.0.infraNodeBlk.attributes.to_ == "1013"
228 - nm_update_node_block.current.0.infraNodeBlk.attributes.dn == "uni/infra/nprof-ansible_access_leaf_switch_profile/leaves-ansible_access_leaf_switch_selector-typ-range/nodeblk-ansible_node_block_leaf_1"
229 - nm_udpate_node_block_leaf_idempotency is not changed
230 - nm_udpate_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.name == "ansible_node_block_leaf_1"
231 - nm_udpate_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.descr == "Updated description for first ansible Node Block for Switch policy leaf selector"
232 - nm_udpate_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.from_ == "1013"
233 - nm_udpate_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.to_ == "1013"
234 - nm_udpate_node_block_leaf_idempotency.current.0.infraNodeBlk.attributes.dn == "uni/infra/nprof-ansible_access_leaf_switch_profile/leaves-ansible_access_leaf_switch_selector-typ-range/nodeblk-ansible_node_block_leaf_1"
235
236 # DELETE NODE BLOCKS
237 - name: Remove Node Block for Switch policy leaf selector (check_mode)
238 cisco.aci.aci_node_block: &node_block_leaf_absent
239 <<: *aci_node_block_leaf_update
240 state: absent
241 check_mode: true
242 register: cm_remove_node_block_leaf
243
244 - name: Remove Node Block for Switch policy leaf selector (normal_mode)
245 cisco.aci.aci_node_block:
246 <<: *node_block_leaf_absent
247 register: nm_remove_node_block_leaf
248
249 - name: Remove Node Block for Switch policy leaf selector - testing idempotency
250 cisco.aci.aci_node_block:
251 <<: *node_block_leaf_absent
252 register: nm_remove_node_block_leaf_idempotency
253
254 - name: Asserts deletion tasks
255 ansible.builtin.assert:
256 that:
257 - cm_remove_node_block_leaf is changed
258 - cm_remove_node_block_leaf.current == cm_remove_node_block_leaf.previous
259 - cm_remove_node_block_leaf.proposed == {}
260 - nm_remove_node_block_leaf is changed
261 - nm_remove_node_block_leaf.previous != []
262 - nm_remove_node_block_leaf.proposed == {}
263 - nm_remove_node_block_leaf.current == []
264 - nm_remove_node_block_leaf_idempotency is not changed
265 - nm_remove_node_block_leaf_idempotency.previous == []
266 - nm_remove_node_block_leaf_idempotency.current == []
267
268 # CLEAN ENVIRONMENT BEFORE ENDING TESTS
269 - name: Remove the Access Spine Switch profile - cleanup before ending tests
270 cisco.aci.aci_access_spine_switch_profile:
271 <<: *aci_access_spine_switch_profile_absent
272
273 - name: Remove the Access Leaf Switch profile - cleanup before ending tests
274 cisco.aci.aci_switch_policy_leaf_profile:
275 <<: *aci_access_leaf_switch_profile_absent