Skip to content

Commit 5785696

Browse files
authored
Merge pull request bn222#283 from thom311/th/version-via-ssh
[th/version-via-ssh] ipu: also check BMC "FirmwareVersion" via SSH
2 parents 976b940 + 7126e97 commit 5785696

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

ipu.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,24 +426,38 @@ def start(self) -> None:
426426
def cold_boot(self) -> None:
427427
pass
428428

429-
def version(self) -> str:
429+
def _version_via_redfish(self) -> Optional[str]:
430430
url = f"https://{self.url}:8443/redfish/v1/Managers/1"
431431
res = self._run_curl(f"-k '{url}'")
432432
if res.returncode != 0:
433-
raise RuntimeError(f"Cannot detect Redfish version: failure to fetch URL {repr(url)}")
433+
return None
434434
try:
435435
data = json.loads(res.out)
436436
except Exception:
437-
raise RuntimeError(f"Cannot detect Redfish version: not valid JSON received but {repr(res.out)}")
437+
return None
438438
fwversion = data.get("FirmwareVersion")
439439
if not isinstance(fwversion, str):
440-
raise RuntimeError(f"Cannot detect Redfish version: FirmwareVersion field not present in {repr(res.out)}")
441-
fwversion = fwversion.strip()
442-
match = re.search(r"^MEV-.*\.([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$", fwversion)
440+
return None
441+
match = re.search(r"^MEV-.*\.([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$", fwversion.strip())
443442
if not match:
444-
raise RuntimeError(f"Cannot detect Redfish version: FirmwareVersion is unexpected {repr(fwversion)}")
443+
return None
445444
return match.group(1)
446445

446+
def _version_via_ssh(self) -> Optional[str]:
447+
rh = host.RemoteHost(self.url)
448+
rh.ssh_connect("root", password="", discover_auth=False)
449+
contents = rh.read_file("/etc/issue")
450+
match = re.search(r"Version: (\S+)", contents)
451+
if not match:
452+
return None
453+
return match.group(1).strip()
454+
455+
def version(self) -> str:
456+
fwversion = self._version_via_redfish() or self._version_via_ssh()
457+
if not fwversion:
458+
raise RuntimeError(f"Failed to detect Redfish version on {self.url}")
459+
return fwversion
460+
447461

448462
def extract_server(url: str) -> str:
449463
"""

0 commit comments

Comments
 (0)