Merge ~ltrager/maas:lp1707562 into maas:master

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: 3be9f76033c4c718f774a289294a050dab0b4628
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1707562
Merge into: maas:master
Diff against target: 120 lines (+63/-4)
2 files modified
src/maasserver/api/machines.py (+33/-3)
src/maasserver/api/tests/test_machines.py (+30/-1)
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
MAAS Lander Needs Fixing
Review via email: mp+363116@code.launchpad.net

Commit message

LP: #1707562 - When an admin creates a machine start commissioning using form.

When an administrator uses the API to create a machine start commissioning
using the CommissionForm. This allows the administrator to set all
commissioning options.

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

UNIT TESTS
-b lp1707562 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/5064/console
COMMIT: 3be9f76033c4c718f774a289294a050dab0b4628

review: Needs Fixing
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/machines.py b/src/maasserver/api/machines.py
2index ee7c7b3..b706767 100644
3--- a/src/maasserver/api/machines.py
4+++ b/src/maasserver/api/machines.py
5@@ -1,4 +1,4 @@
6-# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
7+# Copyright 2015-2019 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 __all__ = [
11@@ -1760,6 +1760,34 @@ class MachinesHandler(NodesHandler, PowersMixin):
12 COMMISSIONING. Machines will wait for COMMISSIONING results and not
13 time out.
14
15+ @param (int) "enable_ssh" [required=false] Whether to enable SSH for
16+ the commissioning environment using the user's SSH key(s). '1' == True,
17+ '0' == False.
18+
19+ @param (int) "skip_bmc_config" [required=false] Whether to skip
20+ re-configuration of the BMC for IPMI based machines. '1' == True, '0'
21+ == False.
22+
23+ @param (int) "skip_networking" [required=false] Whether to skip
24+ re-configuring the networking on the machine after the commissioning
25+ has completed. '1' == True, '0' == False.
26+
27+ @param (int) "skip_storage" [required=false] Whether to skip
28+ re-configuring the storage on the machine after the commissioning has
29+ completed. '1' == True, '0' == False.
30+
31+ @param (string) "commissioning_scripts" [required=false] A comma
32+ seperated list of commissioning script names and tags to be run. By
33+ default all custom commissioning scripts are run. Built-in
34+ commissioning scripts always run. Selecting 'update_firmware' or
35+ 'configure_hba' will run firmware updates or configure HBA's on
36+ matching machines.
37+
38+ @param (string) "testing_scripts" [required=false] A comma seperated
39+ list of testing script names and tags to be run. By default all tests
40+ tagged 'commissioning' will be run. Set to 'none' to disable running
41+ tests.
42+
43 @success (http-status-code) "200" 200
44 @success (json) "success-json" A JSON object containing the machine
45 information.
46@@ -1768,10 +1796,12 @@ class MachinesHandler(NodesHandler, PowersMixin):
47 """
48 machine = create_machine(request)
49 if request.user.is_superuser:
50- d = machine.start_commissioning(request.user)
51+ form = CommissionForm(
52+ instance=machine, user=request.user, data=request.data)
53 # Silently ignore errors to prevent 500 errors. The commissioning
54 # callbacks have their own logging. This fixes LP1600328.
55- d.addErrback(lambda _: None)
56+ if form.is_valid():
57+ machine = form.save()
58 return machine
59
60 def _check_system_ids_exist(self, system_ids):
61diff --git a/src/maasserver/api/tests/test_machines.py b/src/maasserver/api/tests/test_machines.py
62index 8b6bbed..efdc420 100644
63--- a/src/maasserver/api/tests/test_machines.py
64+++ b/src/maasserver/api/tests/test_machines.py
65@@ -1,4 +1,4 @@
66-# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
67+# Copyright 2015-2019 Canonical Ltd. This software is licensed under the
68 # GNU Affero General Public License version 3 (see the file LICENSE).
69
70 """Tests for the machines API."""
71@@ -74,6 +74,8 @@ from maastesting.matchers import (
72 )
73 from maastesting.testcase import MAASTestCase
74 from maastesting.twisted import always_succeed_with
75+from metadataserver.enum import SCRIPT_TYPE
76+from metadataserver.models import ScriptSet
77 from provisioningserver.rpc import cluster as cluster_module
78 from provisioningserver.utils.enum import map_enum
79 from testtools.matchers import (
80@@ -268,6 +270,7 @@ class TestMachinesAPI(APITestCase.ForUser):
81
82 def test_POST_handles_error_when_unable_to_access_bmc(self):
83 # Regression test for LP1600328
84+ self.patch(Machine, "_start").return_value = None
85 make_usable_osystem(self)
86 self.become_admin()
87 power_address = factory.make_ip_address()
88@@ -289,6 +292,32 @@ class TestMachinesAPI(APITestCase.ForUser):
89 power_address, machine.power_parameters['power_address'])
90 self.assertEqual(power_id, machine.power_parameters['power_id'])
91
92+ def test_POST_starts_commissioning_with_selected_test_scripts(self):
93+ # Regression test for LP1707562
94+ self.become_admin()
95+ self.patch(Machine, "_start").return_value = None
96+ make_usable_osystem(self)
97+ power_address = factory.make_ip_address()
98+ power_id = factory.make_name('power_id')
99+ test_script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING)
100+ response = self.client.post(
101+ reverse('machines_handler'),
102+ {
103+ 'architecture': make_usable_architecture(self),
104+ 'mac_addresses': ['aa:bb:cc:dd:ee:ff'],
105+ 'power_type': 'virsh',
106+ 'power_parameters_power_address': power_address,
107+ 'power_parameters_power_id': power_id,
108+ 'testing_scripts': test_script.name,
109+ })
110+ parsed_result = json.loads(response.content.decode())
111+ self.assertEquals(NODE_STATUS.COMMISSIONING, parsed_result['status'])
112+ script_set = ScriptSet.objects.get(
113+ id=parsed_result['current_testing_result_id'])
114+ self.assertItemsEqual(
115+ [test_script.name],
116+ [script_result.name for script_result in script_set])
117+
118 def test_GET_lists_machines(self):
119 # The api allows for fetching the list of Machines.
120 machine1 = factory.make_Node()

Subscribers

People subscribed via source and target branches