Skip to content

Commit 9fe129c

Browse files
akinrosslhercot
authored andcommitted
[ignore] adding testcases for code coverage improvement of aci_rest module
1 parent 3517143 commit 9fe129c

File tree

5 files changed

+105
-8
lines changed

5 files changed

+105
-8
lines changed

plugins/modules/aci_rest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,7 @@ def main():
405405
module.fail_json(msg="Failed to parse provided XML payload: {0}".format(to_text(e)), payload=payload)
406406

407407
# Perform actual request using auth cookie (Same as aci.request(), but also supports XML)
408-
if "port" in aci.params and aci.params.get("port") is not None:
409-
aci.url = "{protocol}://{host}:{port}/".format_map(aci.params) + path.lstrip("/")
410-
else:
411-
aci.url = "{protocol}://{host}/".format_map(aci.params) + path.lstrip("/")
408+
aci.url = "{0}/{1}".format(aci.base_url, path.lstrip("/"))
412409
if aci.params.get("method") != "get" and not rsp_subtree_preserve:
413410
aci.url = update_qsl(aci.url, {"rsp-subtree": "modified"})
414411

tests/integration/targets/aci_rest/tasks/error_handling.yml

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,102 @@
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")

tests/integration/targets/aci_rest/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
- include_tasks: xml_string.yml
2525
tags: xml_string
2626

27-
- include_tasks: error_handling.yml
28-
tags: error_handling
29-
3027
- include_tasks: xml_file.yml
3128
tags: xml_file
29+
30+
- include_tasks: error_handling.yml
31+
tags: error_handling
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{wrong_payload
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wrong_payload

0 commit comments

Comments
 (0)