Merge ~ltrager/maas:lp1881919_2.8 into maas:2.8

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: e54e63ecf8a185780d522ac2f24f78eb51f2e593
Merged at revision: f08c9a0156dc4c587043fabbc764edc0401a8728
Proposed branch: ~ltrager/maas:lp1881919_2.8
Merge into: maas:2.8
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+386228@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
diff --git a/src/maasserver/forms/ephemeral.py b/src/maasserver/forms/ephemeral.py
index 6ada27a..5e10990 100644
--- a/src/maasserver/forms/ephemeral.py
+++ b/src/maasserver/forms/ephemeral.py
@@ -261,7 +261,7 @@ class CommissionForm(TestForm):
261 self.data[script_field] = value.split(",")261 self.data[script_field] = value.split(",")
262262
263 choices = {263 choices = {
264 SCRIPT_TYPE.COMMISSIONING: [],264 SCRIPT_TYPE.COMMISSIONING: [("none", "none")],
265 SCRIPT_TYPE.TESTING: [("none", "none")],265 SCRIPT_TYPE.TESTING: [("none", "none")],
266 }266 }
267 scripts = Script.objects.all()267 scripts = Script.objects.all()
diff --git a/src/metadataserver/models/scriptset.py b/src/metadataserver/models/scriptset.py
index c1c0435..d7dca6d 100644
--- a/src/metadataserver/models/scriptset.py
+++ b/src/metadataserver/models/scriptset.py
@@ -1,4 +1,4 @@
1# Copyright 2017-2019 Canonical Ltd. This software is licensed under the1# Copyright 2017-2020 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__all__ = ["ScriptSet", "get_status_from_qs", "translate_result_type"]4__all__ = ["ScriptSet", "get_status_from_qs", "translate_result_type"]
@@ -145,9 +145,13 @@ class ScriptSetManager(Manager):
145 # all by default excluding for_hardware scripts.145 # all by default excluding for_hardware scripts.
146 qs = Script.objects.filter(146 qs = Script.objects.filter(
147 script_type=SCRIPT_TYPE.COMMISSIONING, for_hardware=[]147 script_type=SCRIPT_TYPE.COMMISSIONING, for_hardware=[]
148 )148 ).exclude(tags__contains=["noauto"])
149 for script in qs:149 for script in qs:
150 script_set.add_pending_script(script, script_input)150 script_set.add_pending_script(script, script_input)
151 elif "none" in scripts:
152 # Don't add any scripts besides the ones that come with MAAS but
153 # do perform cleanup below.
154 pass
151 else:155 else:
152 self._add_user_selected_scripts(script_set, scripts, script_input)156 self._add_user_selected_scripts(script_set, scripts, script_input)
153157
diff --git a/src/metadataserver/models/tests/test_scriptset.py b/src/metadataserver/models/tests/test_scriptset.py
index f69175e..79bd5dd 100644
--- a/src/metadataserver/models/tests/test_scriptset.py
+++ b/src/metadataserver/models/tests/test_scriptset.py
@@ -1,4 +1,4 @@
1# Copyright 2017-2019 Canonical Ltd. This software is licensed under the1# Copyright 2017-2020 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__all__ = []4__all__ = []
@@ -181,6 +181,10 @@ class TestScriptSetManager(MAASServerTestCase):
181181
182 def test_create_commissioning_script_set_adds_all_user_scripts(self):182 def test_create_commissioning_script_set_adds_all_user_scripts(self):
183 script = factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING)183 script = factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING)
184 # Scripts tagged with noauto must be specified by name.
185 factory.make_Script(
186 script_type=SCRIPT_TYPE.COMMISSIONING, tags=["noauto"]
187 )
184 node = factory.make_Node()188 node = factory.make_Node()
185 expected_scripts = list(NODE_INFO_SCRIPTS)189 expected_scripts = list(NODE_INFO_SCRIPTS)
186 expected_scripts.append(script.name)190 expected_scripts.append(script.name)
@@ -196,6 +200,23 @@ class TestScriptSetManager(MAASServerTestCase):
196 node.power_state, script_set.power_state_before_transition200 node.power_state, script_set.power_state_before_transition
197 )201 )
198202
203 def test_create_commissioning_script_set_adds_no_user_scripts(self):
204 factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING)
205 node = factory.make_Node()
206
207 script_set = ScriptSet.objects.create_commissioning_script_set(
208 node, scripts="none"
209 )
210
211 self.assertItemsEqual(
212 list(NODE_INFO_SCRIPTS),
213 [script_result.name for script_result in script_set],
214 )
215 self.assertEquals(RESULT_TYPE.COMMISSIONING, script_set.result_type)
216 self.assertEquals(
217 node.power_state, script_set.power_state_before_transition
218 )
219
199 def test_create_commissioning_script_set_adds_for_hardware_matches_tag(220 def test_create_commissioning_script_set_adds_for_hardware_matches_tag(
200 self,221 self,
201 ):222 ):

Subscribers

People subscribed via source and target branches