Merge lp:~allenap/maas/preseed-cluster-host into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 1458
Proposed branch: lp:~allenap/maas/preseed-cluster-host
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 88 lines (+41/-5)
2 files modified
src/maasserver/preseed.py (+8/-1)
src/maasserver/tests/test_preseed.py (+33/-4)
To merge this branch: bzr merge lp:~allenap/maas/preseed-cluster-host
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Needs Fixing
Julian Edwards (community) Approve
Review via email: mp+149954@code.launchpad.net

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.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

I've realised that cluster_host can already be derived in the preseed environment:

  node.get_managed_interface().ip

This is less convenient, but it works right now, and doesn't require backporting.

Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Gavin,

I don't think that node.get_managed_interface() exists right? Shouldn't it be nodegroup.get_managed_interface().ip? I'm guessing this is being handled automatically for each of the cluster controllers as in it provides the IP of the cluster controller from which the node is trying to install from right?

Revision history for this message
Andres Rodriguez (andreserl) wrote :

Ok I have tested this in a single node MAAS and it seems to work like a charm. The node.nodegroup.get_managed_interface().ip didn't really work.

Revision history for this message
Andres Rodriguez (andreserl) wrote :

No my bad... this doesn't work unfortunately... we need the IP of the cluster node regardless of whether we are managing an interface or not .... (I think that's why it doesn't work).

Revision history for this message
Julian Edwards (julian-edwards) :
review: Approve
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Forgot to add the needs fixing since it doesn't work :(

review: Needs Fixing
Revision history for this message
Julian Edwards (julian-edwards) wrote :

On 05/03/13 14:20, Andres Rodriguez wrote:
> Review: Needs Fixing
>
> Forgot to add the needs fixing since it doesn't work :(
>

I approved on the basis that the branch itself is fine to land, even
though your particular problem is not fixed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:39:27 +0000
@@ -225,7 +225,13 @@
225 Config.objects.get_config('main_archive'))225 Config.objects.get_config('main_archive'))
226 ports_archive_hostname, ports_archive_directory = get_hostname_and_path(226 ports_archive_hostname, ports_archive_directory = get_hostname_and_path(
227 Config.objects.get_config('ports_archive'))227 Config.objects.get_config('ports_archive'))
228 base_url = nodegroup.maas_url if nodegroup is not None else None228 if nodegroup is None:
229 base_url = None
230 cluster_host = None
231 else:
232 base_url = nodegroup.maas_url
233 cluster_if = nodegroup.get_managed_interface()
234 cluster_host = None if cluster_if is None else cluster_if.ip
229 return {235 return {
230 'main_archive_hostname': main_archive_hostname,236 'main_archive_hostname': main_archive_hostname,
231 'main_archive_directory': main_archive_directory,237 'main_archive_directory': main_archive_directory,
@@ -236,6 +242,7 @@
236 'server_url': absolute_reverse('nodes_handler', base_url=base_url),242 'server_url': absolute_reverse('nodes_handler', base_url=base_url),
237 'metadata_enlist_url': absolute_reverse('enlist', base_url=base_url),243 'metadata_enlist_url': absolute_reverse('enlist', base_url=base_url),
238 'http_proxy': Config.objects.get_config('http_proxy'),244 'http_proxy': Config.objects.get_config('http_proxy'),
245 'cluster_host': cluster_host,
239 }246 }
240247
241248
242249
=== 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:39:27 +0000
@@ -21,6 +21,7 @@
21from maasserver.enum import (21from maasserver.enum import (
22 ARCHITECTURE,22 ARCHITECTURE,
23 NODE_STATUS,23 NODE_STATUS,
24 NODEGROUPINTERFACE_MANAGEMENT,
24 PRESEED_TYPE,25 PRESEED_TYPE,
25 )26 )
26from maasserver.models import Config27from maasserver.models import Config
@@ -327,10 +328,9 @@
327 context = get_preseed_context(release, nodegroup)328 context = get_preseed_context(release, nodegroup)
328 self.assertItemsEqual(329 self.assertItemsEqual(
329 ['release', 'metadata_enlist_url', 'server_host', 'server_url',330 ['release', 'metadata_enlist_url', 'server_host', 'server_url',
330 'main_archive_hostname', 'main_archive_directory',331 'cluster_host', 'main_archive_hostname', 'main_archive_directory',
331 'ports_archive_hostname', 'ports_archive_directory',332 'ports_archive_hostname', 'ports_archive_directory',
332 'http_proxy',333 'http_proxy'],
333 ],
334 context)334 context)
335335
336 def test_get_preseed_context_archive_refs(self):336 def test_get_preseed_context_archive_refs(self):
@@ -358,6 +358,35 @@
358 context['ports_archive_directory'],358 context['ports_archive_directory'],
359 ))359 ))
360360
361 def test_preseed_context_cluster_host(self):
362 # The cluster_host context variable is derived from the nodegroup.
363 release = factory.getRandomString()
364 nodegroup = factory.make_node_group(maas_url=factory.getRandomString())
365 context = get_preseed_context(release, nodegroup)
366 self.assertIsNotNone(context["cluster_host"])
367 self.assertEqual(
368 nodegroup.get_managed_interface().ip,
369 context["cluster_host"])
370
371 def test_preseed_context_null_cluster_host_if_unmanaged(self):
372 # If the nodegroup has no managed interface recorded, which is
373 # possible in the data model but would be a bit weird, the
374 # cluster_host context variable is present, but None.
375 release = factory.getRandomString()
376 nodegroup = factory.make_node_group(maas_url=factory.getRandomString())
377 for interface in nodegroup.nodegroupinterface_set.all():
378 interface.management = NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED
379 interface.save()
380 context = get_preseed_context(release, nodegroup)
381 self.assertIsNone(context["cluster_host"])
382
383 def test_preseed_context_null_cluster_host_if_does_not_exist(self):
384 # If there's no nodegroup, the cluster_host context variable is
385 # present, but None.
386 release = factory.getRandomString()
387 context = get_preseed_context(release)
388 self.assertIsNone(context["cluster_host"])
389
361390
362class TestNodePreseedContext(TestCase):391class TestNodePreseedContext(TestCase):
363 """Tests for `get_node_preseed_context`."""392 """Tests for `get_node_preseed_context`."""