launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #14936
[Merge] lp:~rvb/maas/bug-1100225 into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/bug-1100225 into lp:maas.
Commit message:
Only update nodegroup.maas_url if the hostname is not 'localhost'.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1100225 in MAAS: "Restarting the master cluster controller changes the url sent to the nodes to contact the metadata service to http://localhost/MAAS; this prevents the nodes from booting properly."
https://bugs.launchpad.net/maas/+bug/1100225
For more details, see:
https://code.launchpad.net/~rvb/maas/bug-1100225/+merge/143476
--
https://code.launchpad.net/~rvb/maas/bug-1100225/+merge/143476
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/bug-1100225 into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2012-12-20 14:46:36 +0000
+++ src/maasserver/api.py 2013-01-16 11:07:21 +0000
@@ -91,6 +91,7 @@
from inspect import getdoc
import sys
from textwrap import dedent
+from urlparse import urlparse
from xml.sax.saxutils import quoteattr
from celery.app import app_or_default
@@ -949,10 +950,17 @@
def update_nodegroup_maas_url(nodegroup, request):
- """Update `nodegroup.maas_url` from the given `request`."""
+ """Update `nodegroup.maas_url` from the given `request`.
+
+ Only update `nodegroup.maas_url` if the hostname part is not 'localhost'
+ (i.e. the default value used when the master nodegroup connects).
+ """
path = request.META["SCRIPT_NAME"]
- nodegroup.maas_url = build_absolute_uri(request, path)
- nodegroup.save()
+ maas_url = build_absolute_uri(request, path)
+ server_host = urlparse(maas_url).hostname
+ if server_host != 'localhost':
+ nodegroup.maas_url = maas_url
+ nodegroup.save()
class NodeGroupsHandler(OperationsHandler):
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-12-20 10:06:34 +0000
+++ src/maasserver/tests/test_api.py 2013-01-16 11:07:21 +0000
@@ -3918,6 +3918,17 @@
api.update_nodegroup_maas_url(nodegroup, request)
self.assertEqual("http://example.com/script", nodegroup.maas_url)
+ def test_update_from_request_discarded_if_localhost(self):
+ request_factory = RequestFactory(SCRIPT_NAME="/script")
+ request = request_factory.get(
+ "/script/path", SERVER_NAME="localhost")
+ maas_url = factory.make_name('maas_url')
+ nodegroup = factory.make_node_group(maas_url=maas_url)
+ api.update_nodegroup_maas_url(nodegroup, request)
+ # nodegroup.maas_url has not been changed by
+ # api.update_nodegroup_maas_url.
+ self.assertEqual(maas_url, nodegroup.maas_url)
+
def dict_subset(obj, fields):
"""Return a dict of a subset of the fields/values of an object."""