Skip to content

Commit

Permalink
update log level and log message
Browse files Browse the repository at this point in the history
Signed-off-by: nancyc12 <nancy.chen@canonical.com>
  • Loading branch information
nancyc12 committed Nov 16, 2023
1 parent daa720a commit b99bb18
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def run_cmd(
f"sshpass -p {self.password} ssh -t {SSH_OPTS} "
+ f' {self.user}@{self.ipaddr} "{cmd}"'
)
logmsg(logging.DEBUG, f"Run command on DUT: {ssh_cmd}")
try:
r = subprocess.run(
ssh_cmd,
Expand All @@ -59,7 +58,6 @@ def run_cmd(
)
if raise_stderr and rc != 0:
err_msg = f"Failed to execute {cmd}:\n [{rc}] {stdout} {stderr}"
logmsg(logging.DEBUG, err_msg)
raise RuntimeError(err_msg)
return rc, stdout, stderr

Expand All @@ -72,14 +70,14 @@ def get_fw_info(self):
logmsg(logging.INFO, "collect firmware info")
self.run_cmd("sudo fwupdmgr refresh --force")
rc, stdout, stderr = self.run_cmd("sudo fwupdmgr get-devices --json")
logmsg(logging.DEBUG, f"$fwupdmgr get-devices = \n{stdout}")
logmsg(logging.INFO, f"output of '$fwupdmgr get-devices'\n{stdout}")
self._parse_fwupd_raw(stdout)

def _install_fwupd(self):
self.run_cmd("sudo apt update", raise_stderr=False, timeout=120)
self.run_cmd("sudo apt install -y fwupd")
rc, stdout, stderr = self.run_cmd("sudo fwupdmgr --version")
logmsg(logging.DEBUG, stdout)
logmsg(logging.INFO, f"fwupd version\n{stdout}")

def _parse_fwupd_raw(self, fwupd_raw: str) -> bool:
"""
Expand Down Expand Up @@ -155,20 +153,18 @@ def upgrade(self) -> bool:
raise_stderr=False,
)
if rc == 0:
logmsg(logging.DEBUG, stdout)
reboot = True
else:
logmsg(
logging.ERROR,
f"[{dev_name}] Failed to upgrade to "
+ f"{latest_ver['Version']}",
+ f"{latest_ver['Version']}\n"
+ f"error: {stdout}",
)
logmsg(logging.DEBUG, stdout)
else:
logmsg(
logging.DEBUG,
f"[{dev_name}] unsupported Flags: "
+ f"{str(latest_ver['Flags'])}",
logging.INFO,
f"[{dev_name}] not an upgradable component",
)
else:
logmsg(
Expand Down Expand Up @@ -221,19 +217,18 @@ def downgrade(self) -> bool:
raise_stderr=False,
)
if rc == 0:
logmsg(logging.DEBUG, stdout)
reboot = True
else:
logmsg(
logging.ERROR,
f"[{dev_name}] fail to force install (downgrade) "
+ f"firmware {fw_file}",
+ f"firmware {fw_file}\n"
+ f"error: {stdout}",
)
logmsg(logging.DEBUG, stdout)
else:
logmsg(
logging.DEBUG,
f"[{dev_name}] unsupported Flags: {prev_ver['Flags']}",
logging.INFO,
f"[{dev_name}] not a downgradable component",
)
return reboot

Expand All @@ -257,7 +252,6 @@ def check_results(self) -> bool:
f"sudo fwupdmgr get-results {dev['DeviceId']} --json"
)
get_results = json.loads(stdout)
logmsg(logging.DEBUG, f"$fwupdmgr get-result = {stdout}%s")
try:
new_fw = get_results["Releases"][0]
update_state = get_results["UpdateState"]
Expand All @@ -266,7 +260,7 @@ def check_results(self) -> bool:
f"[{dev_name}] unable to determine if new firmware "
+ "is landed due to missing results"
)
logmsg(logging.INFO, msg)
logmsg(logging.ERROR, msg)
fwupd_result = False
continue

Expand All @@ -275,6 +269,7 @@ def check_results(self) -> bool:
f"[{dev_name}] firmware flashed {dev['Version']}"
+ f" → {expected_ver}"
)
log_level = logging.INFO
else:
FwupdUpdateState = [
"FWUPD_UPDATE_STATE_UNKNOWN",
Expand All @@ -290,8 +285,9 @@ def check_results(self) -> bool:
f"[{dev_name}] {FwupdUpdateState[update_state]}:"
+ f" {update_err}"
)
log_level = logging.ERROR
fwupd_result = False
logmsg(logging.INFO, msg)
logmsg(log_level, msg)

return fwupd_result

Expand Down

0 comments on commit b99bb18

Please sign in to comment.