Skip to content

Commit 22aa5de

Browse files
committed
changes login logic to support older iDRAC bmc #188
1 parent d6d3430 commit 22aa5de

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

cr_module/classes/redfish.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,22 @@ def login_with_redirect_handling(self):
389389
allow_redirects=False
390390
)
391391

392+
# to mitigate issues with iDRAC we assume the login worked
393+
# if a session token is present, we treat it as successful login
394+
# and take care of possible problematic error codes later
395+
session_token = response.headers.get('X-Auth-Token')
396+
session_location = response.headers.get('Location')
397+
398+
if session_token is not None:
399+
# Set up the redfish connection with the session information
400+
self.connection.set_session_key(session_token)
401+
if session_location is not None:
402+
self.connection.set_session_location(session_location)
403+
return
404+
392405
# Check for successful login
393406
if response.status_code == 201: # Created
394-
session_token = response.headers.get('X-Auth-Token')
395-
session_location = response.headers.get('Location')
396-
397-
if session_token is not None:
398-
# Set up the redfish connection with the session information
399-
self.connection.set_session_key(session_token)
400-
if session_location is not None:
401-
self.connection.set_session_location(session_location)
402-
return
403-
else:
404-
raise Exception("Login succeeded but no session token received")
407+
raise Exception("Login succeeded but no session token received")
405408

406409
# Handle error responses
407410
elif response.status_code == 401:
@@ -459,7 +462,7 @@ def init_connection(self, reset=False):
459462
self.connection = redfish.redfish_client(base_url=f"https://{self.cli_args.host}",
460463
max_retry=self.cli_args.retries, timeout=self.cli_args.timeout)
461464
except redfish.rest.v1.ServerDownOrUnreachableError:
462-
self.exit_on_error(f"Host '{ self.cli_args.host}' down or unreachable.", "CRITICAL")
465+
self.exit_on_error(f"Host '{self.cli_args.host}' down or unreachable.", "CRITICAL")
463466
except redfish.rest.v1.RetriesExhaustedError:
464467
self.exit_on_error(f"Unable to connect to Host '{self.cli_args.host}', max retries exhausted.",
465468
"CRITICAL")
@@ -693,7 +696,7 @@ def determine_vendor(self):
693696

694697
bmc_version = (
695698
manager_data.get("ManagerType") or
696-
grab(self.connection.root, f"Oem.{vendor_string}.Moniker.PRODGEN")) # Fix for iLO 5 version >2.3.0
699+
grab(self.connection.root, f"Oem.{vendor_string}.Moniker.PRODGEN")) # Fix for iLO 5 version >2.3.0
697700

698701
self.vendor_data.set_bmc_name((bmc_version or "").split(" ")[0])
699702

@@ -702,7 +705,7 @@ def determine_vendor(self):
702705

703706
self.vendor_data.set_bmc_firmware_version(
704707
manager_data.get("ManagerFirmwareVersion") or
705-
grab(manager_data, "Languages.0.Version")) # Fix for iLO 5 version >2.3.0
708+
grab(manager_data, "Languages.0.Version")) # Fix for iLO 5 version >2.3.0
706709

707710
if bmc_version is None:
708711
self.exit_on_error("Cannot determine HPE iLO version information.")

0 commit comments

Comments
 (0)