Skip to content

Commit

Permalink
Merge pull request #214 from thp-canonical/muxpi-custom
Browse files Browse the repository at this point in the history
feat(muxpi): provisioning: skip user creation, boot check via URL
  • Loading branch information
plars authored Mar 8, 2024
2 parents 3bfcc64 + b8a0e20 commit ce996d1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 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 @@ -162,11 +163,14 @@ def provision(self):
logger.info("Flashing Test image")
try:
self.flash_test_image(url)
with self.remote_mount():
image_type = self.get_image_type()
logger.info("Image type detected: {}".format(image_type))
logger.info("Creating Test User")
self.create_user(image_type)
if self.job_data["provision_data"].get("create_user", True):
with self.remote_mount():
image_type = self.get_image_type()
logger.info("Image type detected: {}".format(image_type))
logger.info("Creating Test User")
self.create_user(image_type)
else:
logger.info("Skipping test user creation (create_user=False)")
self.run_post_provision_script()
logger.info("Booting Test Image")
cmd = self.config.get("control_switch_device_cmd", "stm -dut")
Expand Down Expand Up @@ -469,9 +473,30 @@ def check_test_image_booted(self):
test_password = self.job_data.get("test_data", {}).get(
"test_password", "ubuntu"
)

boot_check_url = self.job_data.get("provision_data", {}).get(
"boot_check_url", None
)
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",
Expand Down
4 changes: 4 additions & 0 deletions docs/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ xenial
yaml
LTS
virtualenv
IoT
Tegra
zstd
xz
53 changes: 52 additions & 1 deletion docs/reference/device-connector-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To specify the commands to run by the device in each test phase, set the ``testf
* - ``multi``
- Experimental device type that is used for provisioning multiple other devices in order to coordinate a job across multiple devices at the same time.
* - ``muxpi``
- MuxPi or SDWire device capable of multiplexing the SD card so that it can be written, then control can be switched to the DUT to boot the image.
- MuxPi or SDWire device capable of multiplexing the SD card so that it can be written, then control can be switched to the DUT to boot the image, see :ref:`muxpi`.
* - ``netboot``
- Special purpose device connector for a few devices that must be booted and flashed remotely but the image they need is not compatible with MaaS.
* - ``noprovision``
Expand All @@ -32,3 +32,54 @@ To specify the commands to run by the device in each test phase, set the ``testf
- This device connector is used for Lenovo OEM devices running certain versions of OEM supported images that can use a recovery partition to recover not only the same image, but in some cases, other OEM image versions as well.
* - ``hp_oemscript``
- This device connector is used for HP OEM devices running certain versions of OEM supported images that can use a recovery partition to recover not only the same image, but in some cases, other OEM image versions as well.

.. _muxpi:

muxpi
-----

The ``muxpi`` device connector supports the following ``provision_data`` keys:

.. list-table:: Supported ``provision_data`` keys for ``muxpi``
:header-rows: 1

* - Key
- Description
* - ``url``
- URL to a compressed disk image that is downloaded, decompressed using
``unzstd`` (**xz** format is recommended, but any format supported by
the ``zstd`` tool is supported) and
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_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``):

.. list-table:: Supported image types
:header-rows: 1

* - Image type
- Description
* - ``ce-oem-iot``
- IoT OEM certification
* - ``tegra``
- NVidia Tegra
* - ``pi-desktop``
- Ubuntu Desktop on Raspberry Pi
* - ``ubuntu``
- Ubuntu Classic
* - ``core``
- Ubuntu Core
* - ``core20``
- Ubuntu Core 20
* - ``ubuntu-cpc``
- Ubuntu Certified Public Cloud

0 comments on commit ce996d1

Please sign in to comment.