← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/api-maas-import-pxe-files into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/api-maas-import-pxe-files into lp:maas with lp:~rvb/maas/sudo-mipf as a prerequisite.

Commit message:
Add method on nodegroup to call the task import_pxe_files.  Use the proxy defined in the settings.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/api-maas-import-pxe-files/+merge/132912

= Notes =

I considered patching the task itself instead of patching 'check_call' but it didn't buy anything in terms of SLOC so I decided to go by the book and test the behavior.
-- 
https://code.launchpad.net/~rvb/maas/api-maas-import-pxe-files/+merge/132912
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/api-maas-import-pxe-files into lp:maas.
=== modified file 'src/maasserver/models/nodegroup.py'
--- src/maasserver/models/nodegroup.py	2012-10-29 11:36:40 +0000
+++ src/maasserver/models/nodegroup.py	2012-11-05 15:37:19 +0000
@@ -36,7 +36,10 @@
     Token,
     )
 from provisioningserver.omshell import generate_omapi_key
-from provisioningserver.tasks import add_new_dhcp_host_map
+from provisioningserver.tasks import (
+    add_new_dhcp_host_map,
+    import_pxe_files,
+    )
 
 
 class NodeGroupManager(Manager):
@@ -221,6 +224,17 @@
         """The name of the queue for tasks specific to this nodegroup."""
         return self.uuid
 
+    def import_pxe_files(self):
+        """Import the pxe files on this cluster controller.
+
+        The files are downloaded through the proxy defined in the config
+        setting 'http_proxy' if defined.
+        """
+        # Avoid circular imports.
+        from maasserver.models import Config
+        task_kwargs = dict(http_proxy=Config.objects.get_config('http_proxy'))
+        import_pxe_files.apply_async(queue=self.uuid, kwargs=task_kwargs)
+
     def add_dhcp_host_maps(self, new_leases):
         if self.get_managed_interface() is not None and len(new_leases) > 0:
             # XXX JeroenVermeulen 2012-08-21, bug=1039362: the DHCP

=== modified file 'src/maasserver/tests/test_nodegroup.py'
--- src/maasserver/tests/test_nodegroup.py	2012-10-15 07:13:29 +0000
+++ src/maasserver/tests/test_nodegroup.py	2012-11-05 15:37:19 +0000
@@ -12,6 +12,8 @@
 __metaclass__ = type
 __all__ = []
 
+import os
+
 from django.db.models.signals import post_save
 import django.dispatch
 from maasserver.enum import (
@@ -19,6 +21,7 @@
     NODEGROUPINTERFACE_MANAGEMENT,
     )
 from maasserver.models import (
+    Config,
     NodeGroup,
     nodegroup as nodegroup_module,
     )
@@ -33,6 +36,7 @@
     call,
     Mock,
     )
+from provisioningserver import tasks
 from provisioningserver.omshell import (
     generate_omapi_key,
     Omshell,
@@ -341,3 +345,13 @@
         nodegroup1.ensure_dhcp_key()
         nodegroup2.ensure_dhcp_key()
         self.assertNotEqual(nodegroup1.dhcp_key, nodegroup2.dhcp_key)
+
+    def test_import_pxe_files_calls_script_with_proxy(self):
+        recorder = self.patch(tasks, 'check_call', Mock())
+        proxy = factory.make_name('proxy')
+        Config.objects.set_config('http_proxy', proxy)
+        nodegroup = factory.make_node_group()
+        nodegroup.import_pxe_files()
+        expected_env = dict(os.environ, http_proxy=proxy, https_proxy=proxy)
+        recorder.assert_called_once_with(
+            ['sudo', '-n', 'maas-import-pxe-files'], env=expected_env)