Skip to content

Commit

Permalink
pr fix: boot_check_url
Browse files Browse the repository at this point in the history
  • Loading branch information
thp-canonical committed Mar 7, 2024
1 parent 7a0c10f commit 552e8b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import subprocess
import shlex
import time
import urllib.request
from contextlib import contextmanager
from pathlib import Path

Expand Down Expand Up @@ -438,25 +439,38 @@ def check_test_image_booted(self):
"test_password", "ubuntu"
)

DEFAULT_BOOT_CHECK_CMD = (
'sshpass -p "$TEST_PASSWORD" ssh-copy-id -o StrictHostKeyChecking=no "
"-o UserKnownHostsFile=/dev/null "$TEST_USERNAME@$DEVICE_IP"'
boot_check_url = self.job_data.get("provision_data", {}).get(
"boot_check_url", None
)
boot_check_cmd = self.job_data.get("provision_data", {}).get(
"boot_check_cmd", DEFAULT_BOOT_CHECK_CMD
)
env = os.environ.copy()
env.update({
'TEST_USERNAME': test_username,
'TEST_PASSWORD': test_password,
'DEVICE_IP': self.config["device_ip"],
})
if boot_check_url is not None:
# We don't support full shell expansion of the URL, but just
# replace a literal $DEVICE_IP to the device's IP address
boot_check_url = boot_check_url.replace("$DEVICE_IP", self.config["device_ip"])

while time.time() - started < 1200:
try:
time.sleep(10)

if boot_check_url is not None:
with urllib.request.urlopen(boot_check_url, timeout=5) as response:
if response.status == 200:
return True

continue

cmd = [
"sshpass",
"-p",
test_password,
"ssh-copy-id",
"-o",
"StrictHostKeyChecking=no",
"-o",
"UserKnownHostsFile=/dev/null",
"{}@{}".format(test_username, self.config["device_ip"]),
]
subprocess.check_output(
boot_check_cmd, env=env, stderr=subprocess.STDOUT, timeout=60, shell=True
cmd, stderr=subprocess.STDOUT, timeout=60
)
return True
except Exception:
Expand Down
16 changes: 8 additions & 8 deletions docs/reference/device-connector-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ The ``muxpi`` device connector supports the following ``provision_data`` keys:
flashed to the SD card, which will be used to boot up the DUT.
* - ``create_user``
- Boolean (default ``true``) specifying whether a user account should be created.
* - ``boot_check_cmd``
- Shell command to use for checking if the DUT has finished booting; use
the DUT is reachable via ``$DEVICE_IP``; if not set, SSH will be used to
check when the device comes online. For logging into the device,
``$TEST_USERNAME`` and ``$TEST_PASSWORD`` will be set to the values of
``test_username`` and ``test_password`` from the job's ``test_data``.
When ``boot_check_cmd`` is set, the SSH key for public key authentication
won't be installed on the DUT to allow for testing without SSH.
* - ``boot_check_url``
- URL to use for checking if the DUT has finished booting; a literal
``$DEVICE_IP`` in the URL will be replaced with the IP address of the DUT.
Requesting the URL has to return HTTP status code 200 for the device to
be considered "booted".
If not set, SSH will be used to check when the device comes online.
When ``boot_check_url`` is set, the SSH key for public key authentication
won't be installed on the DUT to allow for test cases without SSH.

Image types recognised for user account creation
(the device type is not used if ``create_user: false`` is set in ``provision_data``):
Expand Down

0 comments on commit 552e8b3

Please sign in to comment.