Skip to content

Commit

Permalink
enhance based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nancyc12 committed Nov 17, 2023
1 parent b99bb18 commit 243f4c8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Tuple
from testflinger_device_connectors.fw_devices.base import AbstractDevice
from testflinger_device_connectors import logmsg
from enum import Enum, auto


SSH_OPTS = "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
Expand Down Expand Up @@ -264,25 +265,20 @@ def check_results(self) -> bool:
fwupd_result = False
continue

if new_fw["Version"] == expected_ver and update_state == 2:
if (
new_fw["Version"] == expected_ver
and update_state
== FwupdUpdateState.FWUPD_UPDATE_STATE_SUCCESS.value
):
msg = (
f"[{dev_name}] firmware flashed {dev['Version']}"
+ f" → {expected_ver}"
)
log_level = logging.INFO
else:
FwupdUpdateState = [
"FWUPD_UPDATE_STATE_UNKNOWN",
"FWUPD_UPDATE_STATE_PENDING",
"FWUPD_UPDATE_STATE_SUCCESS",
"FWUPD_UPDATE_STATE_FAILED",
"FWUPD_UPDATE_STATE_NEEDS_REBOOT",
"FWUPD_UPDATE_STATE_FAILED_TRANSIENT",
"FWUPD_UPDATE_STATE_LAST",
]
update_err = get_results.get("UpdateError", "")
msg = (
f"[{dev_name}] {FwupdUpdateState[update_state]}:"
f"[{dev_name}] {FwupdUpdateState(update_state).name}:"
+ f" {update_err}"
)
log_level = logging.ERROR
Expand All @@ -306,13 +302,20 @@ def check_connectable(self, timeout: int):
timeout_start = time.time()

while status != "0" and time.time() < timeout_start + timeout:
status = subprocess.check_output(
f"timeout 10 ssh {SSH_OPTS} {self.user}@{self.ipaddr} "
+ "/bin/true 2>/dev/null; echo $?",
shell=True,
universal_newlines=True,
).strip()
if status != "0" and status != "124":
try:
status = subprocess.check_output(
f"ssh {SSH_OPTS} {self.user}@{self.ipaddr} "
+ "/bin/true 2>/dev/null; echo $?",
shell=True,
universal_newlines=True,
timeout=10,
).strip()
except (
subprocess.TimeoutExpired,
subprocess.CalledProcessError,
):
pass
if status != "0":
err_msg = f"Failed to SSH to {self.ipaddr} after {timeout}s"
logmsg(logging.ERROR, err_msg)
raise RuntimeError(err_msg)
Expand All @@ -325,3 +328,13 @@ def reboot(self):
self.run_cmd("sudo reboot", raise_stderr=False)
time.sleep(10)
self.check_connectable(self.reboot_timeout)


class FwupdUpdateState(Enum):
FWUPD_UPDATE_STATE_UNKNOWN = 0
FWUPD_UPDATE_STATE_PENDING = auto()
FWUPD_UPDATE_STATE_SUCCESS = auto()
FWUPD_UPDATE_STATE_FAILED = auto()
FWUPD_UPDATE_STATE_NEEDS_REBOOT = auto()
FWUPD_UPDATE_STATE_FAILED_TRANSIENT = auto()
FWUPD_UPDATE_STATE_LAST = auto()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import unittest
import json
from unittest.mock import patch
from testflinger_device_connectors.fw_devices import LVFSDevice
from testflinger_device_connectors.fw_devices import (
LVFSDevice,
FwupdUpdateState,
)
from testflinger_device_connectors.fw_devices.LVFS.tests import fwupd_data

device_results = json.loads(fwupd_data.GET_RESULTS_RESPONSE_DATA)
Expand Down Expand Up @@ -90,7 +93,9 @@ def test_check_results_good(self):
device = LVFSDevice("", "", "")
device._parse_fwupd_raw(fwupd_data.GET_DEVICES_RESPONSE_DATA)
device_results = json.loads(fwupd_data.GET_RESULTS_RESPONSE_DATA)
device_results["UpdateState"] = 2
device_results[
"UpdateState"
] = FwupdUpdateState.FWUPD_UPDATE_STATE_SUCCESS.value
device_results["Releases"][0]["Version"] = "2.90"
device.fw_info[2]["targetVersion"] = "2.90"
self.assertTrue(device.check_results())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from testflinger_device_connectors.fw_devices.base import AbstractDevice
from testflinger_device_connectors.fw_devices.LVFS.LVFS import LVFSDevice
from testflinger_device_connectors.fw_devices.LVFS.LVFS import (
LVFSDevice,
FwupdUpdateState,
)
from testflinger_device_connectors.fw_devices.OEM.OEM import (
OEMDevice,
HPEDevice,
Expand All @@ -12,4 +15,5 @@
"OEMDevice",
"HPEDevice",
"logmsg",
"FwupdUpdateState",
]

0 comments on commit 243f4c8

Please sign in to comment.