Merge ~adam-collard/maas-ci/+git/system-tests:extract-install-deb into ~maas-committers/maas-ci/+git/system-tests:master

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: 3f1ead95b712a105039638dbe33a09d15eada4d6
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas-ci/+git/system-tests:extract-install-deb
Merge into: ~maas-committers/maas-ci/+git/system-tests:master
Diff against target: 192 lines (+51/-46)
1 file modified
systemtests/fixtures.py (+51/-46)
Reviewer Review Type Date Requested Status
Christian Grabowski Approve
MAAS Lander Approve
Review via email: mp+435672@code.launchpad.net

Commit message

Extract steps to install deb from maas_region fixture

Use container_name always

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b extract-install-deb lp:~adam-collard/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: SUCCESS
COMMIT: 3f1ead95b712a105039638dbe33a09d15eada4d6

review: Approve
Revision history for this message
Christian Grabowski (cgrabowski) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/systemtests/fixtures.py b/systemtests/fixtures.py
2index d528efb..3b3b045 100644
3--- a/systemtests/fixtures.py
4+++ b/systemtests/fixtures.py
5@@ -2,9 +2,10 @@ from __future__ import annotations
6
7 import io
8 import os
9+from functools import partial
10 from logging import StreamHandler, getLogger
11 from textwrap import dedent
12-from typing import TYPE_CHECKING, Any, Iterator, Optional, TextIO
13+from typing import TYPE_CHECKING, Any, Callable, Iterator, Optional, TextIO
14
15 import paramiko
16 import pytest
17@@ -27,12 +28,13 @@ LOG_NAME = "systemtests.fixtures"
18 LXD_PROFILE = os.environ.get("MAAS_SYSTEMTESTS_LXD_PROFILE", "prof-maas-lab")
19
20
21-def _add_maas_ppa(lxd: CLILXD, container: str, config: dict[str, Any]) -> None:
22+def _add_maas_ppa(
23+ exec_on_container: Callable[..., Any],
24+ maas_ppas: list[str],
25+) -> None:
26 """Add MAAS PPA to the given container."""
27- MAAS_PPA = config.get("deb", {}).get("ppa", ["ppa:maas-committers/latest-deps"])
28- for ppa in MAAS_PPA:
29- lxd.execute(
30- container,
31+ for ppa in maas_ppas:
32+ exec_on_container(
33 ["add-apt-repository", "-y", ppa],
34 environment={"DEBIAN_FRONTEND": "noninteractive"},
35 )
36@@ -40,15 +42,13 @@ def _add_maas_ppa(lxd: CLILXD, container: str, config: dict[str, Any]) -> None:
37
38 @pytest.fixture(scope="session")
39 def build_container(config: dict[str, Any]) -> Iterator[str]:
40- """Set up a new LXD container with postgres installed."""
41+ """Create a container for building MAAS package in."""
42 log = getLogger(f"{LOG_NAME}.build_container")
43 lxd = get_lxd(log)
44 container_name = os.environ.get(
45 "MAAS_SYSTEMTESTS_BUILD_CONTAINER", "maas-system-build"
46 )
47- if lxd.container_exists(container_name):
48- container = container_name
49- else:
50+ if not lxd.container_exists(container_name):
51 cloud_config = {}
52
53 http_proxy = config.get("proxy", {}).get("http", "")
54@@ -60,14 +60,14 @@ def build_container(config: dict[str, Any]) -> Iterator[str]:
55 }
56
57 user_data = "#cloud-config\n" + yaml.dump(cloud_config, default_style="|")
58- container = lxd.create_container(
59+ lxd.create_container(
60 container_name,
61 config["containers-image"],
62 user_data=user_data,
63 profile=LXD_PROFILE,
64 )
65
66- yield container
67+ yield container_name
68
69
70 @pytest.fixture(scope="session")
71@@ -92,7 +92,11 @@ def maas_deb_repo(
72 proxy_env = None
73
74 if not lxd.file_exists(build_container, "/var/www/html/repo/Packages.gz"):
75- _add_maas_ppa(lxd, build_container, config)
76+ maas_ppas = config.get("deb", {}).get(
77+ "ppa", ["ppa:maas-committers/latest-deps"]
78+ )
79+ exec_on_container = partial(lxd.execute, build_container)
80+ _add_maas_ppa(exec_on_container, maas_ppas)
81 lxd.execute(
82 build_container,
83 [
84@@ -192,9 +196,7 @@ def maas_container(config: dict[str, Any], build_container: str) -> str:
85 container_name = os.environ.get(
86 "MAAS_SYSTEMTESTS_MAAS_CONTAINER", "maas-system-maas"
87 )
88- if lxd.container_exists(container_name):
89- container = container_name
90- else:
91+ if not lxd.container_exists(container_name):
92 if not lxd.profile_exists(container_name):
93 lxd.copy_profile(LXD_PROFILE, container_name)
94 existing_maas_nics = [
95@@ -246,7 +248,7 @@ def maas_container(config: dict[str, Any], build_container: str) -> str:
96 )
97 cloud_config["snap"]["commands"].insert(0, snap_proxy_cmd)
98 user_data = get_user_data(devices, cloud_config=cloud_config)
99- container = lxd.create_container(
100+ lxd.create_container(
101 container_name,
102 config["containers-image"],
103 user_data=user_data,
104@@ -280,7 +282,7 @@ def maas_container(config: dict[str, Any], build_container: str) -> str:
105 container_name, contents, "/etc/apt/apt.conf.d/80maas-system-test"
106 )
107
108- return container
109+ return container_name
110
111
112 @pytest.fixture(scope="session")
113@@ -366,6 +368,32 @@ def vault(maas_container: str, config: dict[str, Any]) -> Optional[Vault]:
114 return vault
115
116
117+def install_deb(
118+ lxd: CLILXD, maas_container: str, maas_deb_repo: str, config: dict[str, Any]
119+) -> str:
120+ on_maas_container = partial(lxd.execute, maas_container)
121+ maas_ppas = config.get("deb", {}).get("ppa", ["ppa:maas-committers/latest-deps"])
122+ lxd.push_text_file(
123+ maas_container,
124+ f"deb [trusted=yes] {maas_deb_repo} ./\n",
125+ "/etc/apt/sources.list.d/maas.list",
126+ )
127+ _add_maas_ppa(on_maas_container, maas_ppas)
128+ on_maas_container(
129+ ["apt", "install", "--yes", "maas"],
130+ environment={"DEBIAN_FRONTEND": "noninteractive"},
131+ )
132+ policy = on_maas_container(
133+ ["apt-cache", "policy", "maas"],
134+ environment={"DEBIAN_FRONTEND": "noninteractive"},
135+ ) # just to record which version is running.
136+ try:
137+ version = policy.stdout.split("\n")[1].strip().split(" ")[1][2:]
138+ except IndexError:
139+ version = ""
140+ return version
141+
142+
143 @pytest.fixture(scope="session")
144 def maas_region(
145 maas_container: str,
146@@ -421,31 +449,11 @@ def maas_region(
147 ],
148 )
149 else:
150- lxd.push_text_file(
151- maas_container,
152- f"deb [trusted=yes] {maas_deb_repo} ./\n",
153- "/etc/apt/sources.list.d/maas.list",
154- )
155- _add_maas_ppa(lxd, maas_container, config)
156- lxd.execute(
157- maas_container,
158- ["apt", "update"],
159- environment={"DEBIAN_FRONTEND": "noninteractive"},
160- )
161- lxd.execute(
162- maas_container,
163- ["apt", "install", "--yes", "maas"],
164- environment={"DEBIAN_FRONTEND": "noninteractive"},
165- )
166- policy = lxd.execute(
167- maas_container,
168- ["apt-cache", "policy", "maas"],
169- environment={"DEBIAN_FRONTEND": "noninteractive"},
170- ) # just to record which version is running.
171- try:
172- version = policy.stdout.split("\n")[1].strip().split(" ")[1][2:]
173- except IndexError:
174- version = ""
175+ # TODO: bind the LXD to the maas_container
176+ assert maas_deb_repo is not None
177+ version = install_deb(lxd, maas_container, maas_deb_repo, config)
178+ with open("version_under_test", "w") as fh:
179+ fh.write(f"{version}\n")
180
181 # We never want to access the region via the system proxy
182 if "no_proxy" not in os.environ:
183@@ -485,9 +493,6 @@ def maas_region(
184 credentials["snap_channel"] = config["snap"]["maas_channel"]
185 yaml.dump(credentials, fh)
186
187- with open("version_under_test", "w") as fh:
188- fh.write(f"{version}\n")
189-
190 if o11y := config.get("o11y"):
191 host_path_to_agent = o11y["grafana_agent_file_path"].strip()
192 agent_path = "/opt/agent/agent-linux-amd64"

Subscribers

People subscribed via source and target branches

to all changes: