Merge lp:~jtv/maas/hide-cluster-default-disable-ipv4-if-no-ipv6 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: 3249
Proposed branch: lp:~jtv/maas/hide-cluster-default-disable-ipv4-if-no-ipv6
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~jtv/maas/bug-1379816
Diff against target: 70 lines (+45/-0)
2 files modified
src/maasserver/forms.py (+10/-0)
src/maasserver/tests/test_forms_nodegroup.py (+35/-0)
To merge this branch: bzr merge lp:~jtv/maas/hide-cluster-default-disable-ipv4-if-no-ipv6
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+238254@code.launchpad.net

Commit message

Hide the cluster edit form's “disable IPv4 by default” button if the cluster has no managed IPv6 interfaces.

Description of the change

Depends on https://code.launchpad.net/~jtv/maas/bug-1379816/+merge/238001 (which is blocked on this change).

The trick is the same one we also used on the Node form's disable_ipv4 field. If the field should not be displayed, we configure it with an empty label and its widget type set to HiddenInput. That way the field still works in the API, but the UI won't show it.

What happens if you leave this field in the “disable IPv4” setting but disable IPv6 on your cluster? Any new nodes will still be created with the setting enabled by default. But when you deploy a node with IPv4 disabled on a cluster that does not manage any IPv6 subnets, the nodes will simply ignore the setting and come up with IPv4 anyway. (This is currently done in the Ubuntu OperatingSystem implementation, but it should eventually be in generic code.)

Jeroen

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

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/forms.py'
2--- src/maasserver/forms.py 2014-10-14 11:23:07 +0000
3+++ src/maasserver/forms.py 2014-10-14 11:23:08 +0000
4@@ -1713,6 +1713,16 @@
5 'default_disable_ipv4',
6 )
7
8+ def __init__(self, *args, **kwargs):
9+ super(NodeGroupEdit, self).__init__(*args, **kwargs)
10+ # Hide the default_disable_ipv4 field if the cluster is not
11+ # configured for IPv6.
12+ show_default_disable_ipv4 = contains_managed_ipv6_interface(
13+ self.instance.nodegroupinterface_set.all())
14+ if not show_default_disable_ipv4:
15+ self.fields['default_disable_ipv4'] = forms.BooleanField(
16+ label="", required=False, widget=forms.HiddenInput())
17+
18 def clean_name(self):
19 old_name = self.instance.name
20 new_name = self.cleaned_data['name']
21
22=== modified file 'src/maasserver/tests/test_forms_nodegroup.py'
23--- src/maasserver/tests/test_forms_nodegroup.py 2014-09-19 04:49:07 +0000
24+++ src/maasserver/tests/test_forms_nodegroup.py 2014-10-14 11:23:08 +0000
25@@ -17,6 +17,10 @@
26 import json
27 from random import randint
28
29+from django.forms import (
30+ CheckboxInput,
31+ HiddenInput,
32+ )
33 from maasserver.enum import (
34 NODE_STATUS,
35 NODEGROUP_STATUS,
36@@ -382,3 +386,34 @@
37 self.assertTrue(form.is_valid())
38 form.save()
39 self.assertEqual(data['name'], reload_object(nodegroup).name)
40+
41+ def test_shows_default_disable_ipv4_if_managed_ipv6_configured(self):
42+ nodegroup = factory.make_NodeGroup()
43+ factory.make_NodeGroupInterface(
44+ nodegroup, network=factory.make_ipv6_network(),
45+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
46+ form = NodeGroupEdit(instance=nodegroup)
47+ self.assertIsInstance(
48+ form.fields['default_disable_ipv4'].widget, CheckboxInput)
49+
50+ def test_hides_default_disable_ipv4_if_no_managed_ipv6_configured(self):
51+ nodegroup = factory.make_NodeGroup()
52+ eth = factory.make_name('eth')
53+ factory.make_NodeGroupInterface(
54+ nodegroup, network=factory.make_ipv4_network(), interface=eth,
55+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
56+ factory.make_NodeGroupInterface(
57+ nodegroup, network=factory.make_ipv6_network(), interface=eth,
58+ management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED)
59+ form = NodeGroupEdit(instance=nodegroup)
60+ self.assertIsInstance(
61+ form.fields['default_disable_ipv4'].widget, HiddenInput)
62+
63+ def test_default_disable_ipv4_field_ignores_other_nodegroups(self):
64+ factory.make_NodeGroupInterface(
65+ factory.make_NodeGroup(), network=factory.make_ipv6_network(),
66+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
67+ nodegroup = factory.make_NodeGroup()
68+ form = NodeGroupEdit(instance=nodegroup)
69+ self.assertIsInstance(
70+ form.fields['default_disable_ipv4'].widget, HiddenInput)