sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #04469
[Merge] ~adam-collard/maas-ci/+git/system-tests:extract-install-deb into ~maas-committers/maas-ci/+git/system-tests:master
Adam Collard has proposed merging ~adam-collard/maas-ci/+git/system-tests:extract-install-deb into ~maas-committers/maas-ci/+git/system-tests:master.
Commit message:
Extract steps to install deb from maas_region fixture
Use container_name always
Requested reviews:
MAAS Committers (maas-committers)
For more details, see:
https://code.launchpad.net/~adam-collard/maas-ci/+git/system-tests/+merge/435672
--
Your team MAAS Committers is requested to review the proposed merge of ~adam-collard/maas-ci/+git/system-tests:extract-install-deb into ~maas-committers/maas-ci/+git/system-tests:master.
diff --git a/systemtests/fixtures.py b/systemtests/fixtures.py
index d528efb..3b3b045 100644
--- a/systemtests/fixtures.py
+++ b/systemtests/fixtures.py
@@ -2,9 +2,10 @@ from __future__ import annotations
import io
import os
+from functools import partial
from logging import StreamHandler, getLogger
from textwrap import dedent
-from typing import TYPE_CHECKING, Any, Iterator, Optional, TextIO
+from typing import TYPE_CHECKING, Any, Callable, Iterator, Optional, TextIO
import paramiko
import pytest
@@ -27,12 +28,13 @@ LOG_NAME = "systemtests.fixtures"
LXD_PROFILE = os.environ.get("MAAS_SYSTEMTESTS_LXD_PROFILE", "prof-maas-lab")
-def _add_maas_ppa(lxd: CLILXD, container: str, config: dict[str, Any]) -> None:
+def _add_maas_ppa(
+ exec_on_container: Callable[..., Any],
+ maas_ppas: list[str],
+) -> None:
"""Add MAAS PPA to the given container."""
- MAAS_PPA = config.get("deb", {}).get("ppa", ["ppa:maas-committers/latest-deps"])
- for ppa in MAAS_PPA:
- lxd.execute(
- container,
+ for ppa in maas_ppas:
+ exec_on_container(
["add-apt-repository", "-y", ppa],
environment={"DEBIAN_FRONTEND": "noninteractive"},
)
@@ -40,15 +42,13 @@ def _add_maas_ppa(lxd: CLILXD, container: str, config: dict[str, Any]) -> None:
@pytest.fixture(scope="session")
def build_container(config: dict[str, Any]) -> Iterator[str]:
- """Set up a new LXD container with postgres installed."""
+ """Create a container for building MAAS package in."""
log = getLogger(f"{LOG_NAME}.build_container")
lxd = get_lxd(log)
container_name = os.environ.get(
"MAAS_SYSTEMTESTS_BUILD_CONTAINER", "maas-system-build"
)
- if lxd.container_exists(container_name):
- container = container_name
- else:
+ if not lxd.container_exists(container_name):
cloud_config = {}
http_proxy = config.get("proxy", {}).get("http", "")
@@ -60,14 +60,14 @@ def build_container(config: dict[str, Any]) -> Iterator[str]:
}
user_data = "#cloud-config\n" + yaml.dump(cloud_config, default_style="|")
- container = lxd.create_container(
+ lxd.create_container(
container_name,
config["containers-image"],
user_data=user_data,
profile=LXD_PROFILE,
)
- yield container
+ yield container_name
@pytest.fixture(scope="session")
@@ -92,7 +92,11 @@ def maas_deb_repo(
proxy_env = None
if not lxd.file_exists(build_container, "/var/www/html/repo/Packages.gz"):
- _add_maas_ppa(lxd, build_container, config)
+ maas_ppas = config.get("deb", {}).get(
+ "ppa", ["ppa:maas-committers/latest-deps"]
+ )
+ exec_on_container = partial(lxd.execute, build_container)
+ _add_maas_ppa(exec_on_container, maas_ppas)
lxd.execute(
build_container,
[
@@ -192,9 +196,7 @@ def maas_container(config: dict[str, Any], build_container: str) -> str:
container_name = os.environ.get(
"MAAS_SYSTEMTESTS_MAAS_CONTAINER", "maas-system-maas"
)
- if lxd.container_exists(container_name):
- container = container_name
- else:
+ if not lxd.container_exists(container_name):
if not lxd.profile_exists(container_name):
lxd.copy_profile(LXD_PROFILE, container_name)
existing_maas_nics = [
@@ -246,7 +248,7 @@ def maas_container(config: dict[str, Any], build_container: str) -> str:
)
cloud_config["snap"]["commands"].insert(0, snap_proxy_cmd)
user_data = get_user_data(devices, cloud_config=cloud_config)
- container = lxd.create_container(
+ lxd.create_container(
container_name,
config["containers-image"],
user_data=user_data,
@@ -280,7 +282,7 @@ def maas_container(config: dict[str, Any], build_container: str) -> str:
container_name, contents, "/etc/apt/apt.conf.d/80maas-system-test"
)
- return container
+ return container_name
@pytest.fixture(scope="session")
@@ -366,6 +368,32 @@ def vault(maas_container: str, config: dict[str, Any]) -> Optional[Vault]:
return vault
+def install_deb(
+ lxd: CLILXD, maas_container: str, maas_deb_repo: str, config: dict[str, Any]
+) -> str:
+ on_maas_container = partial(lxd.execute, maas_container)
+ maas_ppas = config.get("deb", {}).get("ppa", ["ppa:maas-committers/latest-deps"])
+ lxd.push_text_file(
+ maas_container,
+ f"deb [trusted=yes] {maas_deb_repo} ./\n",
+ "/etc/apt/sources.list.d/maas.list",
+ )
+ _add_maas_ppa(on_maas_container, maas_ppas)
+ on_maas_container(
+ ["apt", "install", "--yes", "maas"],
+ environment={"DEBIAN_FRONTEND": "noninteractive"},
+ )
+ policy = on_maas_container(
+ ["apt-cache", "policy", "maas"],
+ environment={"DEBIAN_FRONTEND": "noninteractive"},
+ ) # just to record which version is running.
+ try:
+ version = policy.stdout.split("\n")[1].strip().split(" ")[1][2:]
+ except IndexError:
+ version = ""
+ return version
+
+
@pytest.fixture(scope="session")
def maas_region(
maas_container: str,
@@ -421,31 +449,11 @@ def maas_region(
],
)
else:
- lxd.push_text_file(
- maas_container,
- f"deb [trusted=yes] {maas_deb_repo} ./\n",
- "/etc/apt/sources.list.d/maas.list",
- )
- _add_maas_ppa(lxd, maas_container, config)
- lxd.execute(
- maas_container,
- ["apt", "update"],
- environment={"DEBIAN_FRONTEND": "noninteractive"},
- )
- lxd.execute(
- maas_container,
- ["apt", "install", "--yes", "maas"],
- environment={"DEBIAN_FRONTEND": "noninteractive"},
- )
- policy = lxd.execute(
- maas_container,
- ["apt-cache", "policy", "maas"],
- environment={"DEBIAN_FRONTEND": "noninteractive"},
- ) # just to record which version is running.
- try:
- version = policy.stdout.split("\n")[1].strip().split(" ")[1][2:]
- except IndexError:
- version = ""
+ # TODO: bind the LXD to the maas_container
+ assert maas_deb_repo is not None
+ version = install_deb(lxd, maas_container, maas_deb_repo, config)
+ with open("version_under_test", "w") as fh:
+ fh.write(f"{version}\n")
# We never want to access the region via the system proxy
if "no_proxy" not in os.environ:
@@ -485,9 +493,6 @@ def maas_region(
credentials["snap_channel"] = config["snap"]["maas_channel"]
yaml.dump(credentials, fh)
- with open("version_under_test", "w") as fh:
- fh.write(f"{version}\n")
-
if o11y := config.get("o11y"):
host_path_to_agent = o11y["grafana_agent_file_path"].strip()
agent_path = "/opt/agent/agent-linux-amd64"
Follow ups