From: Zhongyue Luo Date: Tue, 14 May 2013 09:17:46 +0000 (+0800) Subject: Hide lock_prefix argument using synchronized_with_prefix() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ae779e4bf761d2fd1df85d71c412c3d963be021b;p=openstack-build%2Fneutron-build.git Hide lock_prefix argument using synchronized_with_prefix() 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 --- diff --git a/quantum/agent/dhcp_agent.py b/quantum/agent/dhcp_agent.py index 88d6e442a..210bbe1af 100644 --- a/quantum/agent/dhcp_agent.py +++ b/quantum/agent/dhcp_agent.py @@ -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']) diff --git a/quantum/agent/linux/iptables_manager.py b/quantum/agent/linux/iptables_manager.py index b65dcba35..4ab6e23fc 100644 --- a/quantum/agent/linux/iptables_manager.py +++ b/quantum/agent/linux/iptables_manager.py @@ -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. diff --git a/quantum/common/utils.py b/quantum/common/utils.py index 647f38ea2..afeae56cc 100644 --- a/quantum/common/utils.py +++ b/quantum/common/utils.py @@ -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. diff --git a/quantum/manager.py b/quantum/manager.py index 408ce0d67..eb8b2caec 100644 --- a/quantum/manager.py +++ b/quantum/manager.py @@ -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() diff --git a/quantum/plugins/bigswitch/plugin.py b/quantum/plugins/bigswitch/plugin.py index c5d9e46af..0a53849f1 100644 --- a/quantum/plugins/bigswitch/plugin.py +++ b/quantum/plugins/bigswitch/plugin.py @@ -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)