227227 cisco.aci.aci_rest :
228228 << : *tenant
229229 content :
230- <fvTenant name="test_tenant_cert_auth" status="deleted"/>
230+ <fvTenant name="test_tenant_cert_auth" status="deleted"/>
231+
232+ # Test cases for import error handling
233+
234+ - name : Uninstall lxml for error checking
235+ ansible.builtin.pip : &lxml
236+ name : lxml
237+ state : absent
238+ ignore_errors : true # ignore errors to because of multiple executions for hosts at the same time
239+
240+ - name : Uninstall xmljson for error checking
241+ ansible.builtin.pip : &xmljson
242+ name : xmljson
243+ state : absent
244+ ignore_errors : true # ignore errors to because of multiple executions for hosts at the same time
245+
246+ - name : Uninstall pyyaml for error checking
247+ ansible.builtin.pip : &pyyaml
248+ name : pyyaml
249+ state : absent
250+ ignore_errors : true # ignore errors to because of multiple executions for hosts at the same time
251+
252+ - name : Create tenant with invalid src attribute
253+ cisco.aci.aci_rest :
254+ << : *tenant
255+ ignore_errors : true
256+ register : err_missing_lxml
257+
258+ - name : Install lxml
259+ ansible.builtin.pip :
260+ << : *lxml
261+ state : present
262+ ignore_errors : true # ignore errors to because of multiple executions for hosts at the same time
263+
264+ - name : Create tenant with invalid src attribute
265+ cisco.aci.aci_rest :
266+ << : *tenant
267+ ignore_errors : true
268+ register : err_missing_xmljson
269+
270+ - name : Install xmljson
271+ ansible.builtin.pip :
272+ << : *xmljson
273+ state : present
274+ ignore_errors : true # ignore errors to because of multiple executions for hosts at the same time
275+
276+ - name : Install pyyaml
277+ ansible.builtin.pip :
278+ << : *pyyaml
279+ state : present
280+ ignore_errors : true # ignore errors to because of multiple executions for hosts at the same time
281+
282+ # Test case for invalid src
283+
284+ - name : Create tenant with invalid src attribute
285+ cisco.aci.aci_rest :
286+ << : *tenant
287+ src : " ./targets/aci_rest/invalid_src.txt"
288+ content : " {{ fakevar | default(omit) }}"
289+ ignore_errors : true
290+ register : err_src_attribute
291+
292+ # Test case for invalid path extension
293+
294+ - name : Create tenant with invalid path extension
295+ cisco.aci.aci_rest :
296+ << : *tenant
297+ path : /api/mo/uni.invalid
298+ ignore_errors : true
299+ register : err_extension
300+
301+ # Parse failures
302+
303+ - name : Create tenant with fail to parse xml
304+ cisco.aci.aci_rest :
305+ << : *tenant
306+ src : " ./targets/aci_rest/tasks/xml_files/fail_parse.xml"
307+ content : " {{ fakevar | default(omit) }}"
308+ ignore_errors : true
309+ register : err_fail_parse_xml
310+
311+ - name : Create tenant with fail to parse json
312+ cisco.aci.aci_rest :
313+ << : *tenant
314+ path : /api/mo/uni.json
315+ src : " ./targets/aci_rest/tasks/xml_files/fail_parse.json"
316+ content : " {{ fakevar | default(omit) }}"
317+ ignore_errors : true
318+ register : err_fail_parse_json
319+
320+ - name : Assertions checks for import error handling, invalid src, invalid path extension and parse failures
321+ assert :
322+ that :
323+ - err_missing_lxml.msg == "The lxml python library is missing, or lacks etree support."
324+ - err_missing_xmljson.msg == "The xmljson python library is missing, or lacks cobra support."
325+ - err_src_attribute.msg == "Cannot find/access src './targets/aci_rest/invalid_src.txt'"
326+ - err_extension.msg == "Failed to find REST API payload type (neither .xml nor .json)."
327+ - err_fail_parse_xml.msg.startswith("Failed to parse provided XML payload")
328+ - err_fail_parse_json.msg.startswith("Failed to parse provided JSON/YAML payload")
0 commit comments