Merge lp:~jtv/maas/multi-nodegroupformfield-label into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 1850
Proposed branch: lp:~jtv/maas/multi-nodegroupformfield-label
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 65 lines (+10/-11)
2 files modified
src/maasserver/fields.py (+6/-5)
src/maasserver/tests/test_fields.py (+4/-6)
To merge this branch: bzr merge lp:~jtv/maas/multi-nodegroupformfield-label
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+203297@code.launchpad.net

Commit message

Support multiple managed interfaces in NodeGroupFormField.label_from_instance.

Description of the change

It's hard to test explicitly for the case where a nodegroup has multiple managed interfaces, because we don't actually allow that situation yet. But luckily the difference is entirely hidden way inside a unicode.join() call — as far as our code is concerned there is no difference now between one managed interface or several.

I considered adding tests for the fact that unmanaged interfaces are ignored, but I'm not actually sure it's all that important. it seems fairly arbitrary and there were no tests for it before.

Jeroen

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

[0]

52 + for interface in nodegroup.nodegroupinterface_set.all():
53 + interface.delete()

nodegroup.nodegroupinterface_set.all().delete() is more concise.

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Ah of course! I've been doing that elsewhere as well. Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/fields.py'
2--- src/maasserver/fields.py 2013-10-07 09:41:03 +0000
3+++ src/maasserver/fields.py 2014-01-27 12:38:54 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2012 Canonical Ltd. This software is licensed under the
6+# Copyright 2012-2014 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Custom model fields."""
10@@ -88,11 +88,12 @@
11
12 def label_from_instance(self, nodegroup):
13 """Django method: get human-readable choice label for nodegroup."""
14- interface = nodegroup.get_managed_interface()
15- if interface is None:
16+ interfaces = sorted(
17+ interface.ip for interface in nodegroup.get_managed_interfaces())
18+ if len(interfaces) > 0:
19+ return "%s: %s" % (nodegroup.name, ', '.join(interfaces))
20+ else:
21 return nodegroup.name
22- else:
23- return "%s: %s" % (nodegroup.name, interface.ip)
24
25 def clean(self, value):
26 """Django method: provide expected output for various inputs.
27
28=== modified file 'src/maasserver/tests/test_fields.py'
29--- src/maasserver/tests/test_fields.py 2013-10-21 05:31:09 +0000
30+++ src/maasserver/tests/test_fields.py 2014-01-27 12:38:54 +0000
31@@ -1,4 +1,4 @@
32-# Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
33+# Copyright 2012-2014 Canonical Ltd. This software is licensed under the
34 # GNU Affero General Public License version 3 (see the file LICENSE).
35
36 """Test custom model fields."""
37@@ -31,7 +31,6 @@
38 from maasserver.models import (
39 MACAddress,
40 NodeGroup,
41- NodeGroupInterface,
42 )
43 from maasserver.testing.factory import factory
44 from maasserver.testing.testcase import MAASServerTestCase
45@@ -47,17 +46,16 @@
46
47 def test_label_from_instance_tolerates_missing_interface(self):
48 nodegroup = factory.make_node_group()
49- interface = nodegroup.get_managed_interface()
50- if interface is not None:
51- NodeGroupInterface.objects.filter(id=interface.id).delete()
52+ nodegroup.nodegroupinterface_set.all().delete()
53 self.assertEqual(
54 nodegroup.name,
55 NodeGroupFormField().label_from_instance(nodegroup))
56
57 def test_label_from_instance_shows_name_and_address(self):
58 nodegroup = factory.make_node_group()
59+ [interface] = nodegroup.get_managed_interfaces()
60 self.assertEqual(
61- '%s: %s' % (nodegroup.name, nodegroup.get_managed_interface().ip),
62+ '%s: %s' % (nodegroup.name, interface.ip),
63 NodeGroupFormField().label_from_instance(nodegroup))
64
65 def test_clean_defaults_to_master(self):