Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Add firmware_update phase #91

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/testflinger_device_connectors/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def main():
cmd_subparser = dev_subparser.add_subparsers()
for cmd, func in (
("provision", dev_module.provision),
("firmware_update", dev_module.firmware_update),
("runtest", dev_module.runtest),
("allocate", dev_module.allocate),
("reserve", dev_module.reserve),
Expand Down
56 changes: 56 additions & 0 deletions src/testflinger_device_connectors/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import yaml

import testflinger_device_connectors
from testflinger_device_connectors.fw_devices.firmware_update import (
detect_device,
)


class ProvisioningError(Exception):
Expand Down Expand Up @@ -115,6 +118,59 @@ def stop(self):


class DefaultDevice:
def firmware_update(self, args):
"""Default method for processing firmware update commands"""
with open(args.config) as configfile:
config = yaml.safe_load(configfile)
testflinger_device_connectors.configure_logging(config)
testflinger_device_connectors.logmsg(
logging.INFO, "BEGIN firmware_update"
)

test_opportunity = testflinger_device_connectors.get_test_opportunity(
args.job_data
)
fw_config = test_opportunity.get("firmware_update_data")
ignore_failure = fw_config.get("ignore_failure", False)
version = fw_config.get("version")
device_ip = config["device_ip"]
target_device_username = "ubuntu"
exitcode = 0
supported_version = ["latest"]

if version not in supported_version:
testflinger_device_connectors.logmsg(
logging.INFO,
"Fail to provide version in firmware_update_data. "
+ "Current supported version: latest",
)
exitcode = 1
else:
try:
target_device = detect_device(
device_ip, target_device_username
)
target_device.get_fw_info()
if version == "latest":
reboot_required = target_device.upgrade()
if reboot_required:
target_device.reboot()
update_succeeded = target_device.check_results()
if not update_succeeded:
exitcode = 1
except Exception as e:
testflinger_device_connectors.logmsg(
logging.ERROR, f"Firmware Update failed: {str(e)}"
)
exitcode = 1
finally:
testflinger_device_connectors.logmsg(
logging.INFO, "END firmware_update"
)
if ignore_failure:
exitcode = 0
return exitcode

def runtest(self, args):
"""Default method for processing test commands"""
with open(args.config) as configfile:
Expand Down
Loading