← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/beat-update-leases into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/beat-update-leases into lp:maas.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~jtv/maas/beat-update-leases/+merge/121056

Julian says he would like to have the worker upload DHCP leases to the server about once a minute, for starters.  In this branch I set up the beat scheduler (adding the --beat option to celeryd, which will conflict with another branch where I change that same line) to do exactly that.  We could do it more frequently later, in which case we may want to start using the caching mechanism in update_leases (as opposed to upload_leases, which uploads unconditionally).  Then again, if 1-minute resolution is good enough, we may drop update_leases altogether — along with some of the caching logic, I think.

This branch is mostly configuration, which makes it hard to reach for automated tests.  I eyeballed the uploads in action though.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/beat-update-leases/+merge/121056
Your team MAAS Maintainers is requested to review the proposed merge of lp:~jtv/maas/beat-update-leases into lp:maas.
=== modified file 'src/provisioningserver/tasks.py'
--- src/provisioningserver/tasks.py	2012-08-20 11:15:44 +0000
+++ src/provisioningserver/tasks.py	2012-08-23 17:04:17 +0000
@@ -36,6 +36,7 @@
     record_nodegroup_name,
     )
 from provisioningserver.dhcp import config
+from provisioningserver.dhcp.leases import upload_leases
 from provisioningserver.dns.config import (
     DNSConfig,
     execute_rndc_command,
@@ -245,6 +246,16 @@
 
 
 @task
+def upload_dhcp_leases():
+    """Upload DHCP leases.
+
+    Uploads leases to the MAAS API, using cached credentials -- the task
+    originates with celerybeat, not with a server request.
+    """
+    upload_leases()
+
+
+@task
 def add_new_dhcp_host_map(mappings, server_address, shared_key):
     """Add address mappings to the DHCP server.
 

=== modified file 'src/provisioningserver/tests/test_tasks.py'
--- src/provisioningserver/tests/test_tasks.py	2012-08-23 08:16:14 +0000
+++ src/provisioningserver/tests/test_tasks.py	2012-08-23 17:04:17 +0000
@@ -12,6 +12,7 @@
 __metaclass__ = type
 __all__ = []
 
+from datetime import datetime
 import os
 import random
 from subprocess import CalledProcessError
@@ -24,12 +25,14 @@
     MultiFakeMethod,
     )
 from maastesting.matchers import ContainsAll
+from mock import Mock
 from netaddr import IPNetwork
 from provisioningserver import (
     auth,
     tasks,
     )
 from provisioningserver.cache import cache
+from provisioningserver.dhcp import leases
 from provisioningserver.dns.config import (
     conf,
     DNSZoneConfig,
@@ -148,6 +151,14 @@
             recorder.extract_args()[0][0],
             ContainsAll(args))
 
+    def test_upload_dhcp_leases(self):
+        self.patch(
+            leases, 'parse_leases_file',
+            Mock(return_value=(datetime.utcnow(), {})))
+        self.patch(leases, 'process_leases', Mock())
+        tasks.upload_dhcp_leases.delay()
+        self.assertEqual(1, leases.process_leases.call_count)
+
     def test_add_new_dhcp_host_map(self):
         # We don't want to actually run omshell in the task, so we stub
         # out the wrapper class's _run method and record what it would