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

Proposed by Mauricio Faria de Oliveira
Status: Rejected
Rejected by: Adam Collard
Proposed branch: ~mfo/maas:lp2020397-opt-out
Merge into: maas:master
Diff against target: 88 lines (+54/-2)
2 files modified
src/maasserver/preseed.py (+14/-2)
src/maasserver/tests/test_preseed.py (+40/-0)
Reviewer Review Type Date Requested Status
Jack Lloyd-Walters Abstain
MAAS Lander Approve
Review via email: mp+444127@code.launchpad.net

Description of the change

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.

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

UNIT TESTS
-b lp2020397-opt-out lp:~mfo/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/2661/console
COMMIT: 26be7fdf406b47d138c592eaea0806b2d38fc072

review: Needs Fixing
Revision history for this message
Mauricio Faria de Oliveira (mfo) wrote :

jenkins: !test

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

UNIT TESTS
-b lp2020397-opt-out lp:~mfo/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/2664/console
COMMIT: 6cf0398316addba1b0597d5acef8044519924d3c

review: Needs Fixing
Revision history for this message
Mauricio Faria de Oliveira (mfo) wrote :

jenkins: !test

Revision history for this message
Mauricio Faria de Oliveira (mfo) wrote :

jenkins: !test

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

UNIT TESTS
-b lp2020397-opt-out lp:~mfo/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: e1cd74f9583e91fd598f98d60a20a4191d225e8b

review: Approve
Revision history for this message
Jack Lloyd-Walters (lloydwaltersj) wrote :

+1

review: Approve
Revision history for this message
Jack Lloyd-Walters (lloydwaltersj) :
review: Abstain

Unmerged commits

e1cd74f... by Mauricio Faria de Oliveira

LP: #2020397 - Opt-out for custom image dependency validation

Some custom images might not have any package manager at all,
thus fail the (curtin) late commands on deployment for custom
image dependency validation (cloud-init and netplan packages).

Even though these checks may be perceived as a regression in
such cases, it is likely better to keep them by default, for
more robust checks/assertions on deployment vs. boot errors.

As a workaround, users could add late commands to create/remove
symlinks of the package manager command to /bin/true to fake it,
but that is hacky, and might fail after source code changes.

So, let's provide a way for these users to opt-out of custom
image dependency validation with the curtin_userdata preseed
(since these checks are introduced as curtin late commands),
in an upstream-maintained manner.

In the curtin_userdata preseed/template, introduce this line:
custom_validation: 0

This would seem better than introducing per-custom image
properties (database changes involved, probably) or some
CLI/UI changes and pipe them to the deployment functions.

Tests
=====

Steps: download centos70 image, upload as custom, deploy.

Default:

    start: cmd-install/stage-late: executing late commands
    start: cmd-install/stage-late/98-validate-custom-image-has-cloud-init: running 'curtin in-target -- bash -c dpkg-query -s cloud-init || (echo "cloud-init not detected, ..." && exit 1)'
    ...
    bash: dpkg-query: command not found
    cloud-init not detected, MAAS will not be able to configure this machine properly
    ...
    98-validate-custom-image-has-cloud-init command failed
    finish: cmd-install/stage-late/98-validate-custom-image-has-cloud-init: FAIL: running 'curtin in-target -- bash -c dpkg-query -s cloud-init || (echo "cloud-init not detected, ..." && exit 1)'
    ...
    finish: cmd-install/stage-late: FAIL: executing late commands
    curtin: Installation failed with exception: Unexpected error while running command.

Opt-out:

    start: cmd-install/stage-late: executing late commands
    ...
    finish: cmd-install/stage-late: SUCCESS: executing late commands
    curtin: Installation finished.

Unit tests:

    $ make install-dependencies
    $ make bin/pytest
    $ bin/pytest src/maasserver/tests/test_preseed.py -k TestGetCustomImageDependencyValidation -v --no-header --no-summary
    ...
    src/maasserver/tests/test_preseed.py::TestGetCustomImageDependencyValidation::test_validation_for_custom_centos PASSED [ 14%]
    src/maasserver/tests/test_preseed.py::TestGetCustomImageDependencyValidation::test_validation_for_custom_rhel PASSED [ 28%]
    src/maasserver/tests/test_preseed.py::TestGetCustomImageDependencyValidation::test_validation_for_custom_ubuntu PASSED [ 42%]
    src/maasserver/tests/test_preseed.py::TestGetCustomImageDependencyValidation::test_validation_for_linuxes PASSED [ 57%]
    src/maasserver/tests/test_preseed.py::TestGetCustomImageDependencyValidation::test_validation_for_linuxes_skip_zero PASSED [ 71%]
    src/maasserver/tests/test_preseed.py::TestGetCustomImageDependencyValidation::test_validation_for_linuxes_skip_zero_only PASSED [ 85%]
    src/maasserver/tests/test_preseed.py::TestGetCustomImageDependencyValidation::test_validation_for_non_custom PASSED [100%]
    ...

Signed-off-by: Mauricio Faria de Oliveira <email address hidden>

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 94d77c0..57bd72d 100644
3--- a/src/maasserver/preseed.py
4+++ b/src/maasserver/preseed.py
5@@ -632,8 +632,18 @@ def get_curtin_config(request, node, base_osystem=None, base_series=None):
6 }
7 )
8
9+ # Allow users to skip custom image dependency validation
10+ # with 'custom_validation: 0' in curtin_userdata(_custom).
11+ custom_validation_config = None
12+ if "custom_validation" in config:
13+ # The key is only valid on custom osystem, but may exist
14+ # on non-custom (shared template, e.g., curtin_userdata).
15+ if osystem == "custom":
16+ custom_validation_config = config["custom_validation"]
17+ del config["custom_validation"]
18+
19 custom_validation = get_custom_image_dependency_validation(
20- node, base_osystem
21+ node, base_osystem, custom_validation_config
22 )
23 if custom_validation is not None:
24 config["late_commands"].update(custom_validation)
25@@ -655,9 +665,11 @@ PACKAGE_MANAGER_PER_OS = {
26 }
27
28
29-def get_custom_image_dependency_validation(node, base_osystem):
30+def get_custom_image_dependency_validation(node, base_osystem, config=None):
31 if node.get_osystem() != "custom":
32 return None
33+ if config == 0:
34+ return None
35
36 cmd = {}
37 err_msg = "not detected, MAAS will not be able to configure this machine properly"
38diff --git a/src/maasserver/tests/test_preseed.py b/src/maasserver/tests/test_preseed.py
39index 8d36e2a..f068a4f 100644
40--- a/src/maasserver/tests/test_preseed.py
41+++ b/src/maasserver/tests/test_preseed.py
42@@ -442,6 +442,46 @@ class TestGetCustomImageDependencyValidation(MAASServerTestCase):
43 get_custom_image_dependency_validation(machine, osystem)
44 )
45
46+ def test_validation_for_linuxes_skip_zero(self):
47+ machine = factory.make_Machine(
48+ status=NODE_STATUS.DEPLOYED,
49+ architecture="amd64/generic",
50+ osystem="custom",
51+ )
52+ for osystem in LINUX_OSYSTEMS:
53+ distro_series = factory.make_name(osystem)
54+ factory.make_BootResource(
55+ name=f"custom/{distro_series}",
56+ base_image=f"{osystem}/{osystem}",
57+ architecture="amd64/generic",
58+ )
59+ machine.distro_series = distro_series
60+ machine.save()
61+ self.assertIsNone(
62+ get_custom_image_dependency_validation(machine, osystem, 0)
63+ )
64+
65+ def test_validation_for_linuxes_skip_zero_only(self):
66+ machine = factory.make_Machine(
67+ status=NODE_STATUS.DEPLOYED,
68+ architecture="amd64/generic",
69+ osystem="custom",
70+ )
71+ for osystem in LINUX_OSYSTEMS:
72+ distro_series = factory.make_name(osystem)
73+ factory.make_BootResource(
74+ name=f"custom/{distro_series}",
75+ base_image=f"{osystem}/{osystem}",
76+ architecture="amd64/generic",
77+ )
78+ machine.distro_series = distro_series
79+ machine.save()
80+ self.assertIsNotNone(
81+ get_custom_image_dependency_validation(
82+ machine, osystem, "not0"
83+ )
84+ )
85+
86
87 class TestLoadPreseedTemplate(MAASServerTestCase):
88 """Tests for `load_preseed_template`."""

Subscribers

People subscribed via source and target branches