← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/service-url into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/service-url into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jtv/maas/service-url/+merge/97190

We need to tell the nodes where to reach the metadata service.  We have two problems with that:

1. It's not easy to figure out the right host name or address.  We've been using gethostname() for the default, but that too may be wrong.  We had to punt to user configuration for cases where this does not work.

2. When we test our development branches, the metadata service address isn't just a host name.  It's also on an unusual port: TCP port 8000.  This complicates vdenv testing.

So in this branch I define a single new configuration item: the MaaS URL.  The metadata service URL is derived from this, but it's a more generally useful address.

Absent deliberate configuration by administrators, maas_url defaults to a URL taken from the settings.  This in turn defaults to “http://<hostname>/” in general, but “http://<hostname>:8000/” on development systems.  Or maybe we'll find a better default for development systems later; this may take some further tweaking.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/service-url/+merge/97190
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/service-url into lp:maas.
=== modified file 'src/maas/development.py'
--- src/maas/development.py	2012-03-11 21:13:22 +0000
+++ src/maas/development.py	2012-03-13 11:11:18 +0000
@@ -11,9 +11,13 @@
 __metaclass__ = type
 
 import os
+from socket import gethostname
 
 from maas.settings import *
 
+# In development, django can be accessed directly on port 8000.
+DEFAULT_MAAS_URL = "http://%s:8000/"; % gethostname()
+
 # Use our custom test runner, which makes sure that a local database
 # cluster is running in the branch.
 TEST_RUNNER = 'maastesting.runner.TestRunner'

=== modified file 'src/maas/settings.py'
--- src/maas/settings.py	2012-03-12 15:50:49 +0000
+++ src/maas/settings.py	2012-03-13 11:11:18 +0000
@@ -11,6 +11,7 @@
 __metaclass__ = type
 
 import os
+from socket import gethostname
 
 # Use new style url tag:
 # https://docs.djangoproject.com/en/dev/releases/1.3/#changes-to-url-and-ssi
@@ -43,6 +44,12 @@
 LOGIN_REDIRECT_URL = '/'
 LOGIN_URL = '/accounts/login/'
 
+
+# Default URL where this MaaS can be found.  Configuration can, and
+# probably should, override this.
+DEFAULT_MAAS_URL = "http://%s/"; % gethostname()
+
+
 if FORCE_SCRIPT_NAME is not None:
     LOGOUT_URL = FORCE_SCRIPT_NAME + LOGOUT_URL
     LOGIN_REDIRECT_URL = FORCE_SCRIPT_NAME + LOGIN_REDIRECT_URL

=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py	2012-03-13 10:41:00 +0000
+++ src/maasserver/models.py	2012-03-13 11:11:18 +0000
@@ -29,7 +29,6 @@
 from logging import getLogger
 import os
 import re
-from socket import gethostname
 import time
 from uuid import uuid1
 
@@ -763,6 +762,9 @@
         'after_commissioning': NODE_AFTER_COMMISSIONING_ACTION.DEFAULT,
         'check_compatibility': False,
         'node_power_type': POWER_TYPE.WAKE_ON_LAN,
+        # The host name or address where the nodes can access the metadata
+        # service of this MaaS.
+        'maas_url': settings.DEFAULT_MAAS_URL,
         # Ubuntu section configuration.
         'fallback_master_archive': False,
         'keep_mirror_list_uptodate': False,
@@ -774,9 +776,6 @@
         'maas_name': "%s's" % getpass.getuser().capitalize(),
         'provide_dhcp': False,
         ## /settings
-        # The host name or address where the nodes can access the metadata
-        # service.
-        'metadata-host': gethostname(),
         }
 
 

=== modified file 'src/maasserver/provisioning.py'
--- src/maasserver/provisioning.py	2012-03-13 04:38:28 +0000
+++ src/maasserver/provisioning.py	2012-03-13 11:11:18 +0000
@@ -56,7 +56,9 @@
 
 def get_metadata_server_url():
     """Return the URL where nodes can reach the metadata service."""
-    return "http://%s/metadata/"; % Config.objects.get_config('metadata-host')
+    return (
+        "%s/metadata/"
+        % Config.objects.get_config('maas_url').rstrip('/'))
 
 
 def compose_metadata(node):

=== modified file 'src/maasserver/tests/test_provisioning.py'
--- src/maasserver/tests/test_provisioning.py	2012-03-13 09:34:02 +0000
+++ src/maasserver/tests/test_provisioning.py	2012-03-13 11:11:18 +0000
@@ -158,8 +158,8 @@
 
     def test_metadata_server_url_refers_to_own_metadata_service(self):
         self.assertEqual(
-            "http://%s/metadata/";
-            % Config.objects.get_config('metadata-host'),
+            "%s/metadata/"
+            % Config.objects.get_config('maas_url').rstrip('/'),
             get_metadata_server_url())
 
     def test_compose_metadata_includes_metadata_url(self):