Merge ~adam-collard/maas:3.2-backport-2020397-custom-validation into maas:3.2

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: 307a72b30b3181d3289430c1e9309f33780d07f9
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas:3.2-backport-2020397-custom-validation
Merge into: maas:3.2
Diff against target: 118 lines (+21/-24)
2 files modified
src/maasserver/preseed.py (+13/-16)
src/maasserver/tests/test_preseed.py (+8/-8)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
MAAS Maintainers Pending
Review via email: mp+447329@code.launchpad.net

Commit message

[3.2] LP:2020397: Look for executables for cloud-init and netplan

Instead of using package managers, look for executables

Backport efcd6c71914a3773fa6315133c89b9b00bdb89e4

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

UNIT TESTS
-b 3.2-backport-2020397-custom-validation lp:~adam-collard/maas/+git/maas into -b 3.2 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 307a72b30b3181d3289430c1e9309f33780d07f9

review: Approve

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 c692969..0387a99 100644
3--- a/src/maasserver/preseed.py
4+++ b/src/maasserver/preseed.py
5@@ -7,10 +7,8 @@ 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@@ -605,17 +603,14 @@ 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+_CLOUD_INIT = ["cloud-init", "--version"]
23+_NETPLAN = ["netplan", "info"]
24
25- package_tool: str
26- deps: typing.List[str]
27-
28-
29-PACKAGE_MANAGER_PER_OS = {
30- "ubuntu": PackageManager("dpkg-query -s", ["cloud-init", "netplan.io"]),
31- "centos": PackageManager("rpm -q", ["cloud-init"]),
32- "rhel": PackageManager("rpm -q", ["cloud-init"]),
33+DEPS_PER_OS = {
34+ "ubuntu": (_CLOUD_INIT, _NETPLAN),
35+ "centos": (_CLOUD_INIT,),
36+ "rhel": (_CLOUD_INIT,),
37+ "suse": (_CLOUD_INIT,),
38 }
39
40
41@@ -626,11 +621,13 @@ def get_custom_image_dependency_validation(node, base_osystem):
42 cmd = {}
43 err_msg = "not detected, MAAS will not be able to configure this machine properly"
44
45- package_manager = PACKAGE_MANAGER_PER_OS[base_osystem]
46+ deps = DEPS_PER_OS[base_osystem]
47
48- for priority, dep in enumerate(package_manager.deps, start=98):
49- in_target = f'{package_manager.package_tool} {dep} || (echo "{dep} {err_msg}" && exit 1)'
50- cmd[f"{priority}-validate-custom-image-has-{dep}"] = [
51+ for priority, dep_cmds in enumerate(deps, start=98):
52+ name = dep_cmds[0]
53+ executable = " ".join(dep_cmds)
54+ in_target = f'{executable} || (echo "{name} {err_msg}" && exit 1)'
55+ cmd[f"{priority}-validate-custom-image-has-{name}"] = [
56 "curtin",
57 "in-target",
58 "--",
59diff --git a/src/maasserver/tests/test_preseed.py b/src/maasserver/tests/test_preseed.py
60index 95e7a91..1d211ca 100644
61--- a/src/maasserver/tests/test_preseed.py
62+++ b/src/maasserver/tests/test_preseed.py
63@@ -345,15 +345,15 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
64 "--",
65 "bash",
66 "-c",
67- 'dpkg-query -s cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
68+ 'cloud-init --version || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
69 ],
70- "99-validate-custom-image-has-netplan.io": [
71+ "99-validate-custom-image-has-netplan": [
72 "curtin",
73 "in-target",
74 "--",
75 "bash",
76 "-c",
77- 'dpkg-query -s netplan.io || (echo "netplan.io not detected, MAAS will not be able to configure this machine properly" && exit 1)',
78+ 'netplan info || (echo "netplan not detected, MAAS will not be able to configure this machine properly" && exit 1)',
79 ],
80 }
81 self.assertEqual(validation, expected)
82@@ -379,7 +379,7 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
83 "--",
84 "bash",
85 "-c",
86- 'rpm -q cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
87+ 'cloud-init --version || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
88 ],
89 }
90 self.assertEqual(validation, expected)
91@@ -405,7 +405,7 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
92 "--",
93 "bash",
94 "-c",
95- 'rpm -q cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
96+ 'cloud-init --version || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
97 ],
98 }
99 self.assertEqual(validation, expected)
100@@ -1588,15 +1588,15 @@ class TestCurtinUtilities(
101 "--",
102 "bash",
103 "-c",
104- 'dpkg-query -s cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
105+ 'cloud-init --version || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
106 ],
107- "99-validate-custom-image-has-netplan.io": [
108+ "99-validate-custom-image-has-netplan": [
109 "curtin",
110 "in-target",
111 "--",
112 "bash",
113 "-c",
114- 'dpkg-query -s netplan.io || (echo "netplan.io not detected, MAAS will not be able to configure this machine properly" && exit 1)',
115+ 'netplan info || (echo "netplan not detected, MAAS will not be able to configure this machine properly" && exit 1)',
116 ],
117 }
118 self.configure_get_boot_images_for_node(node, "xinstall")

Subscribers

People subscribed via source and target branches