|
1 | 1 | # Test code for the ACI modules |
2 | | -# Copyright: (c) 2021, Tim Cragg (@timcragg) |
| 2 | +# Copyright: (c) 2025, Tim Cragg (@timcragg) |
3 | 3 |
|
4 | 4 | # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
5 | 5 |
|
|
42 | 42 | state: present |
43 | 43 |
|
44 | 44 | # CREATE ICMP SLA POLICY |
45 | | -- name: Create ICMP SLA policy |
46 | | - cisco.aci.aci_ip_sla_monitoring_policy: |
| 45 | +- name: Create ICMP SLA policy in check_mode |
| 46 | + cisco.aci.aci_ip_sla_monitoring_policy: &create_sla |
47 | 47 | <<: *aci_info |
48 | 48 | tenant: ansible_tenant |
49 | 49 | sla_policy: ansible_sla |
50 | 50 | sla_type: icmp |
51 | 51 | frequency: 40 |
52 | 52 | multiplier: 6 |
53 | 53 | state: present |
| 54 | + check_mode: true |
| 55 | + register: create_icmp_sla_cm |
| 56 | + |
| 57 | +- name: Verify SLA creation for check mode |
| 58 | + ansible.builtin.assert: |
| 59 | + that: |
| 60 | + - create_icmp_sla_cm is changed |
| 61 | + - create_icmp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla" |
| 62 | + - create_icmp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.name == "ansible_sla" |
| 63 | + - create_icmp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaDetectMultiplier == "6" |
| 64 | + - create_icmp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaFrequency == "40" |
| 65 | + - create_icmp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaPort == "0" |
| 66 | + - create_icmp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaType == "icmp" |
| 67 | + |
| 68 | +# CREATE ICMP SLA POLICY |
| 69 | +- name: Create ICMP SLA policy |
| 70 | + cisco.aci.aci_ip_sla_monitoring_policy: |
| 71 | + <<: *create_sla |
54 | 72 | register: create_icmp_sla |
55 | 73 |
|
56 | 74 | - name: Verify SLA creation |
57 | 75 | ansible.builtin.assert: |
58 | 76 | that: |
| 77 | + - create_icmp_sla is changed |
| 78 | + - create_icmp_sla.previous == [] |
59 | 79 | - create_icmp_sla.current.0.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla" |
60 | 80 | - create_icmp_sla.current.0.fvIPSLAMonitoringPol.attributes.name == "ansible_sla" |
61 | 81 | - create_icmp_sla.current.0.fvIPSLAMonitoringPol.attributes.slaDetectMultiplier == "6" |
|
66 | 86 | # CREATE ICMP SLA POLICY AGAIN TO TEST IDEMPOTENCE |
67 | 87 | - name: Create ICMP SLA policy again |
68 | 88 | cisco.aci.aci_ip_sla_monitoring_policy: |
69 | | - <<: *aci_info |
70 | | - tenant: ansible_tenant |
71 | | - sla_policy: ansible_sla |
72 | | - sla_type: icmp |
73 | | - frequency: 40 |
74 | | - multiplier: 6 |
75 | | - state: present |
| 89 | + <<: *create_sla |
76 | 90 | register: create_icmp_sla_again |
77 | 91 |
|
78 | 92 | - name: Verify SLA creation idempotence |
79 | 93 | ansible.builtin.assert: |
80 | 94 | that: |
81 | 95 | - create_icmp_sla_again is not changed |
| 96 | + - create_icmp_sla_again.current == create_icmp_sla.current == create_icmp_sla_again.previous |
82 | 97 |
|
83 | 98 | # CREATE SECOND SLA POLICY |
84 | | -- name: Create Second SLA policy again |
| 99 | +- name: Create Second SLA policy |
85 | 100 | cisco.aci.aci_ip_sla_monitoring_policy: |
86 | 101 | <<: *aci_info |
87 | 102 | tenant: ansible_tenant |
|
114 | 129 | - name: Verify HTTP SLA creation |
115 | 130 | ansible.builtin.assert: |
116 | 131 | that: |
| 132 | + - http_sla is changed |
| 133 | + - http_sla.previous == [] |
117 | 134 | - http_sla.current.0.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_http_sla" |
118 | 135 | - http_sla.current.0.fvIPSLAMonitoringPol.attributes.name == "ansible_http_sla" |
119 | 136 | - http_sla.current.0.fvIPSLAMonitoringPol.attributes.slaDetectMultiplier == "6" |
|
147 | 164 | <<: *aci_info |
148 | 165 | tenant: ansible_tenant |
149 | 166 | sla_policy: ansible_http_sla |
150 | | - sla_type: icmp |
| 167 | + sla_type: tcp |
151 | 168 | request_data_size: 2000 |
152 | 169 | state: present |
153 | 170 | ignore_errors: true |
|
159 | 176 | - icmp_with_sla_port is failed |
160 | 177 | - icmp_with_request_data_size is failed |
161 | 178 | - icmp_with_sla_port.msg == "Setting 'sla_port' is not allowed when 'sla_type' is not set to 'tcp'." |
162 | | - - icmp_with_request_data_size.msg == "Setting 'request_data_size' is not allowed when 'sla_type' is not set to 'http." |
| 179 | + - icmp_with_request_data_size.msg == "Setting 'request_data_size' is not allowed when 'sla_type' is set to 'tcp'." |
163 | 180 |
|
164 | 181 | # MODIFY SLA POLICY |
165 | 182 | - name: Convert ICMP SLA policy to TCP |
166 | | - cisco.aci.aci_ip_sla_monitoring_policy: |
| 183 | + cisco.aci.aci_ip_sla_monitoring_policy: &convert_icmp |
167 | 184 | <<: *aci_info |
168 | 185 | tenant: ansible_tenant |
169 | 186 | sla_policy: ansible_sla |
|
172 | 189 | frequency: 20 |
173 | 190 | multiplier: 5 |
174 | 191 | state: present |
| 192 | + check_mode: true |
| 193 | + register: update_tcp_sla_cm |
| 194 | + |
| 195 | +- name: Convert ICMP SLA policy to TCP |
| 196 | + cisco.aci.aci_ip_sla_monitoring_policy: |
| 197 | + <<: *convert_icmp |
175 | 198 | register: update_tcp_sla |
176 | 199 |
|
177 | 200 | - name: Verify SLA update |
178 | 201 | ansible.builtin.assert: |
179 | 202 | that: |
| 203 | + - update_tcp_sla_cm is changed |
| 204 | + - update_tcp_sla is changed |
| 205 | + - update_tcp_sla_cm.previous == create_icmp_sla.current == update_tcp_sla.previous |
| 206 | + - update_tcp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla" |
| 207 | + - update_tcp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.name == "ansible_sla" |
| 208 | + - update_tcp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaDetectMultiplier == "5" |
| 209 | + - update_tcp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaFrequency == "20" |
| 210 | + - update_tcp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaPort == "8080" |
| 211 | + - update_tcp_sla_cm.proposed.fvIPSLAMonitoringPol.attributes.slaType == "tcp" |
180 | 212 | - update_tcp_sla.current.0.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla" |
181 | 213 | - update_tcp_sla.current.0.fvIPSLAMonitoringPol.attributes.name == "ansible_sla" |
182 | 214 | - update_tcp_sla.current.0.fvIPSLAMonitoringPol.attributes.slaDetectMultiplier == "5" |
183 | 215 | - update_tcp_sla.current.0.fvIPSLAMonitoringPol.attributes.slaFrequency == "20" |
184 | 216 | - update_tcp_sla.current.0.fvIPSLAMonitoringPol.attributes.slaPort == "8080" |
185 | 217 | - update_tcp_sla.current.0.fvIPSLAMonitoringPol.attributes.slaType == "tcp" |
186 | 218 |
|
| 219 | +# CREATE ICMP SLA POLICY WITH DEFAULT |
| 220 | +- name: Create ICMP SLA policy with default values |
| 221 | + cisco.aci.aci_ip_sla_monitoring_policy: |
| 222 | + <<: *aci_info |
| 223 | + tenant: ansible_tenant |
| 224 | + sla_policy: ansible_sla_default |
| 225 | + sla_type: icmp |
| 226 | + state: present |
| 227 | + register: create_icmp_sla_default |
| 228 | + |
| 229 | +- name: Verify SLA creation for check mode |
| 230 | + ansible.builtin.assert: |
| 231 | + that: |
| 232 | + - create_icmp_sla_default.current.0.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla_default" |
| 233 | + - create_icmp_sla_default.current.0.fvIPSLAMonitoringPol.attributes.name == "ansible_sla_default" |
| 234 | + - create_icmp_sla_default.current.0.fvIPSLAMonitoringPol.attributes.slaDetectMultiplier == "3" |
| 235 | + - create_icmp_sla_default.current.0.fvIPSLAMonitoringPol.attributes.slaFrequency == "60" |
| 236 | + - create_icmp_sla_default.current.0.fvIPSLAMonitoringPol.attributes.slaPort == "0" |
| 237 | + - create_icmp_sla_default.current.0.fvIPSLAMonitoringPol.attributes.slaType == "icmp" |
| 238 | + |
187 | 239 | # QUERY IP SLA POLICY |
188 | 240 | - name: Query IP SLA monitor |
189 | 241 | cisco.aci.aci_ip_sla_monitoring_policy: |
|
215 | 267 | ansible.builtin.assert: |
216 | 268 | that: |
217 | 269 | - query_sla_all is not changed |
218 | | - - query_sla_all.current | length > 1 |
| 270 | + - query_sla_all.current | length >= 2 |
| 271 | + - "'uni/tn-ansible_tenant/ipslaMonitoringPol-second_ansible_sla' in query_sla_all.current | map(attribute='fvIPSLAMonitoringPol.attributes.dn') | list" |
| 272 | + - "'uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla' in query_sla_all.current | map(attribute='fvIPSLAMonitoringPol.attributes.dn') | list" |
219 | 273 |
|
220 | 274 | # DELETE SLA POLICY |
221 | 275 | - name: Remove IP SLA monitor |
222 | | - cisco.aci.aci_ip_sla_monitoring_policy: |
| 276 | + cisco.aci.aci_ip_sla_monitoring_policy: &remove_sla |
223 | 277 | <<: *aci_info |
224 | 278 | tenant: ansible_tenant |
225 | 279 | sla_policy: ansible_sla |
226 | 280 | state: absent |
| 281 | + check_mode: true |
| 282 | + register: remove_tcp_sla_cm |
| 283 | + |
| 284 | +- name: Remove IP SLA monitor |
| 285 | + cisco.aci.aci_ip_sla_monitoring_policy: |
| 286 | + <<: *remove_sla |
227 | 287 | register: remove_tcp_sla |
228 | 288 |
|
229 | 289 | - name: Verify IP SLA deletion |
230 | 290 | ansible.builtin.assert: |
231 | 291 | that: |
| 292 | + - remove_tcp_sla_cm is changed |
| 293 | + - remove_tcp_sla_cm.proposed == {} |
| 294 | + - remove_tcp_sla_cm.previous.0.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla" |
| 295 | + - remove_tcp_sla_cm.previous.0.fvIPSLAMonitoringPol.attributes.name == "ansible_sla" |
232 | 296 | - remove_tcp_sla is changed |
233 | 297 | - remove_tcp_sla.current == [] |
234 | 298 | - remove_tcp_sla.previous.0.fvIPSLAMonitoringPol.attributes.dn == "uni/tn-ansible_tenant/ipslaMonitoringPol-ansible_sla" |
|
241 | 305 | tenant: ansible_tenant |
242 | 306 | sla_policy: ansible_sla |
243 | 307 | state: absent |
244 | | - register: remove_tcp_sla_again |
| 308 | + register: remove_tcp_sla_cm_again |
245 | 309 |
|
246 | 310 | - name: Verify IP SLA deletion |
247 | 311 | ansible.builtin.assert: |
248 | 312 | that: |
249 | | - - remove_tcp_sla_again is not changed |
| 313 | + - remove_tcp_sla_cm_again is not changed |
| 314 | + - remove_tcp_sla_cm_again.current == [] |
250 | 315 |
|
251 | 316 | # CLEAN UP |
252 | 317 | - name: remove ansible_tenant |
|
0 commit comments