Merge "Ensure ovsdb_probe_interval set before connect()"
This commit is contained in:
commit
2b45716bd4
|
@ -66,9 +66,9 @@ class MetadataAgentOvsIdl(object):
|
|||
tables = ('Open_vSwitch', 'Bridge', 'Port', 'Interface')
|
||||
for table in tables:
|
||||
helper.register_table(table)
|
||||
ovs_idl = idl.Idl(connection_string, helper)
|
||||
ovs_idl._session.reconnect.set_probe_interval(
|
||||
config.get_ovn_ovsdb_probe_interval())
|
||||
ovs_idl = idl.Idl(
|
||||
connection_string, helper,
|
||||
probe_interval=config.get_ovn_ovsdb_probe_interval())
|
||||
conn = connection.Connection(
|
||||
ovs_idl, timeout=config.cfg.CONF.ovs.ovsdb_connection_timeout)
|
||||
return idl_ovs.OvsdbIdl(conn)
|
||||
|
|
|
@ -142,8 +142,6 @@ def get_ovn_idls(driver, trigger):
|
|||
class OvsdbNbOvnIdl(nb_impl_idl.OvnNbApiIdlImpl, Backend):
|
||||
def __init__(self, connection):
|
||||
super(OvsdbNbOvnIdl, self).__init__(connection)
|
||||
self.idl._session.reconnect.set_probe_interval(
|
||||
cfg.get_ovn_ovsdb_probe_interval())
|
||||
|
||||
@classmethod
|
||||
def from_worker(cls, worker_class, driver=None):
|
||||
|
@ -727,10 +725,6 @@ class OvsdbNbOvnIdl(nb_impl_idl.OvnNbApiIdlImpl, Backend):
|
|||
class OvsdbSbOvnIdl(sb_impl_idl.OvnSbApiIdlImpl, Backend):
|
||||
def __init__(self, connection):
|
||||
super(OvsdbSbOvnIdl, self).__init__(connection)
|
||||
# TODO(twilson) This direct access of the idl should be removed in
|
||||
# favor of a backend-agnostic method
|
||||
self.idl._session.reconnect.set_probe_interval(
|
||||
cfg.get_ovn_ovsdb_probe_interval())
|
||||
|
||||
@classmethod
|
||||
def from_worker(cls, worker_class, driver=None):
|
||||
|
|
|
@ -364,8 +364,15 @@ class OvnDbNotifyHandler(event.RowEventHandler):
|
|||
self.driver = driver
|
||||
|
||||
|
||||
class BaseOvnIdl(connection.OvsdbIdl):
|
||||
class Ml2OvnIdlBase(connection.OvsdbIdl):
|
||||
def __init__(self, remote, schema, probe_interval=(), **kwargs):
|
||||
if probe_interval == (): # None is a valid value to pass
|
||||
probe_interval = ovn_conf.get_ovn_ovsdb_probe_interval()
|
||||
super(Ml2OvnIdlBase, self).__init__(
|
||||
remote, schema, probe_interval=probe_interval, **kwargs)
|
||||
|
||||
|
||||
class BaseOvnIdl(Ml2OvnIdlBase):
|
||||
def __init__(self, remote, schema):
|
||||
self.notify_handler = event.RowEventHandler()
|
||||
super(BaseOvnIdl, self).__init__(remote, schema)
|
||||
|
@ -381,7 +388,7 @@ class BaseOvnIdl(connection.OvsdbIdl):
|
|||
self.notify_handler.notify(event, row, updates)
|
||||
|
||||
|
||||
class BaseOvnSbIdl(connection.OvsdbIdl):
|
||||
class BaseOvnSbIdl(Ml2OvnIdlBase):
|
||||
@classmethod
|
||||
def from_server(cls, connection_string, schema_name):
|
||||
_check_and_set_ssl_files(schema_name)
|
||||
|
|
|
@ -14,14 +14,17 @@
|
|||
|
||||
from unittest import mock
|
||||
|
||||
import fixtures as og_fixtures
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.common import utils as n_utils
|
||||
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
|
||||
from neutron.db import ovn_hash_ring_db as db_hash_ring
|
||||
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovsdb_monitor
|
||||
from neutron.tests.functional import base
|
||||
from neutron.tests.functional.resources.ovsdb import fixtures
|
||||
from neutron.tests.functional.resources import process
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
from neutron_lib.plugins import constants as plugin_constants
|
||||
from neutron_lib.plugins import directory
|
||||
|
@ -245,3 +248,34 @@ class TestNBDbMonitorOverTcp(TestNBDbMonitor):
|
|||
class TestNBDbMonitorOverSsl(TestNBDbMonitor):
|
||||
def get_ovsdb_server_protocol(self):
|
||||
return 'ssl'
|
||||
|
||||
|
||||
class OvnIdlProbeInterval(base.TestOVNFunctionalBase):
|
||||
def setUp(self):
|
||||
# skip parent setUp, we don't need it, but we do need grandparent
|
||||
# pylint: disable=bad-super-call
|
||||
super(base.TestOVNFunctionalBase, self).setUp()
|
||||
mm = directory.get_plugin().mechanism_manager
|
||||
self.mech_driver = mm.mech_drivers['ovn'].obj
|
||||
self.temp_dir = self.useFixture(og_fixtures.TempDir()).path
|
||||
install_share_path = self._get_install_share_path()
|
||||
self.mgr = self.useFixture(
|
||||
process.OvsdbServer(self.temp_dir, install_share_path,
|
||||
ovn_nb_db=True, ovn_sb_db=True,
|
||||
protocol='tcp'))
|
||||
connection = self.mgr.get_ovsdb_connection_path
|
||||
self.connections = {'OVN_Northbound': connection(),
|
||||
'OVN_Southbound': connection(db_type='sb')}
|
||||
|
||||
def test_ovsdb_probe_interval(self):
|
||||
klasses = {
|
||||
ovsdb_monitor.BaseOvnIdl: ('OVN_Northbound', {}),
|
||||
ovsdb_monitor.OvnNbIdl: ('OVN_Northbound',
|
||||
{'driver': self.mech_driver}),
|
||||
ovsdb_monitor.OvnSbIdl: ('OVN_Southbound',
|
||||
{'driver': self.mech_driver})}
|
||||
idls = [kls.from_server(self.connections[schema], schema, **kwargs)
|
||||
for kls, (schema, kwargs) in klasses.items()]
|
||||
interval = ovn_conf.get_ovn_ovsdb_probe_interval()
|
||||
for idl in idls:
|
||||
self.assertEqual(interval, idl._session.reconnect.probe_interval)
|
||||
|
|
|
@ -20,7 +20,6 @@ from ovsdbapp.backend import ovs_idl
|
|||
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.common.ovn import utils
|
||||
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
|
||||
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import impl_idl_ovn
|
||||
from neutron.services.portforwarding import constants as pf_const
|
||||
from neutron.tests import base
|
||||
|
@ -421,25 +420,6 @@ class TestNBImplIdlOvn(TestDBImplIdlOvn):
|
|||
fake_lbs = TestNBImplIdlOvn.fake_set['lbs']
|
||||
self._load_ovsdb_fake_rows(self.lb_table, fake_lbs)
|
||||
|
||||
@mock.patch.object(ovs_idl.Backend, 'autocreate_indices', mock.Mock(),
|
||||
create=True)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbNbOvnIdl, 'ovsdb_connection', None)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbNbOvnIdl, 'from_worker', mock.Mock())
|
||||
def test_setting_ovsdb_probe_timeout_default_value(self):
|
||||
inst = impl_idl_ovn.OvsdbNbOvnIdl(mock.Mock())
|
||||
inst.idl._session.reconnect.set_probe_interval.assert_called_with(
|
||||
60000)
|
||||
|
||||
@mock.patch.object(ovs_idl.Backend, 'autocreate_indices', mock.Mock(),
|
||||
create=True)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbNbOvnIdl, 'ovsdb_connection', None)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbNbOvnIdl, 'from_worker', mock.Mock())
|
||||
@mock.patch.object(ovn_conf, 'get_ovn_ovsdb_probe_interval')
|
||||
def test_setting_ovsdb_probe_timeout(self, mock_get_probe_interval):
|
||||
mock_get_probe_interval.return_value = 5000
|
||||
inst = impl_idl_ovn.OvsdbNbOvnIdl(mock.Mock())
|
||||
inst.idl._session.reconnect.set_probe_interval.assert_called_with(5000)
|
||||
|
||||
def test_get_all_logical_switches_with_ports(self):
|
||||
# Test empty
|
||||
mapping = self.nb_ovn_idl.get_all_logical_switches_with_ports()
|
||||
|
@ -827,59 +807,3 @@ class TestNBImplIdlOvn(TestDBImplIdlOvn):
|
|||
lb_row = self._find_ovsdb_fake_row(self.lb_table, 'name', 'lb_2')
|
||||
lb = self.nb_ovn_idl.get_floatingip_in_nat_or_lb(fip_id)
|
||||
self.assertEqual(lb['_uuid'], lb_row.uuid)
|
||||
|
||||
|
||||
class TestSBImplIdlOvn(TestDBImplIdlOvn):
|
||||
|
||||
fake_set = {
|
||||
'chassis': [
|
||||
{'name': 'host-1', 'hostname': 'host-1.localdomain.com',
|
||||
'external_ids': {'ovn-bridge-mappings':
|
||||
'public:br-ex,private:br-0'}},
|
||||
{'name': 'host-2', 'hostname': 'host-2.localdomain.com',
|
||||
'external_ids': {'ovn-bridge-mappings':
|
||||
'public:br-ex,public2:br-ex'}},
|
||||
{'name': 'host-3', 'hostname': 'host-3.localdomain.com',
|
||||
'external_ids': {'ovn-bridge-mappings':
|
||||
'public:br-ex'}}],
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super(TestSBImplIdlOvn, self).setUp()
|
||||
|
||||
self.chassis_table = fakes.FakeOvsdbTable.create_one_ovsdb_table()
|
||||
self._tables = {}
|
||||
self._tables['Chassis'] = self.chassis_table
|
||||
|
||||
with mock.patch.object(impl_idl_ovn.OvsdbSbOvnIdl, 'from_worker',
|
||||
return_value=mock.Mock()):
|
||||
with mock.patch.object(ovs_idl.Backend, 'autocreate_indices',
|
||||
create=True):
|
||||
impl_idl_ovn.OvsdbSbOvnIdl.ovsdb_connection = None
|
||||
self.sb_ovn_idl = impl_idl_ovn.OvsdbSbOvnIdl(mock.Mock())
|
||||
|
||||
self.sb_ovn_idl.idl.tables = self._tables
|
||||
|
||||
def _load_sb_db(self):
|
||||
# Load Chassis
|
||||
fake_chassis = TestSBImplIdlOvn.fake_set['chassis']
|
||||
self._load_ovsdb_fake_rows(self.chassis_table, fake_chassis)
|
||||
|
||||
@mock.patch.object(ovs_idl.Backend, 'autocreate_indices', mock.Mock(),
|
||||
create=True)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbSbOvnIdl, 'ovsdb_connection', None)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbSbOvnIdl, 'from_worker', mock.Mock())
|
||||
def test_setting_ovsdb_probe_timeout_default_value(self):
|
||||
inst = impl_idl_ovn.OvsdbSbOvnIdl(mock.Mock())
|
||||
inst.idl._session.reconnect.set_probe_interval.assert_called_with(
|
||||
60000)
|
||||
|
||||
@mock.patch.object(ovs_idl.Backend, 'autocreate_indices', mock.Mock(),
|
||||
create=True)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbSbOvnIdl, 'ovsdb_connection', None)
|
||||
@mock.patch.object(impl_idl_ovn.OvsdbSbOvnIdl, 'from_worker', mock.Mock())
|
||||
@mock.patch.object(ovn_conf, 'get_ovn_ovsdb_probe_interval')
|
||||
def test_setting_ovsdb_probe_timeout(self, mock_get_probe_interval):
|
||||
mock_get_probe_interval.return_value = 5000
|
||||
inst = impl_idl_ovn.OvsdbSbOvnIdl(mock.Mock())
|
||||
inst.idl._session.reconnect.set_probe_interval.assert_called_with(5000)
|
||||
|
|
Loading…
Reference in New Issue