Merge ~adam-collard/maas:3.1-relax-custom-image-validation into maas:3.1

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: faa15ce62428ef64a79fe99bfcd759619ce23175
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas:3.1-relax-custom-image-validation
Merge into: maas:3.1
Diff against target: 231 lines (+95/-57)
2 files modified
src/maasserver/preseed.py (+28/-27)
src/maasserver/tests/test_preseed.py (+67/-30)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
Adam Collard (community) Approve
Review via email: mp+425737@code.launchpad.net

Commit message

LP:1978154: Don't require netplan for custom CentOS images

We erroneously checked custom CentOS images for netplan, remove that.

Switch to using `rpm -q` for package installation (a more reaonable
translation of `dpkq-query -s`)

Validate RHEL based custom images too.

(cherry picked from commit 9877850af9d3ba9d281b5de9518c9997d0d25dc9 )

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) wrote :

self-approve backport

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 3.1-relax-custom-image-validation lp:~adam-collard/maas/+git/maas into -b 3.1 lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/13091/console
COMMIT: aa80d2c2ad01d91b4b9052758e938559e36ae9d7

review: Needs Fixing
faa15ce... by Adam Collard

Fix use of undefined LINUX_OSYSTEMS

Signed-off-by: Adam Collard <email address hidden>

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 3.1-relax-custom-image-validation lp:~adam-collard/maas/+git/maas into -b 3.1 lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/13092/console
COMMIT: b2a26962d2cec71bfc178b46322558d33d344870

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 3.1-relax-custom-image-validation lp:~adam-collard/maas/+git/maas into -b 3.1 lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/13094/console
COMMIT: faa15ce62428ef64a79fe99bfcd759619ce23175

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/preseed.py b/src/maasserver/preseed.py
2index 4ea3beb..90102aa 100644
3--- a/src/maasserver/preseed.py
4+++ b/src/maasserver/preseed.py
5@@ -7,8 +7,10 @@ from collections import namedtuple
6 import json
7 import os.path
8 from pipes import quote
9+import typing
10 from urllib.parse import urlencode, urlparse
11
12+import attr
13 from crochet import TimeoutError
14 from curtin.config import merge_config
15 from curtin.pack import pack_install
16@@ -595,6 +597,20 @@ def get_curtin_config(request, node, base_osystem=None, base_series=None):
17 return yaml.safe_dump(config)
18
19
20+@attr.s(auto_attribs=True)
21+class PackageManager:
22+
23+ package_tool: str
24+ deps: typing.List[str]
25+
26+
27+PACKAGE_MANAGER_PER_OS = {
28+ "ubuntu": PackageManager("dpkg-query -s", ["cloud-init", "netplan.io"]),
29+ "centos": PackageManager("rpm -q", ["cloud-init"]),
30+ "rhel": PackageManager("rpm -q", ["cloud-init"]),
31+}
32+
33+
34 def get_custom_image_dependency_validation(node, base_osystem):
35 if node.get_osystem() != "custom":
36 return None
37@@ -602,33 +618,18 @@ def get_custom_image_dependency_validation(node, base_osystem):
38 cmd = {}
39 err_msg = "not detected, MAAS will not be able to configure this machine properly"
40
41- deps = ["cloud-init", "netplan.io"]
42- for i, dep in enumerate(deps):
43- in_target = None
44- if base_osystem == "ubuntu":
45- in_target = 'dpkg-query -s {dep} || (echo "{dep} {err_msg}" && exit 1)'.format(
46- dep=dep, err_msg=err_msg
47- )
48- if base_osystem == "centos":
49- in_target = (
50- 'dnf list {dep} || (echo "{dep} {err_msg}" && exit 1)'.format(
51- dep=dep, err_msg=err_msg
52- )
53- )
54-
55- if in_target is not None:
56- cmd[
57- "{priority}-validate-custom-image-has-{dep}".format(
58- priority=98 + i, dep=dep
59- )
60- ] = [
61- "curtin",
62- "in-target",
63- "--",
64- "bash",
65- "-c",
66- in_target,
67- ]
68+ package_manager = PACKAGE_MANAGER_PER_OS[base_osystem]
69+
70+ for priority, dep in enumerate(package_manager.deps, start=98):
71+ in_target = f'{package_manager.package_tool} {dep} || (echo "{dep} {err_msg}" && exit 1)'
72+ cmd[f"{priority}-validate-custom-image-has-{dep}"] = [
73+ "curtin",
74+ "in-target",
75+ "--",
76+ "bash",
77+ "-c",
78+ in_target,
79+ ]
80 return cmd
81
82
83diff --git a/src/maasserver/tests/test_preseed.py b/src/maasserver/tests/test_preseed.py
84index 6239aaf..2ddca2f 100644
85--- a/src/maasserver/tests/test_preseed.py
86+++ b/src/maasserver/tests/test_preseed.py
87@@ -322,20 +322,20 @@ class TestGetPreseedTemplate(MAASServerTestCase):
88 class TestGetCustomImageDependencyValidation(MAASServerTestCase):
89 """Tests for 'get_custom_image_dependency_validation"""
90
91- def test_get_custom_image_dependency_validation_for_custom_ubuntu(self):
92+ def test_validation_for_custom_ubuntu(self):
93+ distro_series = factory.make_name("ubuntu")
94 boot_resource = factory.make_BootResource(
95- name="custom/%s" % factory.make_name("ubuntu"),
96+ name=f"custom/{distro_series}",
97 base_image="ubuntu/focal",
98 architecture="amd64/generic",
99 )
100- base_osystem, _ = boot_resource.split_base_image()
101- machine = factory.make_Machine(status=NODE_STATUS.DEPLOYED)
102- machine.osystem, machine.distro_series = boot_resource.name.split("/")
103- machine.architecture = boot_resource.architecture
104- machine.save()
105- validation = get_custom_image_dependency_validation(
106- machine, base_osystem
107+ machine = factory.make_Machine(
108+ status=NODE_STATUS.DEPLOYED,
109+ architecture=boot_resource.architecture,
110+ osystem="custom",
111+ distro_series=distro_series,
112 )
113+ validation = get_custom_image_dependency_validation(machine, "ubuntu")
114 expected = {
115 "98-validate-custom-image-has-cloud-init": [
116 "curtin",
117@@ -354,23 +354,22 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
118 'dpkg-query -s netplan.io || (echo "netplan.io not detected, MAAS will not be able to configure this machine properly" && exit 1)',
119 ],
120 }
121- for k in expected:
122- self.assertCountEqual(validation[k], expected[k])
123+ self.assertEqual(validation, expected)
124
125- def test_get_custom_image_dependency_validation_for_custom_centos(self):
126+ def test_validation_for_custom_centos(self):
127+ distro_series = factory.make_name("centos7")
128 boot_resource = factory.make_BootResource(
129- name="custom/%s" % factory.make_name("centos7"),
130+ name=f"custom/{distro_series}",
131 base_image="centos/centos7",
132 architecture="amd64/generic",
133 )
134- base_osystem, _ = boot_resource.split_base_image()
135- machine = factory.make_Machine(status=NODE_STATUS.DEPLOYED)
136- machine.osystem, machine.distro_series = boot_resource.name.split("/")
137- machine.architecture = boot_resource.architecture
138- machine.save()
139- validation = get_custom_image_dependency_validation(
140- machine, base_osystem
141+ machine = factory.make_Machine(
142+ status=NODE_STATUS.DEPLOYED,
143+ architecture=boot_resource.architecture,
144+ osystem="custom",
145+ distro_series=distro_series,
146 )
147+ validation = get_custom_image_dependency_validation(machine, "centos")
148 expected = {
149 "98-validate-custom-image-has-cloud-init": [
150 "curtin",
151@@ -378,32 +377,70 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
152 "--",
153 "bash",
154 "-c",
155- 'dnf list cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
156+ 'rpm -q cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
157 ],
158- "99-validate-custom-image-has-netplan.io": [
159+ }
160+ self.assertEqual(validation, expected)
161+
162+ def test_validation_for_custom_rhel(self):
163+ distro_series = factory.make_name("rhel8")
164+ boot_resource = factory.make_BootResource(
165+ name=f"custom/{distro_series}",
166+ base_image="rhel/rhel8",
167+ architecture="amd64/generic",
168+ )
169+ machine = factory.make_Machine(
170+ status=NODE_STATUS.DEPLOYED,
171+ architecture=boot_resource.architecture,
172+ osystem="custom",
173+ distro_series=distro_series,
174+ )
175+ validation = get_custom_image_dependency_validation(machine, "rhel")
176+ expected = {
177+ "98-validate-custom-image-has-cloud-init": [
178 "curtin",
179 "in-target",
180 "--",
181 "bash",
182 "-c",
183- 'dnf list netplan.io || (echo "netplan.io not detected, MAAS will not be able to configure this machine properly" && exit 1)',
184+ 'rpm -q cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
185 ],
186 }
187- for k in expected:
188- self.assertCountEqual(validation[k], expected[k])
189+ self.assertEqual(validation, expected)
190
191- def test_get_custom_image_dependency_validation_for_non_custom(self):
192+ def test_validation_for_non_custom(self):
193 boot_resource = factory.make_BootResource(
194 name="ubuntu/focal", architecture="amd64/generic"
195 )
196- machine = factory.make_Machine(status=NODE_STATUS.DEPLOYED)
197- machine.osystem, machine.distro_series = boot_resource.name.split("/")
198- machine.architecture = boot_resource.architecture
199- machine.save()
200+ machine = factory.make_Machine(
201+ status=NODE_STATUS.DEPLOYED,
202+ architecture=boot_resource.architecture,
203+ osystem="ubuntu",
204+ distro_series="focal",
205+ )
206 self.assertIsNone(
207 get_custom_image_dependency_validation(machine, boot_resource.name)
208 )
209
210+ def test_validation_for_linuxes(self):
211+ machine = factory.make_Machine(
212+ status=NODE_STATUS.DEPLOYED,
213+ architecture="amd64/generic",
214+ osystem="custom",
215+ )
216+ for osystem in ("ubuntu", "centos", "rhel"):
217+ distro_series = factory.make_name(osystem)
218+ factory.make_BootResource(
219+ name=f"custom/{distro_series}",
220+ base_image=f"{osystem}/{osystem}",
221+ architecture="amd64/generic",
222+ )
223+ machine.distro_series = distro_series
224+ machine.save()
225+ self.assertIsNotNone(
226+ get_custom_image_dependency_validation(machine, osystem)
227+ )
228+
229
230 class TestLoadPreseedTemplate(MAASServerTestCase):
231 """Tests for `load_preseed_template`."""

Subscribers

People subscribed via source and target branches