Merge lp:~jtv/maas/ui-maas_url into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Rejected
Rejected by: Andres Rodriguez
Proposed branch: lp:~jtv/maas/ui-maas_url
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 94 lines (+47/-4)
3 files modified
src/maasserver/forms.py (+4/-3)
src/maasserver/models/nodegroup.py (+6/-1)
src/maasserver/tests/test_forms_nodegroup.py (+37/-0)
To merge this branch: bzr merge lp:~jtv/maas/ui-maas_url
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+236817@code.launchpad.net

Commit message

Expose NodeGroup.maas_url in the NodeGroupEdit, so that it can be edited through the UI and the API.

Users will typically have to edit this URL before they can disable IPv4 on nodes. Otherwise, this will default to an IPv4 address which the nodes won't be able to reach.

Description of the change

I didn't bother testing the API side separately. We don't test that for other fields either; it's just another item in the request data as far as the API is concerned.

Along the way I touched up the help text for the ‘name’ field. Makes it feel more like this branch actually makes some changes. :)

Jeroen

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

This looks good, but beware: maas_url is automatically updated by m.api.node_groups.update_nodegroup_maas_url() each time the cluster starts. I guess that behaviour will need to be changed.

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-09-30 09:14:41 +0000
3+++ src/maasserver/forms.py 2014-10-02 05:04:41 +0000
4@@ -1610,9 +1610,9 @@
5 name = forms.CharField(
6 label="DNS zone name",
7 help_text=(
8- "Name of the related DNS zone. Note that this will only "
9- "be used if MAAS is managing a DNS zone for one of the interfaces "
10- "of this cluster. See the 'status' of the interfaces below."),
11+ "Name of this cluster's DNS zone. This is only used if MAAS is "
12+ "managing a DNS zone for any of the cluster's interfaces. "
13+ "See the interfaces' management settings below."),
14 required=False)
15
16 class Meta:
17@@ -1621,6 +1621,7 @@
18 'cluster_name',
19 'status',
20 'name',
21+ 'maas_url',
22 )
23
24 def clean_name(self):
25
26=== modified file 'src/maasserver/models/nodegroup.py'
27--- src/maasserver/models/nodegroup.py 2014-09-30 18:13:21 +0000
28+++ src/maasserver/models/nodegroup.py 2014-10-02 05:04:41 +0000
29@@ -20,6 +20,7 @@
30
31 from apiclient.creds import convert_tuple_to_string
32 from crochet import TimeoutError
33+from django.core.validators import URLValidator
34 from django.db.models import (
35 BooleanField,
36 CharField,
37@@ -175,7 +176,11 @@
38 # The URL where the cluster controller can access the region
39 # controller.
40 maas_url = CharField(
41- blank=True, editable=False, max_length=255, default='')
42+ blank=True, editable=True, max_length=255, default='',
43+ validators=[URLValidator()], verbose_name="Region controller URL",
44+ help_text=(
45+ "URL where nodes in this cluster can reach the MAAS region "
46+ "controller API."))
47
48 # Should nodes on this cluster be configured to disable IPv4 on deployment
49 # by default?
50
51=== modified file 'src/maasserver/tests/test_forms_nodegroup.py'
52--- src/maasserver/tests/test_forms_nodegroup.py 2014-09-19 04:49:07 +0000
53+++ src/maasserver/tests/test_forms_nodegroup.py 2014-10-02 05:04:41 +0000
54@@ -382,3 +382,40 @@
55 self.assertTrue(form.is_valid())
56 form.save()
57 self.assertEqual(data['name'], reload_object(nodegroup).name)
58+
59+ def test_accepts_IPv4_URL(self):
60+ url = 'http://%s/MAAS' % factory.make_ipv4_address()
61+ cluster = factory.make_NodeGroup()
62+ data = self.make_form_data(cluster)
63+ data['maas_url'] = url
64+ form = NodeGroupEdit(instance=cluster, data=data)
65+ self.assertTrue(form.is_valid(), form._errors)
66+ cluster = form.save()
67+ self.assertEqual(url, cluster.maas_url)
68+
69+ def test_accepts_IPv6_URL(self):
70+ url = 'http://[%s]/MAAS' % factory.make_ipv6_address()
71+ cluster = factory.make_NodeGroup()
72+ data = self.make_form_data(cluster)
73+ data['maas_url'] = url
74+ form = NodeGroupEdit(instance=cluster, data=data)
75+ self.assertTrue(form.is_valid(), form._errors)
76+ cluster = form.save()
77+ self.assertEqual(url, cluster.maas_url)
78+
79+ def test_accepts_hostname_URL(self):
80+ url = 'http://%s.example.com/MAAS' % factory.make_name('host')
81+ cluster = factory.make_NodeGroup()
82+ data = self.make_form_data(cluster)
83+ data['maas_url'] = url
84+ form = NodeGroupEdit(instance=cluster, data=data)
85+ self.assertTrue(form.is_valid(), form._errors)
86+ cluster = form.save()
87+ self.assertEqual(url, cluster.maas_url)
88+
89+ def test_rejects_invalid_URL(self):
90+ cluster = factory.make_NodeGroup()
91+ data = self.make_form_data(cluster)
92+ data['maas_url'] = '???//foo!'
93+ form = NodeGroupEdit(instance=cluster, data=data)
94+ self.assertFalse(form.is_valid())