From 9558ac75f8c788c94a89e8adbc314c4efe3e9309 Mon Sep 17 00:00:00 2001 From: Paolo Gentili Date: Thu, 1 Aug 2024 14:49:37 +0200 Subject: [PATCH] Add: ubuntu_sso_email assertion when provisioning UC via zapper_kvm --- .../devices/zapper_kvm/README.md | 1 + .../devices/zapper_kvm/__init__.py | 12 ++++++ .../zapper_kvm/tests/test_zapper_kvm.py | 40 +++++++++++++++++++ docs/.wordlist.txt | 2 + docs/reference/device-connector-types.rst | 5 ++- 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/README.md b/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/README.md index 295d0478..238fa1ed 100644 --- a/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/README.md +++ b/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/README.md @@ -23,6 +23,7 @@ Unless specified via _autoinstall_ storage filter, the tool will select the larg - __cmdline_append__ (optional): kernel parameters to append at the end of GRUB entry cmdline - __base_user_data__ (optional): a string containing base64 encoded autoinstall user-data to use as base for provisioning, it should be validated against [this schema](https://canonical-subiquity.readthedocs-hosted.com/en/latest/reference/autoinstall-schema.html) - __autoinstall_oem__: (optional): set to "true" to install OEM meta-packages and the reset partition (Desktop 24.04+) +- __ubuntu_sso_email__: (optional): a valid Ubuntu SSO email to which the DUT provisioned with a non-dangerous grade UC image will be linked ## Ubuntu Desktop 22.04 OEM diff --git a/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/__init__.py b/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/__init__.py index 1e934b41..a763de9d 100644 --- a/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/__init__.py +++ b/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/__init__.py @@ -101,6 +101,17 @@ def _validate_configuration( ) retries = self.job_data["provision_data"].get("robot_retries", 1) + # If a SSO email is specified, e.g. UC, username must match + # the local-part because that would be the only user available + # on the DUT after provisioning. + if "ubuntu_sso_email" in self.job_data["provision_data"]: + email = self.job_data["provision_data"]["ubuntu_sso_email"] + if username != email.split("@")[0]: + raise ProvisioningError( + "Test username doesn't match the provided " + "ubuntu_sso_email." + ) + provisioning_data = { "url": url, "username": username, @@ -119,6 +130,7 @@ def _validate_configuration( "skip_download", "wait_until_ssh", "live_image", + "ubuntu_sso_email", ] provisioning_data.update( { diff --git a/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/tests/test_zapper_kvm.py b/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/tests/test_zapper_kvm.py index ec1aceed..c754c8b9 100644 --- a/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/tests/test_zapper_kvm.py +++ b/device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/tests/test_zapper_kvm.py @@ -92,6 +92,7 @@ def test_validate_configuration_w_opt(self): "skip_download": True, "wait_until_ssh": True, "live_image": False, + "ubuntu_sso_email": "username@domain.com", }, "test_data": { "test_username": "username", @@ -115,10 +116,49 @@ def test_validate_configuration_w_opt(self): "skip_download": True, "wait_until_ssh": True, "live_image": False, + "ubuntu_sso_email": "username@domain.com", } self.assertEqual(args, ()) self.assertDictEqual(kwargs, expected) + def test_validate_configuration_raises_sso(self): + """ + Test whether the validate_configuration raises an exception + if the provided test_username doesn't match with the SSO email. + """ + + connector = DeviceConnector() + connector.config = { + "device_ip": "1.1.1.1", + "control_host": "1.1.1.2", + "reboot_script": ["cmd1", "cmd2"], + } + connector.job_data = { + "job_queue": "queue", + "provision_data": { + "url": "http://example.com/image.iso", + "robot_tasks": [ + "job.robot", + "another.robot", + ], + "storage_layout": "lvm", + "robot_retries": 3, + "cmdline_append": "more arguments", + "skip_download": True, + "wait_until_ssh": True, + "live_image": False, + "ubuntu_sso_email": "realuser@domain.com", + }, + "test_data": { + "test_username": "username", + "test_password": "password", + }, + } + + connector._get_autoinstall_conf = Mock() + with self.assertRaises(ProvisioningError): + connector._validate_configuration() + def test_validate_configuration_alloem(self): """ Test whether the validate_configuration function returns diff --git a/docs/.wordlist.txt b/docs/.wordlist.txt index 33906e99..50a70b04 100644 --- a/docs/.wordlist.txt +++ b/docs/.wordlist.txt @@ -85,6 +85,7 @@ SecureBoot SKU SQA SSID +SSO subdirectories subfolders subtree @@ -97,6 +98,7 @@ txt Ubuntu ubuntu url +UC UI URI USB diff --git a/docs/reference/device-connector-types.rst b/docs/reference/device-connector-types.rst index 8c1126da..c901d872 100644 --- a/docs/reference/device-connector-types.rst +++ b/docs/reference/device-connector-types.rst @@ -284,7 +284,7 @@ The ``zapper_kvm`` device connector, depending on the target image, supports the path from the ``robot/snippets`` path in the Zapper repository. * - ``storage_layout`` - When provisioning an image supporting *autoinstall*, the storage_layout can - be either ``lvm`` (default), ``direct``, ``zfs`` or ``hybrid`` (Core, Desktop 23.10+) + be either ``lvm`` (default), ``direct``, ``zfs`` or ``hybrid`` (Desktop 23.10+, UC24) * - ``cmdline_append`` - (Optional) When provisioning an image supporting *autoinstall*, the cmdline_append can be used to append Kernel parameters to the standard GRUB entry. @@ -295,6 +295,9 @@ The ``zapper_kvm`` device connector, depending on the target image, supports the on this topic * - ``autoinstall_oem``: - (Optional) Set to "true" to install OEM meta-packages and the reset partition (Desktop 24.04+). + * - ``ubuntu_sso_email``: + - (Optional) A valid Ubuntu SSO email to which the DUT provisioned with a non-dangerous grade UC image will be linked (UC24). +. .. list-table:: Supported ``provision_data`` keys for ``zapper_kvm`` with target Ubuntu OEM 22.04 :header-rows: 1