Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state check to check_device_booted #137

Merged
merged 1 commit into from
Oct 26, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,72 @@ def provision(self):
self._run_cmd_list(recovery_cmds)
self.check_device_booted()

def check_generic_classic(self):
try:
test_username = self.job_data.get("test_data", {}).get(
"test_username", "ubuntu"
)
test_password = self.job_data.get("test_data", {}).get(
"test_password", "ubuntu"
)
except AttributeError:
test_username = "ubuntu"
test_password = "ubuntu"

image_type = (
subprocess.check_output(
(
"sshpass -p {} ssh -o StrictHostKeyChecking=no "
"-o UserKnownHostsFile=/dev/null "
"{}@{} snap model | grep model"
).format(
test_password,
test_username,
self.config["device_ip"],
),
shell=True,
)
).decode()

if "generic-classic" in image_type:
return True

return False

def check_device_initialized(self):
try:
test_username = self.job_data.get("test_data", {}).get(
"test_username", "ubuntu"
)
test_password = self.job_data.get("test_data", {}).get(
"test_password", "ubuntu"
)
except AttributeError:
test_username = "ubuntu"
test_password = "ubuntu"

boot_state = (
subprocess.check_output(
(
"sshpass -p {} ssh "
"-o StrictHostKeyChecking=no "
"-o UserKnownHostsFile=/dev/null "
"{}@{} snap changes "
'| grep "Initialize device"'
).format(
test_password,
test_username,
self.config["device_ip"],
),
shell=True,
)
).decode()

if "Done" in boot_state:
return True

return False

def copy_ssh_id(self):
"""Copy the ssh id to the device"""
try:
Expand Down Expand Up @@ -122,8 +188,15 @@ def check_device_booted(self):
while time.time() - started < 3600:
try:
time.sleep(90)
self.copy_ssh_id()
return True
if (
self.check_generic_classic()
or self.check_device_initialized()
):
# We can only copy ssh key after device is initialized
# or the ssh key would be missing
self.copy_ssh_id()
return True

except subprocess.SubprocessError:
pass
# If we get here, then we didn't boot in time
Expand Down