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
diff --git a/src/maasserver/preseed.py b/src/maasserver/preseed.py
index 4ea3beb..90102aa 100644
--- a/src/maasserver/preseed.py
+++ b/src/maasserver/preseed.py
@@ -7,8 +7,10 @@ from collections import namedtuple
7import json7import json
8import os.path8import os.path
9from pipes import quote9from pipes import quote
10import typing
10from urllib.parse import urlencode, urlparse11from urllib.parse import urlencode, urlparse
1112
13import attr
12from crochet import TimeoutError14from crochet import TimeoutError
13from curtin.config import merge_config15from curtin.config import merge_config
14from curtin.pack import pack_install16from curtin.pack import pack_install
@@ -595,6 +597,20 @@ def get_curtin_config(request, node, base_osystem=None, base_series=None):
595 return yaml.safe_dump(config)597 return yaml.safe_dump(config)
596598
597599
600@attr.s(auto_attribs=True)
601class PackageManager:
602
603 package_tool: str
604 deps: typing.List[str]
605
606
607PACKAGE_MANAGER_PER_OS = {
608 "ubuntu": PackageManager("dpkg-query -s", ["cloud-init", "netplan.io"]),
609 "centos": PackageManager("rpm -q", ["cloud-init"]),
610 "rhel": PackageManager("rpm -q", ["cloud-init"]),
611}
612
613
598def get_custom_image_dependency_validation(node, base_osystem):614def get_custom_image_dependency_validation(node, base_osystem):
599 if node.get_osystem() != "custom":615 if node.get_osystem() != "custom":
600 return None616 return None
@@ -602,33 +618,18 @@ def get_custom_image_dependency_validation(node, base_osystem):
602 cmd = {}618 cmd = {}
603 err_msg = "not detected, MAAS will not be able to configure this machine properly"619 err_msg = "not detected, MAAS will not be able to configure this machine properly"
604620
605 deps = ["cloud-init", "netplan.io"]621 package_manager = PACKAGE_MANAGER_PER_OS[base_osystem]
606 for i, dep in enumerate(deps):622
607 in_target = None623 for priority, dep in enumerate(package_manager.deps, start=98):
608 if base_osystem == "ubuntu":624 in_target = f'{package_manager.package_tool} {dep} || (echo "{dep} {err_msg}" && exit 1)'
609 in_target = 'dpkg-query -s {dep} || (echo "{dep} {err_msg}" && exit 1)'.format(625 cmd[f"{priority}-validate-custom-image-has-{dep}"] = [
610 dep=dep, err_msg=err_msg626 "curtin",
611 )627 "in-target",
612 if base_osystem == "centos":628 "--",
613 in_target = (629 "bash",
614 'dnf list {dep} || (echo "{dep} {err_msg}" && exit 1)'.format(630 "-c",
615 dep=dep, err_msg=err_msg631 in_target,
616 )632 ]
617 )
618
619 if in_target is not None:
620 cmd[
621 "{priority}-validate-custom-image-has-{dep}".format(
622 priority=98 + i, dep=dep
623 )
624 ] = [
625 "curtin",
626 "in-target",
627 "--",
628 "bash",
629 "-c",
630 in_target,
631 ]
632 return cmd633 return cmd
633634
634635
diff --git a/src/maasserver/tests/test_preseed.py b/src/maasserver/tests/test_preseed.py
index 6239aaf..2ddca2f 100644
--- a/src/maasserver/tests/test_preseed.py
+++ b/src/maasserver/tests/test_preseed.py
@@ -322,20 +322,20 @@ class TestGetPreseedTemplate(MAASServerTestCase):
322class TestGetCustomImageDependencyValidation(MAASServerTestCase):322class TestGetCustomImageDependencyValidation(MAASServerTestCase):
323 """Tests for 'get_custom_image_dependency_validation"""323 """Tests for 'get_custom_image_dependency_validation"""
324324
325 def test_get_custom_image_dependency_validation_for_custom_ubuntu(self):325 def test_validation_for_custom_ubuntu(self):
326 distro_series = factory.make_name("ubuntu")
326 boot_resource = factory.make_BootResource(327 boot_resource = factory.make_BootResource(
327 name="custom/%s" % factory.make_name("ubuntu"),328 name=f"custom/{distro_series}",
328 base_image="ubuntu/focal",329 base_image="ubuntu/focal",
329 architecture="amd64/generic",330 architecture="amd64/generic",
330 )331 )
331 base_osystem, _ = boot_resource.split_base_image()332 machine = factory.make_Machine(
332 machine = factory.make_Machine(status=NODE_STATUS.DEPLOYED)333 status=NODE_STATUS.DEPLOYED,
333 machine.osystem, machine.distro_series = boot_resource.name.split("/")334 architecture=boot_resource.architecture,
334 machine.architecture = boot_resource.architecture335 osystem="custom",
335 machine.save()336 distro_series=distro_series,
336 validation = get_custom_image_dependency_validation(
337 machine, base_osystem
338 )337 )
338 validation = get_custom_image_dependency_validation(machine, "ubuntu")
339 expected = {339 expected = {
340 "98-validate-custom-image-has-cloud-init": [340 "98-validate-custom-image-has-cloud-init": [
341 "curtin",341 "curtin",
@@ -354,23 +354,22 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
354 'dpkg-query -s netplan.io || (echo "netplan.io not detected, MAAS will not be able to configure this machine properly" && exit 1)',354 'dpkg-query -s netplan.io || (echo "netplan.io not detected, MAAS will not be able to configure this machine properly" && exit 1)',
355 ],355 ],
356 }356 }
357 for k in expected:357 self.assertEqual(validation, expected)
358 self.assertCountEqual(validation[k], expected[k])
359358
360 def test_get_custom_image_dependency_validation_for_custom_centos(self):359 def test_validation_for_custom_centos(self):
360 distro_series = factory.make_name("centos7")
361 boot_resource = factory.make_BootResource(361 boot_resource = factory.make_BootResource(
362 name="custom/%s" % factory.make_name("centos7"),362 name=f"custom/{distro_series}",
363 base_image="centos/centos7",363 base_image="centos/centos7",
364 architecture="amd64/generic",364 architecture="amd64/generic",
365 )365 )
366 base_osystem, _ = boot_resource.split_base_image()366 machine = factory.make_Machine(
367 machine = factory.make_Machine(status=NODE_STATUS.DEPLOYED)367 status=NODE_STATUS.DEPLOYED,
368 machine.osystem, machine.distro_series = boot_resource.name.split("/")368 architecture=boot_resource.architecture,
369 machine.architecture = boot_resource.architecture369 osystem="custom",
370 machine.save()370 distro_series=distro_series,
371 validation = get_custom_image_dependency_validation(
372 machine, base_osystem
373 )371 )
372 validation = get_custom_image_dependency_validation(machine, "centos")
374 expected = {373 expected = {
375 "98-validate-custom-image-has-cloud-init": [374 "98-validate-custom-image-has-cloud-init": [
376 "curtin",375 "curtin",
@@ -378,32 +377,70 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
378 "--",377 "--",
379 "bash",378 "bash",
380 "-c",379 "-c",
381 'dnf list cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',380 'rpm -q cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
382 ],381 ],
383 "99-validate-custom-image-has-netplan.io": [382 }
383 self.assertEqual(validation, expected)
384
385 def test_validation_for_custom_rhel(self):
386 distro_series = factory.make_name("rhel8")
387 boot_resource = factory.make_BootResource(
388 name=f"custom/{distro_series}",
389 base_image="rhel/rhel8",
390 architecture="amd64/generic",
391 )
392 machine = factory.make_Machine(
393 status=NODE_STATUS.DEPLOYED,
394 architecture=boot_resource.architecture,
395 osystem="custom",
396 distro_series=distro_series,
397 )
398 validation = get_custom_image_dependency_validation(machine, "rhel")
399 expected = {
400 "98-validate-custom-image-has-cloud-init": [
384 "curtin",401 "curtin",
385 "in-target",402 "in-target",
386 "--",403 "--",
387 "bash",404 "bash",
388 "-c",405 "-c",
389 'dnf list netplan.io || (echo "netplan.io not detected, MAAS will not be able to configure this machine properly" && exit 1)',406 'rpm -q cloud-init || (echo "cloud-init not detected, MAAS will not be able to configure this machine properly" && exit 1)',
390 ],407 ],
391 }408 }
392 for k in expected:409 self.assertEqual(validation, expected)
393 self.assertCountEqual(validation[k], expected[k])
394410
395 def test_get_custom_image_dependency_validation_for_non_custom(self):411 def test_validation_for_non_custom(self):
396 boot_resource = factory.make_BootResource(412 boot_resource = factory.make_BootResource(
397 name="ubuntu/focal", architecture="amd64/generic"413 name="ubuntu/focal", architecture="amd64/generic"
398 )414 )
399 machine = factory.make_Machine(status=NODE_STATUS.DEPLOYED)415 machine = factory.make_Machine(
400 machine.osystem, machine.distro_series = boot_resource.name.split("/")416 status=NODE_STATUS.DEPLOYED,
401 machine.architecture = boot_resource.architecture417 architecture=boot_resource.architecture,
402 machine.save()418 osystem="ubuntu",
419 distro_series="focal",
420 )
403 self.assertIsNone(421 self.assertIsNone(
404 get_custom_image_dependency_validation(machine, boot_resource.name)422 get_custom_image_dependency_validation(machine, boot_resource.name)
405 )423 )
406424
425 def test_validation_for_linuxes(self):
426 machine = factory.make_Machine(
427 status=NODE_STATUS.DEPLOYED,
428 architecture="amd64/generic",
429 osystem="custom",
430 )
431 for osystem in ("ubuntu", "centos", "rhel"):
432 distro_series = factory.make_name(osystem)
433 factory.make_BootResource(
434 name=f"custom/{distro_series}",
435 base_image=f"{osystem}/{osystem}",
436 architecture="amd64/generic",
437 )
438 machine.distro_series = distro_series
439 machine.save()
440 self.assertIsNotNone(
441 get_custom_image_dependency_validation(machine, osystem)
442 )
443
407444
408class TestLoadPreseedTemplate(MAASServerTestCase):445class TestLoadPreseedTemplate(MAASServerTestCase):
409 """Tests for `load_preseed_template`."""446 """Tests for `load_preseed_template`."""

Subscribers

People subscribed via source and target branches