Skip to content

Commit dfc2207

Browse files
author
Shiva Shankar Vaddepally
committed
adding logout to success case
Signed-off-by: Shiva Shankar Vaddepally <shivashankar.vaddepally@cloud.com>
1 parent 84ef270 commit dfc2207

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

plugins/module_utils/module_executor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ def __init__(self, resource_name, supports_check_mode=True):
138138
self.module.params["api_path"] = "nitro/v2/config"
139139

140140
self.client = NitroAPIClient(self.module, self.resource_name)
141-
have_pass = all([
141+
have_userpass = all([
142142
self.module.params.get("nitro_user"),
143143
self.module.params.get("nitro_pass")
144144
])
145-
if have_pass and not self.module.check_mode:
145+
if have_userpass and not self.module.check_mode:
146146
self.client._headers.pop("X-NITRO-USER", None)
147147
self.client._headers.pop("X-NITRO-PASS", None)
148148
self.client._headers.pop("Cookie", None)
@@ -212,6 +212,12 @@ def return_success(self):
212212
# }
213213
if self.resource_name == "login":
214214
self.module_result["sessionid"] = self.sessionid
215+
if self.client._headers["Cookie"] != "":
216+
ok, response = adc_logout(self.client)
217+
if not ok:
218+
log("ERROR: Logout failed: %s" % response)
219+
else:
220+
log("INFO: Logout successful")
215221
self.module.exit_json(**self.module_result)
216222

217223
@trace
@@ -241,6 +247,7 @@ def return_failure(self, msg):
241247
log("ERROR: Logout failed: %s" % response)
242248
else:
243249
log("INFO: Logout successful")
250+
self.client._headers["Cookie"] = ""
244251
self.module.fail_json(msg=msg, **self.module_result)
245252

246253
@trace

0 commit comments

Comments
 (0)