← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/preseed-cluster-host into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/preseed-cluster-host into lp:maas.

Commit message:
Include a 'cluster_host' setting in the preseed template rendering context.

This is set to the IP address of the first managed interface of the cluster.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/preseed-cluster-host/+merge/149954
-- 
https://code.launchpad.net/~allenap/maas/preseed-cluster-host/+merge/149954
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/preseed-cluster-host into lp:maas.
=== modified file 'src/maasserver/preseed.py'
--- src/maasserver/preseed.py	2012-11-27 10:39:51 +0000
+++ src/maasserver/preseed.py	2013-02-21 23:34:24 +0000
@@ -225,7 +225,13 @@
         Config.objects.get_config('main_archive'))
     ports_archive_hostname, ports_archive_directory = get_hostname_and_path(
         Config.objects.get_config('ports_archive'))
-    base_url = nodegroup.maas_url if nodegroup is not None else None
+    if nodegroup is None:
+        base_url = None
+        cluster_host = None
+    else:
+        base_url = nodegroup.maas_url
+        cluster_if = nodegroup.get_managed_interface()
+        cluster_host = None if cluster_if is None else cluster_if.ip
     return {
         'main_archive_hostname': main_archive_hostname,
         'main_archive_directory': main_archive_directory,
@@ -236,6 +242,7 @@
         'server_url': absolute_reverse('nodes_handler', base_url=base_url),
         'metadata_enlist_url': absolute_reverse('enlist', base_url=base_url),
         'http_proxy': Config.objects.get_config('http_proxy'),
+        'cluster_host': cluster_host,
         }
 
 

=== modified file 'src/maasserver/tests/test_preseed.py'
--- src/maasserver/tests/test_preseed.py	2012-11-27 10:26:19 +0000
+++ src/maasserver/tests/test_preseed.py	2013-02-21 23:34:24 +0000
@@ -21,6 +21,7 @@
 from maasserver.enum import (
     ARCHITECTURE,
     NODE_STATUS,
+    NODEGROUPINTERFACE_MANAGEMENT,
     PRESEED_TYPE,
     )
 from maasserver.models import Config
@@ -327,10 +328,9 @@
         context = get_preseed_context(release, nodegroup)
         self.assertItemsEqual(
             ['release', 'metadata_enlist_url', 'server_host', 'server_url',
-            'main_archive_hostname', 'main_archive_directory',
-            'ports_archive_hostname', 'ports_archive_directory',
-            'http_proxy',
-            ],
+             'cluster_host', 'main_archive_hostname', 'main_archive_directory',
+             'ports_archive_hostname', 'ports_archive_directory',
+             'http_proxy'],
             context)
 
     def test_get_preseed_context_archive_refs(self):
@@ -358,6 +358,35 @@
                 context['ports_archive_directory'],
             ))
 
+    def test_preseed_context_cluster_host(self):
+        # The cluster_host context variable is derived from the nodegroup.
+        release = factory.getRandomString()
+        nodegroup = factory.make_node_group(maas_url=factory.getRandomString())
+        context = get_preseed_context(release, nodegroup)
+        self.assertIsNotNone(context["cluster_host"])
+        self.assertEqual(
+            nodegroup.get_managed_interface().ip,
+            context["cluster_host"])
+
+    def test_preseed_context_null_cluster_host_if_unmanaged(self):
+        # If the nodegroup has no managed interface recorded, which is
+        # possible in the data model but would be a bit weird, the
+        # cluster_host context variable is present, but None.
+        release = factory.getRandomString()
+        nodegroup = factory.make_node_group(maas_url=factory.getRandomString())
+        for interface in nodegroup.nodegroupinterface_set.all():
+            interface.management = NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED
+            interface.save()
+        context = get_preseed_context(release, nodegroup)
+        self.assertIsNone(context["cluster_host"])
+
+    def test_preseed_context_null_cluster_host_if_does_not_exist(self):
+        # If there's no nodegroup, the cluster_host context variable is
+        # present, but None.
+        release = factory.getRandomString()
+        context = get_preseed_context(release)
+        self.assertIsNone(context["cluster_host"])
+
 
 class TestNodePreseedContext(TestCase):
     """Tests for `get_node_preseed_context`."""


Follow ups