← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~mfo/maas:lp2020397-opt-out into maas:master

 

Mauricio Faria de Oliveira has proposed merging ~mfo/maas:lp2020397-opt-out into maas:master.

Requested reviews:
  MAAS Maintainers (maas-maintainers)
Related bugs:
  Bug #2020397 in MAAS: "Custom images which worked ok is not working with 3.2"
  https://bugs.launchpad.net/maas/+bug/2020397

For more details, see:
https://code.launchpad.net/~mfo/maas/+git/maas/+merge/444127

Introduce an option to opt-out for custom image dependency validation in the curtin_userdata preseed.

custom_validation: 0

More details in the commit message.


-- 
Your team MAAS Maintainers is requested to review the proposed merge of ~mfo/maas:lp2020397-opt-out into maas:master.
diff --git a/src/maasserver/preseed.py b/src/maasserver/preseed.py
index 94d77c0..ad83e3f 100644
--- a/src/maasserver/preseed.py
+++ b/src/maasserver/preseed.py
@@ -632,8 +632,18 @@ def get_curtin_config(request, node, base_osystem=None, base_series=None):
             }
         )
 
+    # Allow users to skip custom image dependency validation
+    # with 'custom_validation: 0' in curtin_userdata(_custom).
+    custom_validation_config = None
+    if "custom_validation" in config:
+        # The key is only valid on custom osystem, but may exist
+        # on non-custom (shared template, e.g., curtin_userdata).
+        if osystem == "custom":
+            custom_validation_config = config["custom_validation"]
+        del config["custom_validation"]
+
     custom_validation = get_custom_image_dependency_validation(
-        node, base_osystem
+        node, base_osystem, custom_validation_config
     )
     if custom_validation is not None:
         config["late_commands"].update(custom_validation)
@@ -655,9 +665,11 @@ PACKAGE_MANAGER_PER_OS = {
 }
 
 
-def get_custom_image_dependency_validation(node, base_osystem):
+def get_custom_image_dependency_validation(node, base_osystem, config):
     if node.get_osystem() != "custom":
         return None
+    if config == 0:
+        return None
 
     cmd = {}
     err_msg = "not detected, MAAS will not be able to configure this machine properly"
diff --git a/src/maasserver/tests/test_preseed.py b/src/maasserver/tests/test_preseed.py
index 8d36e2a..6fd204f 100644
--- a/src/maasserver/tests/test_preseed.py
+++ b/src/maasserver/tests/test_preseed.py
@@ -336,7 +336,7 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
             osystem="custom",
             distro_series=distro_series,
         )
-        validation = get_custom_image_dependency_validation(machine, "ubuntu")
+        validation = get_custom_image_dependency_validation(machine, "ubuntu", None)
         expected = {
             "98-validate-custom-image-has-cloud-init": [
                 "curtin",
@@ -370,7 +370,7 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
             osystem="custom",
             distro_series=distro_series,
         )
-        validation = get_custom_image_dependency_validation(machine, "centos")
+        validation = get_custom_image_dependency_validation(machine, "centos", None)
         expected = {
             "98-validate-custom-image-has-cloud-init": [
                 "curtin",
@@ -396,7 +396,7 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
             osystem="custom",
             distro_series=distro_series,
         )
-        validation = get_custom_image_dependency_validation(machine, "rhel")
+        validation = get_custom_image_dependency_validation(machine, "rhel", None)
         expected = {
             "98-validate-custom-image-has-cloud-init": [
                 "curtin",
@@ -420,7 +420,7 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
             distro_series="focal",
         )
         self.assertIsNone(
-            get_custom_image_dependency_validation(machine, boot_resource.name)
+            get_custom_image_dependency_validation(machine, boot_resource.name, None)
         )
 
     def test_validation_for_linuxes(self):
@@ -439,9 +439,46 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
             machine.distro_series = distro_series
             machine.save()
             self.assertIsNotNone(
-                get_custom_image_dependency_validation(machine, osystem)
+                get_custom_image_dependency_validation(machine, osystem, None)
             )
 
+    def test_validation_for_linuxes_skip_zero(self):
+        machine = factory.make_Machine(
+            status=NODE_STATUS.DEPLOYED,
+            architecture="amd64/generic",
+            osystem="custom",
+        )
+        for osystem in LINUX_OSYSTEMS:
+            distro_series = factory.make_name(osystem)
+            factory.make_BootResource(
+                name=f"custom/{distro_series}",
+                base_image=f"{osystem}/{osystem}",
+                architecture="amd64/generic",
+            )
+            machine.distro_series = distro_series
+            machine.save()
+            self.assertIsNone(
+                get_custom_image_dependency_validation(machine, osystem, 0)
+            )
+
+    def test_validation_for_linuxes_skip_zero_only(self):
+        machine = factory.make_Machine(
+            status=NODE_STATUS.DEPLOYED,
+            architecture="amd64/generic",
+            osystem="custom",
+        )
+        for osystem in LINUX_OSYSTEMS:
+            distro_series = factory.make_name(osystem)
+            factory.make_BootResource(
+                name=f"custom/{distro_series}",
+                base_image=f"{osystem}/{osystem}",
+                architecture="amd64/generic",
+            )
+            machine.distro_series = distro_series
+            machine.save()
+            self.assertIsNotNone(
+                get_custom_image_dependency_validation(machine, osystem, "not0")
+            )
 
 class TestLoadPreseedTemplate(MAASServerTestCase):
     """Tests for `load_preseed_template`."""

Follow ups