← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/get-rid-of-maas_url into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/get-rid-of-maas_url into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/get-rid-of-maas_url/+merge/118343

Delete use of the Config 'maas_url'.  Get rid of get_metadata_server_url and use absolute_reverse instead.
-- 
https://code.launchpad.net/~rvb/maas/get-rid-of-maas_url/+merge/118343
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/get-rid-of-maas_url into lp:maas.
=== modified file 'src/maasserver/models/config.py'
--- src/maasserver/models/config.py	2012-07-27 14:52:44 +0000
+++ src/maasserver/models/config.py	2012-08-06 12:26:25 +0000
@@ -19,7 +19,6 @@
 import copy
 from socket import gethostname
 
-from django.conf import settings
 from django.db.models import (
     CharField,
     Manager,
@@ -39,9 +38,6 @@
         '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,

=== modified file 'src/maasserver/provisioning.py'
--- src/maasserver/provisioning.py	2012-06-22 09:48:17 +0000
+++ src/maasserver/provisioning.py	2012-08-06 12:26:25 +0000
@@ -23,7 +23,6 @@
 from logging import getLogger
 from textwrap import dedent
 from urllib import urlencode
-from urlparse import urljoin
 import xmlrpclib
 
 from django.conf import settings
@@ -44,10 +43,10 @@
     )
 from maasserver.exceptions import ExternalComponentException
 from maasserver.models import (
-    Config,
     MACAddress,
     Node,
     )
+from maasserver.utils import absolute_reverse
 from provisioningserver.enum import PSERV_FAULT
 import yaml
 
@@ -331,16 +330,6 @@
     return ProvisioningProxy(xmlrpc_proxy)
 
 
-def get_metadata_server_url():
-    """Return the URL where nodes can reach the metadata service."""
-    maas_url = Config.objects.get_config('maas_url')
-    if settings.FORCE_SCRIPT_NAME is None:
-        path = "metadata/"
-    else:
-        path = "%s/metadata/" % settings.FORCE_SCRIPT_NAME
-    return urljoin(maas_url, path)
-
-
 def compose_cloud_init_preseed(token):
     """Compose the preseed value for a node in any state but Commissioning."""
     credentials = urlencode({
@@ -353,7 +342,7 @@
     # ks_meta, and it gets fed straight into debconf.
     metadata_preseed_items = [
         ('datasources', 'multiselect', 'MAAS'),
-        ('maas-metadata-url', 'string', get_metadata_server_url()),
+        ('maas-metadata-url', 'string', absolute_reverse('metadata')),
         ('maas-metadata-credentials', 'string', credentials),
         ]
 
@@ -371,7 +360,7 @@
     return "#cloud-config\n%s" % yaml.safe_dump({
         'datasource': {
             'MAAS': {
-                'metadata_url': get_metadata_server_url(),
+                'metadata_url': absolute_reverse('metadata'),
                 'consumer_key': token.consumer.key,
                 'token_key': token.key,
                 'token_secret': token.secret,

=== modified file 'src/maasserver/tests/test_provisioning.py'
--- src/maasserver/tests/test_provisioning.py	2012-06-25 09:03:14 +0000
+++ src/maasserver/tests/test_provisioning.py	2012-08-06 12:26:25 +0000
@@ -16,7 +16,6 @@
 from base64 import b64decode
 from xmlrpclib import Fault
 
-from django.conf import settings
 from maasserver import (
     components,
     provisioning,
@@ -36,10 +35,7 @@
     ExternalComponentException,
     MAASAPIException,
     )
-from maasserver.models import (
-    Config,
-    Node,
-    )
+from maasserver.models import Node
 from maasserver.provisioning import (
     check_profiles,
     compose_cloud_init_preseed,
@@ -47,7 +43,6 @@
     compose_preseed,
     DETAILED_PRESENTATIONS,
     get_all_profile_names,
-    get_metadata_server_url,
     get_profile_name,
     name_arch_in_cobbler_style,
     present_detailed_user_friendly_fault,
@@ -58,7 +53,10 @@
     )
 from maasserver.testing.factory import factory
 from maasserver.testing.testcase import TestCase
-from maasserver.utils import map_enum
+from maasserver.utils import (
+    absolute_reverse,
+    map_enum,
+    )
 from metadataserver.models import NodeKey
 from provisioningserver.enum import (
     POWER_TYPE,
@@ -78,19 +76,6 @@
 class TestHelpers(TestCase):
     """Tests for helpers that don't actually need any kind of pserv."""
 
-    def test_metadata_server_url_refers_to_own_metadata_service(self):
-        self.assertEqual(
-            "%s/metadata/"
-            % Config.objects.get_config('maas_url').rstrip('/'),
-            get_metadata_server_url())
-
-    def test_metadata_server_url_includes_script_name(self):
-        self.patch(settings, "FORCE_SCRIPT_NAME", "/MAAS")
-        self.assertEqual(
-            "%s/MAAS/metadata/"
-            % Config.objects.get_config('maas_url').rstrip('/'),
-            get_metadata_server_url())
-
     def test_compose_preseed_for_commissioning_node_produces_yaml(self):
         node = factory.make_node(status=NODE_STATUS.COMMISSIONING)
         preseed = yaml.safe_load(compose_preseed(node))
@@ -107,13 +92,13 @@
 
     def test_compose_preseed_includes_metadata_url(self):
         node = factory.make_node(status=NODE_STATUS.READY)
-        self.assertIn(get_metadata_server_url(), compose_preseed(node))
+        self.assertIn(absolute_reverse('metadata'), compose_preseed(node))
 
     def test_compose_preseed_for_commissioning_includes_metadata_url(self):
         node = factory.make_node(status=NODE_STATUS.COMMISSIONING)
         preseed = yaml.safe_load(compose_preseed(node))
         self.assertEqual(
-            get_metadata_server_url(),
+            absolute_reverse('metadata'),
             preseed['datasource']['MAAS']['metadata_url'])
 
     def test_compose_preseed_includes_node_oauth_token(self):