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
This commit is contained in:
Zhongyue Luo 2013-05-14 17:17:46 +08:00
parent ff50266427
commit ae779e4bf7
5 changed files with 18 additions and 16 deletions

View 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'])

View 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.

View 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.

View 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()

View 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)