← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/batch-omshell-updates into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/batch-omshell-updates into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jtv/maas/batch-omshell-updates/+merge/118534

A very simple preparatory change, as mentioned in the call.  It will make registration of DHCP leases more easily scalable by making requests naturally batch-oriented, and save Omshell process from having to fork an external process for every single lease.  Plus, it's just very very simple to do.

The ip→mac dict is the same representation as used consistently in lease parsing and updates elsewhere.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/batch-omshell-updates/+merge/118534
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/batch-omshell-updates into lp:maas.
=== modified file 'src/provisioningserver/tasks.py'
--- src/provisioningserver/tasks.py	2012-08-02 10:55:49 +0000
+++ src/provisioningserver/tasks.py	2012-08-07 11:04:27 +0000
@@ -172,18 +172,19 @@
 
 
 @task
-def add_new_dhcp_host_map(ip_address, mac_address, server_address, shared_key):
-    """Add a MAC to IP mapping in the DHCP server.
+def add_new_dhcp_host_map(mappings, server_address, shared_key):
+    """Add address mappings to the DHCP server.
 
-    :param ip_address: Dotted quad string
-    :param mac_address: Colon-separated hex string, e.g. aa:bb:cc:dd:ee:ff
+    :param mappings: A dict of new IP addresses, and the MAC addreses they
+        translate to.
     :param server_address: IP or hostname for the DHCP server
     :param shared_key: The HMAC-MD5 key that the DHCP server uses for access
         control.
     """
     omshell = Omshell(server_address, shared_key)
     try:
-        omshell.create(ip_address, mac_address)
+        for ip_address, mac_address in mappings.items():
+            omshell.create(ip_address, mac_address)
     except CalledProcessError:
         # TODO signal to webapp that the job failed.
 

=== modified file 'src/provisioningserver/tests/test_tasks.py'
--- src/provisioningserver/tests/test_tasks.py	2012-08-02 10:55:49 +0000
+++ src/provisioningserver/tests/test_tasks.py	2012-08-07 11:04:27 +0000
@@ -108,7 +108,7 @@
         key = factory.getRandomString()
         recorder = FakeMethod(result=(0, "hardware-type"))
         self.patch(Omshell, '_run', recorder)
-        add_new_dhcp_host_map.delay(ip, mac, server_address, key)
+        add_new_dhcp_host_map.delay({ip: mac}, server_address, key)
 
         self.assertRecordedStdin(recorder, ip, mac, server_address, key)
 
@@ -122,7 +122,7 @@
         self.patch(Omshell, '_run', FakeMethod(result=(0, "this_will_fail")))
         self.assertRaises(
             CalledProcessError, add_new_dhcp_host_map.delay,
-            ip, mac, server_address, key)
+            {mac: ip}, server_address, key)
 
     def test_remove_dhcp_host_map(self):
         # We don't want to actually run omshell in the task, so we stub


Follow ups