Skip to content

Commit

Permalink
Drop use_sudo attribute on IntegrationInstance (#694)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lucasmoura committed Nov 26, 2020
1 parent 6ee0107 commit 53f2bfb
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions tests/integration_tests/instances.py
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -151,4 +146,4 @@ class IntegrationOciInstance(IntegrationInstance):


class IntegrationLxdInstance(IntegrationInstance):
use_sudo = False
pass

0 comments on commit 53f2bfb

Please sign in to comment.