From a8321400becd4ccbbea247bb1eecd1ba35247bea Mon Sep 17 00:00:00 2001 From: Praveen K Pandey Date: Sat, 31 Aug 2024 17:27:28 +0530 Subject: [PATCH] OpTestUtils: Handle successful login response format difference Depending on code level running on BMC/eBMC, expected format for a response on successful login operation may differ. Expected: status': 'ok' Actual: "token":"" This patch adds code to handle this valid response. before FIx: Traceback (most recent call last): File "/home/shirisha_g/Desktop/Reinstall-202132021432/OPTEST-SETUP/op-test/common/OpTestUtil.py", line 2576, in login .format(r.status_code, json_data['status'], KeyError: 'status' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/shirisha_g/Desktop/Reinstall-202132021432/OPTEST-SETUP/op-test/OpTestConfiguration.py", line 939, in objs password=self.args.bmc_password) File "/home/shirisha_g/Desktop/Reinstall-202132021432/OPTEST-SETUP/op-test/common/OpTestEBMC.py", line 55, in __init__ r = self.conf.util_bmc_server.login() File "/home/shirisha_g/Desktop/Reinstall-202132021432/OPTEST-SETUP/op-test/common/OpTestUtil.py", line 2599, in login .format(self._url(uri), username, password, e)) common.Exceptions.HTTPCheck: Something happened with the HTTP Server. Review the following for more details Message="Requests post problem, check that your credentials are properly Signed-off-by: Praveen K Pandey --- common/OpTestUtil.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/OpTestUtil.py b/common/OpTestUtil.py index 62157a5a..52c348ac 100644 --- a/common/OpTestUtil.py +++ b/common/OpTestUtil.py @@ -2571,6 +2571,12 @@ def login(self, username=None, password=None): self.xAuthHeader['X-Auth-Token'] = match.group(1) self.jsonHeader.update(self.xAuthHeader) json_data = json.loads(r.text) + if json_data.get('token'): + json_data={ + "data": "User '%s' logged in" %username, + "message": "200 OK", + "status": "ok" + } log.debug("r.status_code={} json_data['status']={}" " r.text={} r.headers={} r.request.headers={}" .format(r.status_code, json_data['status'],