]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Hide lock_prefix argument using synchronized_with_prefix()
authorZhongyue Luo <zhongyue.nah@intel.com>
Tue, 14 May 2013 09:17:46 +0000 (17:17 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Mon, 10 Jun 2013 08:09:29 +0000 (16:09 +0800)
The lockfile module has a new convenience API which sets the lockfile prefix.
Using this API, the prefix is not required everytime synchronized is used.
This enables for projects to have consistant prefixes on their lockfiles

Change-Id: I4bc3f28a9ed2a6e2438a90f163bbde081211062c

quantum/agent/dhcp_agent.py
quantum/agent/linux/iptables_manager.py
quantum/common/utils.py
quantum/manager.py
quantum/plugins/bigswitch/plugin.py

index 88d6e442a11cdf3d644863c4d34265deac61f527..210bbe1afa4957887b3ff4e82c343ef10e1fc6cc 100644 (file)
@@ -32,11 +32,11 @@ from quantum.agent import rpc as agent_rpc
 from quantum.common import constants
 from quantum.common import exceptions
 from quantum.common import topics
+from quantum.common import utils
 from quantum import context
 from quantum import manager
 from quantum.openstack.common import importutils
 from quantum.openstack.common import jsonutils
-from quantum.openstack.common import lockutils
 from quantum.openstack.common import log as logging
 from quantum.openstack.common import loopingcall
 from quantum.openstack.common.rpc import proxy
@@ -230,13 +230,13 @@ class DhcpAgent(manager.Manager):
         else:
             self.disable_dhcp_helper(network.id)
 
-    @lockutils.synchronized('agent', 'dhcp-')
+    @utils.synchronized('dhcp-agent')
     def network_create_end(self, context, payload):
         """Handle the network.create.end notification event."""
         network_id = payload['network']['id']
         self.enable_dhcp_helper(network_id)
 
-    @lockutils.synchronized('agent', 'dhcp-')
+    @utils.synchronized('dhcp-agent')
     def network_update_end(self, context, payload):
         """Handle the network.update.end notification event."""
         network_id = payload['network']['id']
@@ -245,12 +245,12 @@ class DhcpAgent(manager.Manager):
         else:
             self.disable_dhcp_helper(network_id)
 
-    @lockutils.synchronized('agent', 'dhcp-')
+    @utils.synchronized('dhcp-agent')
     def network_delete_end(self, context, payload):
         """Handle the network.delete.end notification event."""
         self.disable_dhcp_helper(payload['network_id'])
 
-    @lockutils.synchronized('agent', 'dhcp-')
+    @utils.synchronized('dhcp-agent')
     def subnet_update_end(self, context, payload):
         """Handle the subnet.update.end notification event."""
         network_id = payload['subnet']['network_id']
@@ -259,7 +259,7 @@ class DhcpAgent(manager.Manager):
     # Use the update handler for the subnet create event.
     subnet_create_end = subnet_update_end
 
-    @lockutils.synchronized('agent', 'dhcp-')
+    @utils.synchronized('dhcp-agent')
     def subnet_delete_end(self, context, payload):
         """Handle the subnet.delete.end notification event."""
         subnet_id = payload['subnet_id']
@@ -267,7 +267,7 @@ class DhcpAgent(manager.Manager):
         if network:
             self.refresh_dhcp_helper(network.id)
 
-    @lockutils.synchronized('agent', 'dhcp-')
+    @utils.synchronized('dhcp-agent')
     def port_update_end(self, context, payload):
         """Handle the port.update.end notification event."""
         port = DictModel(payload['port'])
@@ -279,7 +279,7 @@ class DhcpAgent(manager.Manager):
     # Use the update handler for the port create event.
     port_create_end = port_update_end
 
-    @lockutils.synchronized('agent', 'dhcp-')
+    @utils.synchronized('dhcp-agent')
     def port_delete_end(self, context, payload):
         """Handle the port.delete.end notification event."""
         port = self.cache.get_port_by_id(payload['port_id'])
index b65dcba35882f6413d70707ae4c2de16ad33ab88..4ab6e23fcac01fc80248ec034445336034e377e1 100644 (file)
@@ -24,8 +24,8 @@
 import inspect
 import os
 
-from quantum.agent.linux import utils
-from quantum.openstack.common import lockutils
+from quantum.agent.linux import utils as linux_utils
+from quantum.common import utils
 from quantum.openstack.common import log as logging
 
 LOG = logging.getLogger(__name__)
@@ -228,7 +228,7 @@ class IptablesManager(object):
         if _execute:
             self.execute = _execute
         else:
-            self.execute = utils.execute
+            self.execute = linux_utils.execute
 
         self.use_ipv6 = use_ipv6
         self.root_helper = root_helper
@@ -307,7 +307,7 @@ class IptablesManager(object):
 
         self._apply()
 
-    @lockutils.synchronized('iptables', 'quantum-', external=True)
+    @utils.synchronized('iptables', external=True)
     def _apply(self):
         """Apply the current in-memory set of iptables rules.
 
index 647f38ea2eb624a1cc1b621e070ebc9f35d3c2c6..afeae56cc40e5b6f4dbcbb55a68c8672a9086e72 100644 (file)
@@ -30,12 +30,15 @@ from eventlet.green import subprocess
 from oslo.config import cfg
 
 from quantum.common import constants as q_const
+from quantum.openstack.common import lockutils
 from quantum.openstack.common import log as logging
 
 
 TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
 LOG = logging.getLogger(__name__)
 
+synchronized = lockutils.synchronized_with_prefix('quantum-')
+
 
 def read_cached_file(filename, cache_info, reload_func=None):
     """Read from a file if it has been modified.
index 408ce0d67fe474530257272f7e9d12422473b86a..eb8b2caece229b0f935a9459c81086d38be145cf 100644 (file)
@@ -18,8 +18,8 @@
 
 from oslo.config import cfg
 
+from quantum.common import utils
 from quantum.openstack.common import importutils
-from quantum.openstack.common import lockutils
 from quantum.openstack.common import log as logging
 from quantum.openstack.common import periodic_task
 from quantum.plugins.common import constants
@@ -183,7 +183,7 @@ class QuantumManager(object):
                        "desc": plugin_inst.get_plugin_description()})
 
     @classmethod
-    @lockutils.synchronized("qmlock", "qml-")
+    @utils.synchronized("manager")
     def _create_instance(cls):
         if cls._instance is None:
             cls._instance = cls()
index c5d9e46af065a765a636da7ef751be9d69d73f52..0a53849f129abb6e5fbcbba3300cc3a37d6cf95e 100644 (file)
@@ -65,7 +65,6 @@ from quantum.db import dhcp_rpc_base
 from quantum.db import l3_db
 from quantum.extensions import l3
 from quantum.extensions import portbindings
-from quantum.openstack.common import lockutils
 from quantum.openstack.common import log as logging
 from quantum.openstack.common import rpc
 from quantum.plugins.bigswitch.version import version_string_with_vcs
@@ -160,7 +159,7 @@ class ServerProxy(object):
         if auth:
             self.auth = 'Basic ' + base64.encodestring(auth).strip()
 
-    @lockutils.synchronized('rest_call', 'bsn-', external=True)
+    @utils.synchronized('bsn-rest-call', external=True)
     def rest_call(self, action, resource, data, headers):
         uri = self.base_uri + resource
         body = json.dumps(data)