diff options
author | Chad Smith <chad.smith@canonical.com> | 2022-02-02 21:38:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 21:38:56 -0700 |
commit | 6ed3c5dfcd9392784d2199224ac7d28d1abfdf7b (patch) | |
tree | d23ac67311e6f7f8095853a54f35cb6b363bb0c9 /tests | |
parent | b64b7d8ceb0e7bdb7cc9839c238798622c5b9682 (diff) | |
download | vyos-cloud-init-6ed3c5dfcd9392784d2199224ac7d28d1abfdf7b.tar.gz vyos-cloud-init-6ed3c5dfcd9392784d2199224ac7d28d1abfdf7b.zip |
integration: do not LXD bind mount /etc/cloud/cloud.cfg.d (#1234)
Since lxc bind mounts will be read-only as nobody:nogroup
we don't want to bind mount /etc/cloud/cloud.cfg.d into the
instance because some tests add artifacts to /etc/cloud/cloud.cfg.d.
Also make LXD push_file pull_file methods assert that the
file transfer was a success, otherwise we miss the root-cause
for test failures.
This resulted in failed Jenkins runs in test_lxd_discovery with a
symptom of NoCloud being detected instead of LXD datasource.
The root-case was that instance.file_push failed due to permission
errors for root on the bind mounted /etc/cloud/cloud.cfg.d.
Also bump pycloudlib commitish to get Azure Jammy image support.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration_tests/clouds.py | 23 | ||||
-rw-r--r-- | tests/integration_tests/instances.py | 4 |
2 files changed, 19 insertions, 8 deletions
diff --git a/tests/integration_tests/clouds.py b/tests/integration_tests/clouds.py index 81d5b9a0..ef613339 100644 --- a/tests/integration_tests/clouds.py +++ b/tests/integration_tests/clouds.py @@ -134,7 +134,7 @@ class IntegrationCloud(ABC): user_data=None, launch_kwargs=None, settings=integration_settings, - **kwargs + **kwargs, ) -> IntegrationInstance: if launch_kwargs is None: launch_kwargs = {} @@ -259,10 +259,6 @@ class _LxdIntegrationCloud(IntegrationCloud): mounts = [ (cloudinit_path, "/usr/lib/python3/dist-packages/cloudinit"), ( - os.path.join(cloudinit_path, "..", "config", "cloud.cfg.d"), - "/etc/cloud/cloud.cfg.d", - ), - ( os.path.join(cloudinit_path, "..", "templates"), "/etc/cloud/templates", ), @@ -286,6 +282,21 @@ class _LxdIntegrationCloud(IntegrationCloud): ).format(**format_variables) subp(command.split()) + # /etc/cloud/cloud.cfg.d is a directory we write to in some + # integration tests. We can't use lxc mount in the container + # as /etc/cloud/cloud.cfg.d will then be owned nobody:nogroup and be + # read-only for root. + # Instead copy static files to the instance under test. + config_dir = os.path.join( + cloudinit_path, "..", "config", "cloud.cfg.d" + ) + for src_file in os.listdir(config_dir): + command = ( + f"lxc file push {config_dir}/{src_file} " + f"{instance.name}/etc/cloud/cloud.cfg.d/" + ) + subp(command.split()) + def _perform_launch(self, launch_kwargs, **kwargs): launch_kwargs["inst_type"] = launch_kwargs.pop("instance_type", None) wait = launch_kwargs.pop("wait", True) @@ -304,7 +315,7 @@ class _LxdIntegrationCloud(IntegrationCloud): launch_kwargs.pop("name", default_name), release, profile_list=profile_list, - **launch_kwargs + **launch_kwargs, ) if self.settings.CLOUD_INIT_SOURCE == "IN_PLACE": self._mount_source(pycloudlib_instance) diff --git a/tests/integration_tests/instances.py b/tests/integration_tests/instances.py index e3d597af..f30456fc 100644 --- a/tests/integration_tests/instances.py +++ b/tests/integration_tests/instances.py @@ -81,13 +81,13 @@ class IntegrationInstance: # First copy to a temporary directory because of permissions issues tmp_path = _get_tmp_path() self.instance.execute("cp {} {}".format(str(remote_path), tmp_path)) - self.instance.pull_file(tmp_path, str(local_path)) + assert self.instance.pull_file(tmp_path, str(local_path)).ok def push_file(self, local_path, remote_path): # First push to a temporary directory because of permissions issues tmp_path = _get_tmp_path() self.instance.push_file(str(local_path), tmp_path) - self.execute("mv {} {}".format(tmp_path, str(remote_path))) + assert self.execute("mv {} {}".format(tmp_path, str(remote_path))).ok def read_from_file(self, remote_path) -> str: result = self.execute("cat {}".format(remote_path)) |