Skip to content

Commit

Permalink
[bugfix] Made changes to aci_rest module to only add annotation when …
Browse files Browse the repository at this point in the history
…the value is a dictionary and changed the way the cookie is retrieved in the httpapi plugin
  • Loading branch information
shrsr committed Oct 7, 2024
1 parent 7ab2866 commit 025125e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
5 changes: 1 addition & 4 deletions plugins/httpapi/aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ def login(self, username, password):
self.connection._connected = True
try:
response, response_data = self.connection.send(path, data, method=method)
response_value = self._get_response_value(response_data)
self.connection._auth = {
"Cookie": "APIC-Cookie={0}".format(self._response_to_json(response_value).get("imdata")[0]["aaaLogin"]["attributes"]["token"])
}
self.connection._auth = {"Cookie": response.headers.get("Set-Cookie")}
self.connection.queue_message("debug", "Connection to {0} was successful".format(self.connection.get_option("host")))
except Exception as exc_login:
self.connection._connected = False
Expand Down
12 changes: 8 additions & 4 deletions plugins/module_utils/aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,14 @@ def response_json(self, rawoutput):
return

# Extract JSON API output
self.imdata = jsondata.get("imdata")
if self.imdata is None:
self.imdata = dict()
self.totalCount = int(jsondata.get("totalCount"))
if isinstance(jsondata, list):
self.imdata = jsondata
self.totalCount = len(jsondata)
else:
self.imdata = jsondata.get("imdata", {})
total_count = jsondata.get("totalCount")
if total_count is not None:
self.totalCount = int(total_count)

# Handle possible APIC error information
self.response_error()
Expand Down
17 changes: 9 additions & 8 deletions plugins/modules/aci_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,15 @@ def add_annotation(annotation, payload):
for key, val in payload.items():
if key in ANNOTATION_UNSUPPORTED:
continue
att = val.get("attributes", {})
if "annotation" not in att.keys():
att["annotation"] = annotation
# Recursively add annotation to children
children = val.get("children", None)
if children:
for child in children:
add_annotation(annotation, child)
if isinstance(val, dict):
att = val.get("attributes", {})
if "annotation" not in att.keys():
att["annotation"] = annotation
# Recursively add annotation to children
children = val.get("children", None)
if children:
for child in children:
add_annotation(annotation, child)


def add_annotation_xml(annotation, tree):
Expand Down
25 changes: 24 additions & 1 deletion tests/integration/targets/aci_rest/tasks/json_inline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,27 @@
- nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.2.fvCtx.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.2.fvCtx.attributes.annotation == "test:inoption"

- name: Disable Intersight Connectivity
cisco.aci.aci_rest:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /connector/Systems.json
method: post
rsp_subtree_preserve: true
content:
{
"AdminState": false
}
register: disable_intersight_connectivity

- name: Verify Intersight Connectivity is disabled
assert:
that:
- disable_intersight_connectivity.imdata.0.AdminState == false

0 comments on commit 025125e

Please sign in to comment.