Merge ~ltrager/maas:lp1881919_2.7 into maas:2.7

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: 2ed0926301c3e6bea5fe30fb14a921a4f7477555
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1881919_2.7
Merge into: maas:2.7
Diff against target: 83 lines (+29/-4)
3 files modified
src/maasserver/forms/ephemeral.py (+1/-1)
src/metadataserver/models/scriptset.py (+6/-2)
src/metadataserver/models/tests/test_scriptset.py (+22/-1)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Review via email: mp+386229@code.launchpad.net

Commit message

LP: #1881919 - Allow user to disable running a user uploaded commissioning script.

Currently when no commissioning scripts are selected by the user all user
uploaded commissioning scripts are automatically selected. This branch adds two ways to disable that.

1. Any commissioning script tagged with "noauto" won't be automatically selected by MAAS.
2. When using the API if commissioning_scripts=none no user uploaded commissioning script will be selected.

To post a comment you must log in.
Revision history for this message
Lee Trager (ltrager) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/forms/ephemeral.py b/src/maasserver/forms/ephemeral.py
2index 6ada27a..5e10990 100644
3--- a/src/maasserver/forms/ephemeral.py
4+++ b/src/maasserver/forms/ephemeral.py
5@@ -261,7 +261,7 @@ class CommissionForm(TestForm):
6 self.data[script_field] = value.split(",")
7
8 choices = {
9- SCRIPT_TYPE.COMMISSIONING: [],
10+ SCRIPT_TYPE.COMMISSIONING: [("none", "none")],
11 SCRIPT_TYPE.TESTING: [("none", "none")],
12 }
13 scripts = Script.objects.all()
14diff --git a/src/metadataserver/models/scriptset.py b/src/metadataserver/models/scriptset.py
15index c1c0435..d7dca6d 100644
16--- a/src/metadataserver/models/scriptset.py
17+++ b/src/metadataserver/models/scriptset.py
18@@ -1,4 +1,4 @@
19-# Copyright 2017-2019 Canonical Ltd. This software is licensed under the
20+# Copyright 2017-2020 Canonical Ltd. This software is licensed under the
21 # GNU Affero General Public License version 3 (see the file LICENSE).
22
23 __all__ = ["ScriptSet", "get_status_from_qs", "translate_result_type"]
24@@ -145,9 +145,13 @@ class ScriptSetManager(Manager):
25 # all by default excluding for_hardware scripts.
26 qs = Script.objects.filter(
27 script_type=SCRIPT_TYPE.COMMISSIONING, for_hardware=[]
28- )
29+ ).exclude(tags__contains=["noauto"])
30 for script in qs:
31 script_set.add_pending_script(script, script_input)
32+ elif "none" in scripts:
33+ # Don't add any scripts besides the ones that come with MAAS but
34+ # do perform cleanup below.
35+ pass
36 else:
37 self._add_user_selected_scripts(script_set, scripts, script_input)
38
39diff --git a/src/metadataserver/models/tests/test_scriptset.py b/src/metadataserver/models/tests/test_scriptset.py
40index f69175e..79bd5dd 100644
41--- a/src/metadataserver/models/tests/test_scriptset.py
42+++ b/src/metadataserver/models/tests/test_scriptset.py
43@@ -1,4 +1,4 @@
44-# Copyright 2017-2019 Canonical Ltd. This software is licensed under the
45+# Copyright 2017-2020 Canonical Ltd. This software is licensed under the
46 # GNU Affero General Public License version 3 (see the file LICENSE).
47
48 __all__ = []
49@@ -181,6 +181,10 @@ class TestScriptSetManager(MAASServerTestCase):
50
51 def test_create_commissioning_script_set_adds_all_user_scripts(self):
52 script = factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING)
53+ # Scripts tagged with noauto must be specified by name.
54+ factory.make_Script(
55+ script_type=SCRIPT_TYPE.COMMISSIONING, tags=["noauto"]
56+ )
57 node = factory.make_Node()
58 expected_scripts = list(NODE_INFO_SCRIPTS)
59 expected_scripts.append(script.name)
60@@ -196,6 +200,23 @@ class TestScriptSetManager(MAASServerTestCase):
61 node.power_state, script_set.power_state_before_transition
62 )
63
64+ def test_create_commissioning_script_set_adds_no_user_scripts(self):
65+ factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING)
66+ node = factory.make_Node()
67+
68+ script_set = ScriptSet.objects.create_commissioning_script_set(
69+ node, scripts="none"
70+ )
71+
72+ self.assertItemsEqual(
73+ list(NODE_INFO_SCRIPTS),
74+ [script_result.name for script_result in script_set],
75+ )
76+ self.assertEquals(RESULT_TYPE.COMMISSIONING, script_set.result_type)
77+ self.assertEquals(
78+ node.power_state, script_set.power_state_before_transition
79+ )
80+
81 def test_create_commissioning_script_set_adds_for_hardware_matches_tag(
82 self,
83 ):

Subscribers

People subscribed via source and target branches