Debian Codegraph @

ansible_collections/cisco/mso/tests/integration/targets/ndo_fex_device/tasks/main.yml

raw symbols SCIP
1 # Test code for the MSO modules
2 # Copyright: (c) 2025, Shreyas Srish (@shrsr) <[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 MultiSite host, username and password
7 ansible.builtin.fail:
8 msg: "Please define the following variables: mso_hostname, mso_username and mso_password."
9 when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
10
11 # CLEAN ENVIRONMENT
12 - name: Set vars
13 ansible.builtin.set_fact:
14 mso_info: &mso_info
15 host: "{{ mso_hostname }}"
16 username: "{{ mso_username }}"
17 password: "{{ mso_password }}"
18 validate_certs: "{{ mso_validate_certs | default(false) }}"
19 use_ssl: "{{ mso_use_ssl | default(true) }}"
20 use_proxy: "{{ mso_use_proxy | default(true) }}"
21 output_level: '{{ mso_output_level | default("debug") }}'
22
23 # QUERY VERSION
24 - name: Query mso version
25 cisco.mso.mso_version:
26 <<: *mso_info
27 state: query
28 register: version
29
30 - name: Execute tasks only for FEX version > 2.0
31 when: version.current.version is version('2.0', '>')
32 block:
33
34 # SETUP
35 - name: Ensure Fabric Resource template does not exist
36 cisco.mso.ndo_template: &ndo_fabric_resource_template_absent
37 <<: *mso_info
38 template: ansible_fabric_resource_template
39 type: fabric_resource
40 state: absent
41
42 - name: Create a new Fabric Resource template
43 cisco.mso.ndo_template:
44 <<: *ndo_fabric_resource_template_absent
45 state: present
46 register: create_fabric_resource
47
48 # CREATE
49 - name: Create FEX Device (check mode)
50 cisco.mso.ndo_fex_device: &add_fex_device
51 <<: *mso_info
52 template: ansible_fabric_resource_template
53 name: ansible_fex_device
54 fex_id: 101
55 nodes: [203]
56 interfaces: ['1/3']
57 description: Ansible FEX Device
58 state: present
59 check_mode: true
60 register: cm_fex_device
61
62 - name: Create FEX Device
63 cisco.mso.ndo_fex_device:
64 <<: *add_fex_device
65 register: nm_fex_device
66
67 - name: Create FEX Device again
68 cisco.mso.ndo_fex_device:
69 <<: *add_fex_device
70 register: nm_fex_device_again
71
72 - name: Assert FEX Device is created
73 ansible.builtin.assert:
74 that:
75 - cm_fex_device is changed
76 - nm_fex_device is changed
77 - nm_fex_device_again is not changed
78 - cm_fex_device.previous == nm_fex_device.previous == {}
79 - cm_fex_device.current.templateName == nm_fex_device.current.templateName == create_fabric_resource.current.displayName
80 - cm_fex_device.current.templateId == nm_fex_device.current.templateId == create_fabric_resource.current.templateId
81 - cm_fex_device.current.name == nm_fex_device.current.name == "ansible_fex_device"
82 - cm_fex_device.current.fexId == nm_fex_device.current.fexId == 101
83 - cm_fex_device.current.nodes[0] == nm_fex_device.current.nodes[0] == "203"
84 - cm_fex_device.current.interfaces == nm_fex_device.current.interfaces == "1/3"
85 - cm_fex_device.current.description == nm_fex_device.current.description == "Ansible FEX Device"
86 - nm_fex_device_again.previous == nm_fex_device_again.current == nm_fex_device.current
87
88 # UPDATE
89 - name: Update FEX Device (check mode)
90 cisco.mso.ndo_fex_device: &update_fex_device
91 <<: *add_fex_device
92 description: Test Ansible FEX Device Updated
93 nodes: [101, 102, 103-105]
94 interfaces: ['1/1,1/2-4']
95 check_mode: true
96 register: cm_update_fex_device
97
98 - name: Update FEX Device
99 cisco.mso.ndo_fex_device:
100 <<: *update_fex_device
101 register: nm_update_fex_device
102
103 - name: Update FEX Device again
104 cisco.mso.ndo_fex_device:
105 <<: *update_fex_device
106 register: nm_update_fex_device_again
107
108 - name: Assert FEX Device is updated
109 ansible.builtin.assert:
110 that:
111 - cm_update_fex_device is changed
112 - nm_update_fex_device is changed
113 - nm_update_fex_device_again is not changed
114 - cm_update_fex_device.current.templateName == nm_update_fex_device.current.templateName == create_fabric_resource.current.displayName
115 - cm_update_fex_device.current.templateId == nm_update_fex_device.current.templateId == create_fabric_resource.current.templateId
116 - cm_update_fex_device.previous.nodes[0] == nm_update_fex_device.previous.nodes[0] == "203"
117 - cm_update_fex_device.current.nodes[0] == nm_update_fex_device.current.nodes[0] == "101"
118 - cm_update_fex_device.current.nodes[1] == nm_update_fex_device.current.nodes[1] == "102"
119 - cm_update_fex_device.current.nodes[2] == nm_update_fex_device.current.nodes[2] == "103-105"
120 - cm_update_fex_device.previous.interfaces == nm_update_fex_device.previous.interfaces == "1/3"
121 - cm_update_fex_device.current.interfaces == nm_update_fex_device.current.interfaces == "1/1,1/2-4"
122 - cm_update_fex_device.previous.description == nm_update_fex_device.previous.description == "Ansible FEX Device"
123 - cm_update_fex_device.current.description == nm_update_fex_device.current.description == "Test Ansible FEX Device Updated"
124 - nm_update_fex_device_again.previous == nm_update_fex_device_again.current == nm_update_fex_device.current
125
126 - name: Create another FEX Device for query all
127 cisco.mso.ndo_fex_device: &add_fex_device_another
128 <<: *mso_info
129 template: ansible_fabric_resource_template
130 name: ansible_fex_device_another
131 fex_id: 101
132 nodes: [203]
133 interfaces: ['1/3']
134 description: Ansible FEX Device
135 state: present
136 register: another_fex
137
138 # QUERY
139 - name: Query FEX Device by name
140 cisco.mso.ndo_fex_device:
141 <<: *mso_info
142 template: ansible_fabric_resource_template
143 name: ansible_fex_device
144 state: query
145 register: query_name
146
147 - name: Query FEX Device by UUID
148 cisco.mso.ndo_fex_device:
149 <<: *mso_info
150 template_id: '{{ create_fabric_resource.current.templateId }}'
151 uuid: '{{ nm_fex_device.current.uuid }}'
152 state: query
153 register: query_uuid
154
155 - name: Query all FEX Devices
156 cisco.mso.ndo_fex_device:
157 <<: *mso_info
158 template: ansible_fabric_resource_template
159 state: query
160 register: query_all
161
162 - name: Assert FEX Device is queried
163 ansible.builtin.assert:
164 that:
165 - query_name is not changed
166 - query_uuid is not changed
167 - query_name.current == nm_update_fex_device.current
168 - query_uuid.current == nm_update_fex_device.current
169 - query_all.current | length == 2
170 - query_all.current.0.name == "ansible_fex_device"
171 - query_all.current.1.name == "ansible_fex_device_another"
172
173 # DELETE
174 - name: Delete FEX Device using name (check mode)
175 cisco.mso.ndo_fex_device: &delete_fex_device
176 <<: *mso_info
177 template: ansible_fabric_resource_template
178 name: ansible_fex_device
179 state: absent
180 check_mode: true
181 register: cm_delete_fex_device
182
183 - name: Delete FEX Device using name
184 cisco.mso.ndo_fex_device:
185 <<: *delete_fex_device
186 register: nm_delete_fex_device
187
188 - name: Delete FEX Device using name again
189 cisco.mso.ndo_fex_device:
190 <<: *delete_fex_device
191 register: nm_delete_fex_device_again
192
193 - name: Delete FEX Device using uuid
194 cisco.mso.ndo_fex_device:
195 <<: *mso_info
196 template: ansible_fabric_resource_template
197 uuid: '{{ another_fex.current.uuid }}'
198 state: absent
199 register: nm_delete_another_fex_device
200
201 - name: Assert FEX Device is deleted
202 ansible.builtin.assert:
203 that:
204 - cm_delete_fex_device is changed
205 - nm_delete_fex_device is changed
206 - nm_delete_fex_device_again is not changed
207 - nm_delete_another_fex_device is changed
208 - cm_delete_fex_device.current == nm_delete_fex_device.current == {}
209 - cm_delete_fex_device.previous.name == nm_delete_fex_device.previous.name == "ansible_fex_device"
210 - nm_delete_another_fex_device.previous.name == "ansible_fex_device_another"
211 - nm_delete_another_fex_device.current == {}
212 - nm_delete_fex_device_again.previous == nm_delete_fex_device_again.current == nm_delete_another_fex_device.current
213
214 # CLEANUP
215 - name: Ensure fabric resource template does not exist
216 cisco.mso.ndo_template:
217 <<: *ndo_fabric_resource_template_absent