From 1712c82a47ec49019d633eb866fec4a1df94b0a5 Mon Sep 17 00:00:00 2001 From: Lucas Moura Date: Thu, 26 Nov 2020 18:26:50 -0300 Subject: [PATCH] Drop use_sudo attribute on IntegrationInstance pycloudlib will stop running commands as root by default on LXD. To align with that change and make the behavior consistent with other clouds we support, our LXD instances will now run the commands with sudo by default. --- tests/integration_tests/instances.py | 29 ++++++++++++---------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tests/integration_tests/instances.py b/tests/integration_tests/instances.py index a0a5fb6b118..033847b807d 100644 --- a/tests/integration_tests/instances.py +++ b/tests/integration_tests/instances.py @@ -26,8 +26,6 @@ def _get_tmp_path(): class IntegrationInstance: - use_sudo = True - def __init__(self, cloud: 'IntegrationCloud', instance: BaseInstance, settings=integration_settings): self.cloud = cloud @@ -37,11 +35,9 @@ def __init__(self, cloud: 'IntegrationCloud', instance: BaseInstance, def destroy(self): self.instance.delete() - def execute(self, command, *, use_sudo=None) -> Result: + def execute(self, command, *, use_sudo=True) -> Result: if self.instance.username == 'root' and use_sudo is False: raise Exception('Root user cannot run unprivileged') - if use_sudo is None: - use_sudo = self.use_sudo return self.instance.execute(command, use_sudo=use_sudo) def pull_file(self, remote_path, local_path): @@ -97,21 +93,21 @@ def _install_new_cloud_init(self, remote_script): def install_proposed_image(self): log.info('Installing proposed image') remote_script = ( - '{sudo} echo deb "http://archive.ubuntu.com/ubuntu ' + 'echo deb "http://archive.ubuntu.com/ubuntu ' '$(lsb_release -sc)-proposed main" | ' - '{sudo} tee /etc/apt/sources.list.d/proposed.list\n' - '{sudo} apt-get update -q\n' - '{sudo} apt-get install -qy cloud-init' - ).format(sudo='sudo' if self.use_sudo else '') + 'tee /etc/apt/sources.list.d/proposed.list\n' + 'apt-get update -q\n' + 'apt-get install -qy cloud-init' + ) self._install_new_cloud_init(remote_script) def install_ppa(self, repo): log.info('Installing PPA') remote_script = ( - '{sudo} add-apt-repository {repo} -y && ' - '{sudo} apt-get update -q && ' - '{sudo} apt-get install -qy cloud-init' - ).format(sudo='sudo' if self.use_sudo else '', repo=repo) + 'add-apt-repository {repo} -y && ' + 'apt-get update -q && ' + 'apt-get install -qy cloud-init' + ).format(repo=repo) self._install_new_cloud_init(remote_script) def install_deb(self): @@ -122,8 +118,7 @@ def install_deb(self): self.push_file( local_path=integration_settings.CLOUD_INIT_SOURCE, remote_path=remote_path) - remote_script = '{sudo} dpkg -i {path}'.format( - sudo='sudo' if self.use_sudo else '', path=remote_path) + remote_script = 'dpkg -i {path}'.format(path=remote_path) self._install_new_cloud_init(remote_script) def __enter__(self): @@ -151,4 +146,4 @@ class IntegrationOciInstance(IntegrationInstance): class IntegrationLxdInstance(IntegrationInstance): - use_sudo = False + pass