Merge lp:~ltrager/maas/lp1636858_2.0 into lp:maas/2.0

Proposed by Lee Trager on 2016-10-26
Status: Merged
Approved by: Lee Trager on 2016-10-27
Approved revision: 5201
Merged at revision: 5202
Proposed branch: lp:~ltrager/maas/lp1636858_2.0
Merge into: lp:maas/2.0
Diff against target: 72 lines (+27/-6)
3 files modified
etc/maas/templates/commissioning-user-data/snippets/maas_enlist.sh (+1/-1)
src/maasserver/api/tests/test_machines.py (+18/-1)
src/maasserver/forms.py (+8/-4)
To merge this branch: bzr merge lp:~ltrager/maas/lp1636858_2.0
Reviewer Review Type Date Requested Status
Lee Trager Approve on 2016-10-27
Review via email: mp+309413@code.launchpad.net

Commit message

Backport from 2.1.1 - If the power_parameters are the empty string set them to an empty dictionary, don't use json.loads

To post a comment you must log in.
MAAS Lander (maas-lander) wrote :

Voting does not meet specified criteria. Required: Approve >= 1, Disapprove == 0. Got: .

Lee Trager (ltrager) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'etc/maas/templates/commissioning-user-data/snippets/maas_enlist.sh'
2--- etc/maas/templates/commissioning-user-data/snippets/maas_enlist.sh 2016-04-12 17:36:35 +0000
3+++ etc/maas/templates/commissioning-user-data/snippets/maas_enlist.sh 2016-10-26 23:40:14 +0000
4@@ -136,7 +136,7 @@
5 -n | --hostname hostname of the node to register
6 -i | --interface interface address to register (obtains MAC address)
7 -a | --arch architecture of the node to register
8- -t | --power-type power type (ipmi, virsh, manual)
9+ -t | --power-type power type (ipmi, virsh, moonshot)
10 -p | --power-params power parameters (In JSON format, between single quotes)
11 e.g. --power-params '{"power_address":"192.168.1.10"}'
12 --subarch subarchitecture of the node to register
13
14=== modified file 'src/maasserver/api/tests/test_machines.py'
15--- src/maasserver/api/tests/test_machines.py 2016-10-05 19:01:28 +0000
16+++ src/maasserver/api/tests/test_machines.py 2016-10-26 23:40:14 +0000
17@@ -203,6 +203,23 @@
18 "Select a valid choice. %s is not one of the "
19 "available choices." % power_type, validation_errors[0])
20
21+ def test_POST_new_handles_empty_str_power_parameters(self):
22+ # Regression test for LP:1636858
23+ response = self.client.post(
24+ reverse('machines_handler'),
25+ {
26+ 'architecture': make_usable_architecture(self),
27+ 'mac_addresses': ['aa:bb:cc:dd:ee:ff'],
28+ 'power_type': '',
29+ 'power_parameters': '',
30+ })
31+ self.assertEqual(http.client.OK, response.status_code)
32+ system_id = json.loads(
33+ response.content.decode(settings.DEFAULT_CHARSET))['system_id']
34+ machine = Machine.objects.get(system_id=system_id)
35+ self.assertEquals('', machine.power_type)
36+ self.assertItemsEqual({}, machine.power_parameters)
37+
38 def test_GET_lists_machines(self):
39 # The api allows for fetching the list of Machines.
40 machine1 = factory.make_Node()
41@@ -219,7 +236,7 @@
42
43 def test_GET_machines_issues_constant_number_of_queries(self):
44 # XXX: GavinPanella 2014-10-03 bug=1377335
45- self.skip("Unreliable; something is causing varying counts.")
46+ self.skipTest("Unreliable; something is causing varying counts.")
47
48 for _ in range(10):
49 factory.make_Node_with_Interface_on_Subnet()
50
51=== modified file 'src/maasserver/forms.py'
52--- src/maasserver/forms.py 2016-10-24 18:41:13 +0000
53+++ src/maasserver/forms.py 2016-10-26 23:40:14 +0000
54@@ -253,10 +253,14 @@
55 'power_parameters', form.initial.get('power_parameters', {}))
56
57 if isinstance(power_parameters, str):
58- try:
59- power_parameters = json.loads(power_parameters)
60- except json.JSONDecodeError:
61- raise ValidationError("Failed to parse JSON power_parameters")
62+ if power_parameters.strip() == '':
63+ power_parameters = {}
64+ else:
65+ try:
66+ power_parameters = json.loads(power_parameters)
67+ except json.JSONDecodeError:
68+ raise ValidationError(
69+ "Failed to parse JSON power_parameters")
70
71 # Integrate the machines existing power_parameters if unset by form.
72 if machine:

Subscribers

People subscribed via source and target branches

to all changes: