diff options
author | Chad Smith <chad.smith@canonical.com> | 2021-11-11 12:30:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 13:30:59 -0600 |
commit | 918d69a02ec9cb891a5bc987bdce783802b1a743 (patch) | |
tree | 1668ce81c8c1ed7a69334a8972ccb72f6d20d9e0 | |
parent | 22150a20d94cddf2a41073e71a7f0e44bfb4bc51 (diff) | |
download | vyos-cloud-init-918d69a02ec9cb891a5bc987bdce783802b1a743.tar.gz vyos-cloud-init-918d69a02ec9cb891a5bc987bdce783802b1a743.zip |
tests: specialize lxd_discovery test for lxd_vm vendordata (#1106)
On Bionic and Xenial, pycloudlib sets user.vendor-data config in lxd
to ensure that lxd-agent is setup on those images.
Adapt the lxd_discovery integration test to assert the appropriate
user.vendor-data config key exists if we are on xenial or bionic.
Also add assertions that /var/lib/cloud/nocloud-net/meta-data still
exists in the images because we want NoCloud to be a viable fallback
datasource if LXD config security.lxddev = false or LXD datasource
discovery encountered an unexpected error.
-rw-r--r-- | tests/integration_tests/datasources/test_lxd_discovery.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/integration_tests/datasources/test_lxd_discovery.py b/tests/integration_tests/datasources/test_lxd_discovery.py index be76e179..93200962 100644 --- a/tests/integration_tests/datasources/test_lxd_discovery.py +++ b/tests/integration_tests/datasources/test_lxd_discovery.py @@ -2,6 +2,7 @@ import json import pytest import yaml +from tests.integration_tests.clouds import ImageSpecification from tests.integration_tests.instances import IntegrationInstance from tests.integration_tests.util import verify_clean_log @@ -53,10 +54,35 @@ def test_lxd_datasource_discovery(client: IntegrationInstance): assert "LXD socket API v. 1.0 (/dev/lxd/sock)" == v1["subplatform"] ds_cfg = json.loads(client.execute('cloud-init query ds').stdout) assert ["config", "meta_data"] == sorted(list(ds_cfg["1.0"].keys())) - assert ["user.meta_data"] == list(ds_cfg["1.0"]["config"].keys()) + if ( + client.settings.PLATFORM == "lxd_vm" and + ImageSpecification.from_os_image().release in ("xenial", "bionic") + ): + # pycloudlib injects user.vendor_data for lxd_vm on bionic and xenial + # to start the lxd-agent. + # https://github.com/canonical/pycloudlib/blob/main/pycloudlib/\ + # lxd/defaults.py#L13-L27 + lxd_config_keys = ["user.meta_data", "user.vendor_data"] + else: + lxd_config_keys = ["user.meta_data"] + assert lxd_config_keys == list(ds_cfg["1.0"]["config"].keys()) assert {"public-keys": v1["public_ssh_keys"][0]} == ( yaml.safe_load(ds_cfg["1.0"]["config"]["user.meta_data"]) ) assert ( "#cloud-config\ninstance-id" in ds_cfg["1.0"]["meta_data"] ) + # Assert NoCloud seed data is still present in cloud image metadata + # This will start failing if we redact metadata templates from + # https://cloud-images.ubuntu.com/daily/server/jammy/current/\ + # jammy-server-cloudimg-amd64-lxd.tar.xz + nocloud_metadata = yaml.safe_load( + client.read_from_file( + "/var/lib/cloud/seed/nocloud-net/meta-data" + ) + ) + assert client.instance.name == nocloud_metadata["instance-id"] + assert ( + nocloud_metadata["instance-id"] == nocloud_metadata["local-hostname"] + ) + assert v1["public_ssh_keys"][0] == nocloud_metadata["public-keys"] |