Merge "Make NeutronOvsdbIdl singleton" into stable/train
This commit is contained in:
commit
dc2ed5adc9
|
@ -22,6 +22,7 @@ from ovsdbapp.backend.ovs_idl import vlog
|
||||||
from ovsdbapp.schema.open_vswitch import impl_idl
|
from ovsdbapp.schema.open_vswitch import impl_idl
|
||||||
|
|
||||||
from neutron.agent.ovsdb.native import connection as n_connection
|
from neutron.agent.ovsdb.native import connection as n_connection
|
||||||
|
from neutron.common import utils
|
||||||
from neutron.conf.agent import ovs_conf
|
from neutron.conf.agent import ovs_conf
|
||||||
from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants
|
from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants
|
||||||
|
|
||||||
|
@ -83,12 +84,13 @@ class OvsCleanup(command.BaseCommand):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@utils.SingletonDecorator
|
||||||
class NeutronOvsdbIdl(impl_idl.OvsdbIdl):
|
class NeutronOvsdbIdl(impl_idl.OvsdbIdl):
|
||||||
def __init__(self, connection, idl_monitor):
|
def __init__(self, connection, idl_monitor):
|
||||||
max_level = None if cfg.CONF.OVS.ovsdb_debug else vlog.INFO
|
max_level = None if cfg.CONF.OVS.ovsdb_debug else vlog.INFO
|
||||||
vlog.use_python_logger(max_level=max_level)
|
vlog.use_python_logger(max_level=max_level)
|
||||||
self.idl_monitor = idl_monitor
|
self.idl_monitor = idl_monitor
|
||||||
super(NeutronOvsdbIdl, self).__init__(connection)
|
impl_idl.OvsdbIdl.__init__(self, connection)
|
||||||
|
|
||||||
def ovs_cleanup(self, bridges, all_ports=False):
|
def ovs_cleanup(self, bridges, all_ports=False):
|
||||||
return OvsCleanup(self, bridges, all_ports)
|
return OvsCleanup(self, bridges, all_ports)
|
||||||
|
|
|
@ -982,3 +982,15 @@ def timecost(f):
|
||||||
ret = f(*args, **kwargs)
|
ret = f(*args, **kwargs)
|
||||||
return ret
|
return ret
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
class SingletonDecorator(object):
|
||||||
|
|
||||||
|
def __init__(self, klass):
|
||||||
|
self._klass = klass
|
||||||
|
self._instance = None
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
if self._instance is None:
|
||||||
|
self._instance = self._klass(*args, **kwargs)
|
||||||
|
return self._instance
|
||||||
|
|
|
@ -624,3 +624,21 @@ class SpawnWithOrWithoutProfilerTestCase(
|
||||||
|
|
||||||
def test_spawn_without_profiler(self):
|
def test_spawn_without_profiler(self):
|
||||||
self._compare_profilers_in_parent_and_in_child(init_profiler=False)
|
self._compare_profilers_in_parent_and_in_child(init_profiler=False)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.SingletonDecorator
|
||||||
|
class _TestSingletonClass(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.variable = None
|
||||||
|
|
||||||
|
|
||||||
|
class SingletonDecoratorTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
|
def test_singleton_instance_class(self):
|
||||||
|
instance_1 = _TestSingletonClass()
|
||||||
|
instance_1.variable = 'value1'
|
||||||
|
|
||||||
|
instance_2 = _TestSingletonClass()
|
||||||
|
self.assertEqual(instance_1.__hash__(), instance_2.__hash__())
|
||||||
|
self.assertEqual('value1', instance_2.variable)
|
||||||
|
|
Loading…
Reference in New Issue