Merge lp:~rvb/maas/no-nodegroup-for-devices into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 3610
Proposed branch: lp:~rvb/maas/no-nodegroup-for-devices
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 92 lines (+12/-19)
2 files modified
src/maasserver/api/tests/test_devices.py (+2/-4)
src/maasserver/forms.py (+10/-15)
To merge this branch: bzr merge lp:~rvb/maas/no-nodegroup-for-devices
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+251771@code.launchpad.net

Commit message

Link the devices to the default nodegroup. Devices should not be linked to a particular nodegroup but since the DNS machinery is linked to the nodegroups, as a step forward, we use the default nodegroup for now.

Description of the change

When we disconnect the DNS machinery from the nodegroups, we can remove this and have the device's nodegroup field set to None. What's important right now is that the API is designed in a way that can work with the model with have now *and* with the new networking model (i.e. we don't want the use to select a nodegroup when creating a device).

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/tests/test_devices.py'
2--- src/maasserver/api/tests/test_devices.py 2015-02-17 19:32:56 +0000
3+++ src/maasserver/api/tests/test_devices.py 2015-03-04 16:27:53 +0000
4@@ -29,6 +29,7 @@
5 from maasserver.models import (
6 Node,
7 node as node_module,
8+ NodeGroup,
9 StaticIPAddress,
10 )
11 from maasserver.testing.api import APITestCase
12@@ -44,7 +45,6 @@
13 '/api/1.0/devices/', reverse('devices_handler'))
14
15 def test_new_creates_device(self):
16- cluster = factory.make_NodeGroup()
17 hostname = factory.make_name('host')
18 macs = {
19 factory.make_mac_address()
20@@ -54,7 +54,6 @@
21 reverse('devices_handler'),
22 {
23 'op': 'new',
24- 'nodegroup': cluster.id,
25 'hostname': hostname,
26 'mac_addresses': macs,
27 })
28@@ -63,18 +62,17 @@
29 device = Node.devices.get(system_id=system_id)
30 self.assertEquals(hostname, device.hostname)
31 self.assertFalse(device.installable)
32+ self.assertEquals(NodeGroup.objects.ensure_master(), device.nodegroup)
33 self.assertEquals(self.logged_in_user, device.owner)
34 self.assertEquals(
35 macs,
36 {mac.mac_address for mac in device.macaddress_set.all()})
37
38 def test_POST_returns_limited_fields(self):
39- cluster = factory.make_NodeGroup()
40 response = self.client.post(
41 reverse('devices_handler'),
42 {
43 'op': 'new',
44- 'nodegroup': cluster.id,
45 'hostname': factory.make_string(),
46 'mac_addresses': ['aa:bb:cc:dd:ee:ff'],
47 })
48
49=== modified file 'src/maasserver/forms.py'
50--- src/maasserver/forms.py 2015-02-20 16:52:57 +0000
51+++ src/maasserver/forms.py 2015-03-04 16:27:53 +0000
52@@ -638,7 +638,6 @@
53 model = Device
54
55 fields = (
56- 'nodegroup',
57 'hostname',
58 'parent',
59 )
60@@ -648,22 +647,18 @@
61 self.request = request
62
63 instance = kwargs.get('instance')
64- # Are we creating a new node object?
65- self.new_node = (instance is None)
66- if self.new_node:
67- # Offer choice of nodegroup.
68- self.fields['nodegroup'] = NodeGroupFormField(
69- required=False, empty_label="Default (master)")
70+ # Are we creating a new device object?
71+ self.new_device = (instance is None)
72
73 def save(self, commit=True):
74- node = super(DeviceForm, self).save(commit=False)
75- node.installable = False
76- if self.new_node:
77- # Set the owner: non-installable nodes are owned by their
78- # creator.
79- node.owner = self.request.user
80- node.save()
81- return node
82+ device = super(DeviceForm, self).save(commit=False)
83+ device.installable = False
84+ if self.new_device:
85+ # Set the owner: devices are owned by their creator.
86+ device.owner = self.request.user
87+ device.nodegroup = NodeGroup.objects.ensure_master()
88+ device.save()
89+ return device
90
91
92 CLUSTER_NOT_AVAILABLE = mark_safe(