← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/shorter-cache-key-name into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/shorter-cache-key-name into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jtv/maas/shorter-cache-key-name/+merge/120049

This is just for my immediate convenience, and perhaps the sanity of my reviewer on the next branch who won't want to see all these tiny loosely-related changes added to the diff.

Speaking of diff size, don't let it intimidate you: it's a very simple and consistent auto-pilot change.  Plus there were one or two places where lines were sufficiently shortened to improve formatting.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/shorter-cache-key-name/+merge/120049
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/shorter-cache-key-name into lp:maas.
=== modified file 'src/provisioningserver/auth.py'
--- src/provisioningserver/auth.py	2012-08-14 15:02:25 +0000
+++ src/provisioningserver/auth.py	2012-08-17 03:52:18 +0000
@@ -21,12 +21,11 @@
 from apiclient.creds import convert_string_to_tuple
 from provisioningserver.cache import cache
 
-
 # Cache key for the API credentials as last sent by the server.
-API_CREDENTIALS_KEY_CACHE_NAME = 'api_credentials'
+API_CREDENTIALS_CACHE_KEY = 'api_credentials'
 
 # Cache key for the name of the nodegroup that this worker manages.
-RECORDED_NODEGROUP_NAME_KEY_CACHE_NAME = 'nodegroup_name'
+RECORDED_NODEGROUP_NAME_CACHE_KEY = 'nodegroup_name'
 
 
 def locate_maas_api():
@@ -42,7 +41,7 @@
         a single string: consumer key, resource token, and resource seret
         separated by colons.
     """
-    cache.set(API_CREDENTIALS_KEY_CACHE_NAME, api_credentials)
+    cache.set(API_CREDENTIALS_CACHE_KEY, api_credentials)
 
 
 def get_recorded_api_credentials():
@@ -52,7 +51,7 @@
         (consumer_key, resource_token, resource_secret) as expected by
         :class:`MAASOauth`.  Otherwise, None.
     """
-    credentials_string = cache.get(API_CREDENTIALS_KEY_CACHE_NAME)
+    credentials_string = cache.get(API_CREDENTIALS_CACHE_KEY)
     if credentials_string is None:
         return None
     else:
@@ -61,7 +60,7 @@
 
 def record_nodegroup_name(nodegroup_name):
     """Record the name of the nodegroup we manage, as sent by the server."""
-    cache.set(RECORDED_NODEGROUP_NAME_KEY_CACHE_NAME, nodegroup_name)
+    cache.set(RECORDED_NODEGROUP_NAME_CACHE_KEY, nodegroup_name)
 
 
 def get_recorded_nodegroup_name():
@@ -69,4 +68,4 @@
 
     If the server has not sent the name yet, returns None.
     """
-    return cache.get(RECORDED_NODEGROUP_NAME_KEY_CACHE_NAME)
+    return cache.get(RECORDED_NODEGROUP_NAME_CACHE_KEY)

=== modified file 'src/provisioningserver/dhcp/leases.py'
--- src/provisioningserver/dhcp/leases.py	2012-08-14 15:05:18 +0000
+++ src/provisioningserver/dhcp/leases.py	2012-08-17 03:52:18 +0000
@@ -53,20 +53,20 @@
 from provisioningserver.logging import task_logger
 
 # Cache key for the modification time on last-processed leases file.
-LEASES_TIME_KEY_CACHE_NAME = 'leases_time'
+LEASES_TIME_CACHE_KEY = 'leases_time'
 
 
 # Cache key for the leases as last parsed.
-LEASES_KEY_CACHE_NAME = 'recorded_leases'
+LEASES_CACHE_KEY = 'recorded_leases'
 
 
 # Cache key for the shared key for use with omshell.
-OMAPI_SHARED_KEY_CACHE_NAME = 'omapi_shared_key'
+OMAPI_SHARED_CACHE_KEY = 'omapi_shared_key'
 
 
 def record_omapi_shared_key(shared_key):
     """Record the OMAPI shared key as received from the server."""
-    cache.set(OMAPI_SHARED_KEY_CACHE_NAME, shared_key)
+    cache.set(OMAPI_SHARED_CACHE_KEY, shared_key)
 
 
 def get_leases_timestamp():
@@ -91,8 +91,8 @@
     # These variables are shared between threads.  A bit of
     # inconsistency due to concurrent updates is not a problem, but read
     # them both at once here to reduce the scope for trouble.
-    previous_leases = cache.get(LEASES_KEY_CACHE_NAME)
-    previous_leases_time = cache.get(LEASES_TIME_KEY_CACHE_NAME)
+    previous_leases = cache.get(LEASES_CACHE_KEY)
+    previous_leases_time = cache.get(LEASES_TIME_CACHE_KEY)
 
     if get_leases_timestamp() == previous_leases_time:
         return None
@@ -111,8 +111,8 @@
     :param leases: A dict mapping each leased IP address to the MAC address
         that it has been assigned to.
     """
-    cache.set(LEASES_TIME_KEY_CACHE_NAME, last_change)
-    cache.set(LEASES_KEY_CACHE_NAME, leases)
+    cache.set(LEASES_TIME_CACHE_KEY, last_change)
+    cache.set(LEASES_CACHE_KEY, leases)
 
 
 def identify_new_leases(current_leases):
@@ -123,7 +123,7 @@
     """
     # The recorded leases is shared between threads.  Read it
     # just once to reduce the impact of concurrent changes.
-    previous_leases = cache.get(LEASES_KEY_CACHE_NAME)
+    previous_leases = cache.get(LEASES_CACHE_KEY)
     if previous_leases is None:
         return current_leases
     else:
@@ -143,7 +143,7 @@
 
     # The recorded_omapi_shared_key is shared between threads, so read
     # it just once, atomically.
-    omapi_key = cache.get(OMAPI_SHARED_KEY_CACHE_NAME)
+    omapi_key = cache.get(OMAPI_SHARED_CACHE_KEY)
     if omapi_key is None:
         task_logger.info(
             "Not registering new leases: "

=== modified file 'src/provisioningserver/dhcp/tests/test_leases.py'
--- src/provisioningserver/dhcp/tests/test_leases.py	2012-08-16 13:39:14 +0000
+++ src/provisioningserver/dhcp/tests/test_leases.py	2012-08-17 03:52:18 +0000
@@ -30,9 +30,9 @@
 from provisioningserver.dhcp.leases import (
     check_lease_changes,
     identify_new_leases,
-    LEASES_KEY_CACHE_NAME,
-    LEASES_TIME_KEY_CACHE_NAME,
-    OMAPI_SHARED_KEY_CACHE_NAME,
+    LEASES_CACHE_KEY,
+    LEASES_TIME_CACHE_KEY,
+    OMAPI_SHARED_CACHE_KEY,
     parse_leases_file,
     process_leases,
     record_lease_state,
@@ -52,17 +52,15 @@
     def test_record_omapi_shared_key_records_shared_key(self):
         key = factory.getRandomString()
         record_omapi_shared_key(key)
-        self.assertEqual(key, cache.get(OMAPI_SHARED_KEY_CACHE_NAME))
+        self.assertEqual(key, cache.get(OMAPI_SHARED_CACHE_KEY))
 
     def test_record_lease_state_records_time_and_leases(self):
         time = datetime.utcnow()
         leases = {factory.getRandomIPAddress(): factory.getRandomMACAddress()}
         record_lease_state(time, leases)
         self.assertEqual(
-            (time, leases), (
-                cache.get(LEASES_TIME_KEY_CACHE_NAME),
-                cache.get(LEASES_KEY_CACHE_NAME),
-                ))
+            (time, leases),
+            (cache.get(LEASES_TIME_CACHE_KEY), cache.get(LEASES_CACHE_KEY)))
 
 
 class StopExecuting(BaseException):
@@ -124,7 +122,7 @@
         """Set a recorded omapi key for the duration of this test."""
         if key is None:
             key = factory.getRandomString()
-        cache.set(OMAPI_SHARED_KEY_CACHE_NAME, key)
+        cache.set(OMAPI_SHARED_CACHE_KEY, key)
 
     def set_nodegroup_name(self):
         """Set the recorded nodegroup name for the duration of this test."""
@@ -145,8 +143,8 @@
         state so that it gets reset at the end of the test.  Using this will
         prevent recorded lease state from leaking into other tests.
         """
-        cache.set(LEASES_TIME_KEY_CACHE_NAME, time)
-        cache.set(LEASES_KEY_CACHE_NAME, leases)
+        cache.set(LEASES_TIME_CACHE_KEY, time)
+        cache.set(LEASES_CACHE_KEY, leases)
 
     def test_record_lease_state_sets_leases_and_timestamp(self):
         time = datetime.utcnow()
@@ -154,10 +152,8 @@
         self.set_lease_state()
         record_lease_state(time, leases)
         self.assertEqual(
-            (time, leases), (
-                cache.get(LEASES_TIME_KEY_CACHE_NAME),
-                cache.get(LEASES_KEY_CACHE_NAME),
-                ))
+            (time, leases),
+            (cache.get(LEASES_TIME_CACHE_KEY), cache.get(LEASES_CACHE_KEY)))
 
     def test_check_lease_changes_returns_tuple_if_no_state_cached(self):
         self.set_lease_state()
@@ -336,7 +332,7 @@
         old_leases = {
             factory.getRandomIPAddress(): factory.getRandomMACAddress(),
         }
-        cache.set(LEASES_KEY_CACHE_NAME, old_leases)
+        cache.set(LEASES_CACHE_KEY, old_leases)
         new_leases = {
             factory.getRandomIPAddress(): factory.getRandomMACAddress(),
         }

=== modified file 'src/provisioningserver/tests/test_auth.py'
--- src/provisioningserver/tests/test_auth.py	2012-08-16 13:39:14 +0000
+++ src/provisioningserver/tests/test_auth.py	2012-08-17 03:52:18 +0000
@@ -34,7 +34,7 @@
         creds_string = convert_tuple_to_string(make_credentials())
         auth.record_api_credentials(creds_string)
         self.assertEqual(
-            creds_string, cache.get(auth.API_CREDENTIALS_KEY_CACHE_NAME))
+            creds_string, cache.get(auth.API_CREDENTIALS_CACHE_KEY))
 
     def test_get_recorded_api_credentials_returns_credentials_as_tuple(self):
         creds = make_credentials()


Follow ups