Skip to content

Commit

Permalink
feat(integration_test): add CLOUD_INIT_PKG setting
Browse files Browse the repository at this point in the history
Add CLOUD_INIT_PKG to control what specific cloud-init package to
install when CLOUD_INIT_SOURCE is PROPOSED, UPGRADE or points to a ppa.

SC-1858
  • Loading branch information
aciba90 committed Sep 27, 2024
1 parent c62d7f2 commit b8eea6a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
50 changes: 34 additions & 16 deletions tests/integration_tests/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,16 @@ def install_new_cloud_init(
self,
source: CloudInitSource,
clean=True,
pkg: str = integration_settings.CLOUD_INIT_PKG,
):
if source == CloudInitSource.DEB_PACKAGE:
self.install_deb()
elif source == CloudInitSource.PPA:
self.install_ppa()
self.install_ppa(pkg)
elif source == CloudInitSource.PROPOSED:
self.install_proposed_image()
self.install_proposed_image(pkg)
elif source == CloudInitSource.UPGRADE:
self.upgrade_cloud_init()
self.upgrade_cloud_init(pkg)
else:
raise RuntimeError(
"Specified to install {} which isn't supported here".format(
Expand All @@ -201,20 +202,20 @@ def install_new_cloud_init(
if clean:
self.instance.clean()

def install_proposed_image(self):
log.info("Installing proposed image")
def install_proposed_image(self, pkg: str):
log.info("Installing %s from -proposed", pkg)
assert self.execute(
'echo deb "http://archive.ubuntu.com/ubuntu '
'$(lsb_release -sc)-proposed main" >> '
"/etc/apt/sources.list.d/proposed.list"
).ok
self._apt_update()
assert self.execute(
"apt-get install -qy cloud-init -t=$(lsb_release -sc)-proposed"
f"apt-get install -qy {pkg} -t=$(lsb_release -sc)-proposed"
).ok

def install_ppa(self):
log.info("Installing PPA")
def install_ppa(self, pkg: str):
log.info("Installing %s from PPA", pkg)
if self.execute("which add-apt-repository").failed:
log.info("Installing missing software-properties-common package")
self._apt_update()
Expand All @@ -223,18 +224,35 @@ def install_ppa(self):
).ok
pin_origin = self.settings.CLOUD_INIT_SOURCE[4:] # Drop leading ppa:
pin_origin = re.sub("[^a-z0-9-]", "-", pin_origin)
preferences = f"""\
package: cloud-init
Pin: release o=LP-PPA-{pin_origin}
Pin-Priority: 1001
package: cloud-init-base
Pin: release o=LP-PPA-{pin_origin}
Pin-Priority: 1001
package: cloud-init-cloud-sigma
Pin: release o=LP-PPA-{pin_origin}
Pin-Priority: 1001
package: cloud-init-smart-os
Pin: release o=LP-PPA-{pin_origin}
Pin-Priority: 1001"""
self.write_to_file(
"/etc/apt/preferences.d/cloud-init-integration-testing",
f"package: cloud-init\nPin: release o=LP-PPA-{pin_origin}\n"
"Pin-Priority: 1001\n",
preferences,
)
assert self.execute(
"add-apt-repository {} -y".format(self.settings.CLOUD_INIT_SOURCE)
).ok
# PIN this PPA as priority for cloud-init installs regardless of ver
assert self.execute(
"apt-get install -qy cloud-init --allow-downgrades"
).ok
r = self.execute(
f"DEBIAN_FRONTEND=noninteractive"
f" apt-get install -qy {pkg} --allow-downgrades"
)
assert r.ok, r.stderr

@retry(tries=30, delay=1)
def install_deb(self):
Expand All @@ -255,10 +273,10 @@ def install_deb(self):
).ok

@retry(tries=30, delay=1)
def upgrade_cloud_init(self):
log.info("Upgrading cloud-init to latest version in archive")
def upgrade_cloud_init(self, pkg: str):
log.info("Upgrading %s to latest version in archive", pkg)
self._apt_update()
assert self.execute("apt-get install -qy cloud-init").ok
assert self.execute(f"apt-get install -qy {pkg}").ok

def _apt_update(self):
"""Run an apt update.
Expand Down
4 changes: 4 additions & 0 deletions tests/integration_tests/integration_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
# A path to a valid package to be uploaded and installed
CLOUD_INIT_SOURCE = "NONE"

# cloud-init metapackage to install
# Examples: cloud-init, cloud-init-base, cloud-init-smart-os
CLOUD_INIT_PKG = "cloud-init"

# Before an instance is torn down, we run `cloud-init collect-logs`
# and transfer them locally. These settings specify when to collect these
# logs and where to put them on the local filesystem
Expand Down

0 comments on commit b8eea6a

Please sign in to comment.