Merge lp:~rvb/maas/bug-1100225 into lp:maas/trunk

Proposed by Raphaël Badin on 2013-01-16
Status: Merged
Approved by: Raphaël Badin on 2013-01-16
Approved revision: 1422
Merged at revision: 1422
Proposed branch: lp:~rvb/maas/bug-1100225
Merge into: lp:maas/trunk
Diff against target: 54 lines (+22/-3)
2 files modified
src/maasserver/api.py (+11/-3)
src/maasserver/tests/test_api.py (+11/-0)
To merge this branch: bzr merge lp:~rvb/maas/bug-1100225
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) 2013-01-16 Approve on 2013-01-16
Review via email: mp+143476@code.launchpad.net

Commit message

Only update nodegroup.maas_url if the hostname is not 'localhost'.

To post a comment you must log in.
Jeroen T. Vermeulen (jtv) wrote :

Looks good, makes sense. Thanks for the fix.

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.py'
2--- src/maasserver/api.py 2012-12-20 14:46:36 +0000
3+++ src/maasserver/api.py 2013-01-16 11:07:21 +0000
4@@ -91,6 +91,7 @@
5 from inspect import getdoc
6 import sys
7 from textwrap import dedent
8+from urlparse import urlparse
9 from xml.sax.saxutils import quoteattr
10
11 from celery.app import app_or_default
12@@ -949,10 +950,17 @@
13
14
15 def update_nodegroup_maas_url(nodegroup, request):
16- """Update `nodegroup.maas_url` from the given `request`."""
17+ """Update `nodegroup.maas_url` from the given `request`.
18+
19+ Only update `nodegroup.maas_url` if the hostname part is not 'localhost'
20+ (i.e. the default value used when the master nodegroup connects).
21+ """
22 path = request.META["SCRIPT_NAME"]
23- nodegroup.maas_url = build_absolute_uri(request, path)
24- nodegroup.save()
25+ maas_url = build_absolute_uri(request, path)
26+ server_host = urlparse(maas_url).hostname
27+ if server_host != 'localhost':
28+ nodegroup.maas_url = maas_url
29+ nodegroup.save()
30
31
32 class NodeGroupsHandler(OperationsHandler):
33
34=== modified file 'src/maasserver/tests/test_api.py'
35--- src/maasserver/tests/test_api.py 2012-12-20 10:06:34 +0000
36+++ src/maasserver/tests/test_api.py 2013-01-16 11:07:21 +0000
37@@ -3918,6 +3918,17 @@
38 api.update_nodegroup_maas_url(nodegroup, request)
39 self.assertEqual("http://example.com/script", nodegroup.maas_url)
40
41+ def test_update_from_request_discarded_if_localhost(self):
42+ request_factory = RequestFactory(SCRIPT_NAME="/script")
43+ request = request_factory.get(
44+ "/script/path", SERVER_NAME="localhost")
45+ maas_url = factory.make_name('maas_url')
46+ nodegroup = factory.make_node_group(maas_url=maas_url)
47+ api.update_nodegroup_maas_url(nodegroup, request)
48+ # nodegroup.maas_url has not been changed by
49+ # api.update_nodegroup_maas_url.
50+ self.assertEqual(maas_url, nodegroup.maas_url)
51+
52
53 def dict_subset(obj, fields):
54 """Return a dict of a subset of the fields/values of an object."""