Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests to run commands on LXD as non root #694

Merged
merged 1 commit into from Nov 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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