Add wait for the post-fork event to nb/sb objects

It is possible for events from the nb/sb to fire before the opposite
db connection is made. These events can call back into driver code
which tries to access the other db before it is connected.

Closes-Bug: #1929197
Closes-Bug: #1928794
Closes-Bug: #1929633
Change-Id: If947581b90ced42981c4611c32de8f428a052c69
changes/55/781555/8
Terry Wilson 2 years ago
parent 3cae410b30
commit 90980f496c

@ -225,8 +225,8 @@ def main():
# and will fail with a KeyError if it isn't there
core_plugin.mechanism_manager.mech_drivers['ovn'] = driver
ovn_driver = driver.obj
ovn_driver._nb_ovn = ovn_api
ovn_driver._sb_ovn = ovn_sb_api
ovn_driver.nb_ovn = ovn_api
ovn_driver.sb_ovn = ovn_sb_api
synchronizer = ovn_db_sync.OvnNbSynchronizer(
core_plugin, ovn_api, ovn_sb_api, mode, ovn_driver)

@ -77,8 +77,8 @@ class NeutronAgent(abc.ABC):
if self.set_down:
return False
# TODO(twilson) Determine if we can go back to just checking:
# if self.driver._nb_ovn.nb_global.nb_cfg == self.nb_cfg:
if self.driver._nb_ovn.nb_global.nb_cfg - self.nb_cfg <= 1:
# if self.driver.nb_ovn.nb_global.nb_cfg == self.nb_cfg:
if self.driver.nb_ovn.nb_global.nb_cfg - self.nb_cfg <= 1:
return True
now = timeutils.utcnow(with_timezone=True)
if (now - self.updated_at).total_seconds() < cfg.CONF.agent_down_time:

@ -144,24 +144,28 @@ class OVNMechanismDriver(api.MechanismDriver):
@property
def _ovn_client(self):
if self._ovn_client_inst is None:
if not(self._nb_ovn and self._sb_ovn):
# Wait until the post_fork_initialize method has finished and
# IDLs have been correctly setup.
self._post_fork_event.wait()
self._ovn_client_inst = ovn_client.OVNClient(self._nb_ovn,
self._sb_ovn)
self._ovn_client_inst = ovn_client.OVNClient(self.nb_ovn,
self.sb_ovn)
return self._ovn_client_inst
@property
def nb_ovn(self):
# NOTE (twilson): This and sb_ovn can be moved to instance variables
# once all references to the private versions are changed
self._post_fork_event.wait()
return self._nb_ovn
@nb_ovn.setter
def nb_ovn(self, val):
self._nb_ovn = val
@property
def sb_ovn(self):
self._post_fork_event.wait()
return self._sb_ovn
@sb_ovn.setter
def sb_ovn(self, val):
self._sb_ovn = val
def check_vlan_transparency(self, context):
"""OVN driver vlan transparency support."""
vlan_transparency_network_types = [
@ -314,7 +318,7 @@ class OVNMechanismDriver(api.MechanismDriver):
self.hash_ring_group)
n_agent.AgentCache(self) # Initialize singleton agent cache
self._nb_ovn, self._sb_ovn = impl_idl_ovn.get_ovn_idls(self, trigger)
self.nb_ovn, self.sb_ovn = impl_idl_ovn.get_ovn_idls(self, trigger)
# Override agents API methods
self.patch_plugin_merge("get_agents", get_agents)
@ -334,8 +338,8 @@ class OVNMechanismDriver(api.MechanismDriver):
# This sync neutron DB to OVN-NB DB only in inconsistent states
self.nb_synchronizer = ovn_db_sync.OvnNbSynchronizer(
self._plugin,
self._nb_ovn,
self._sb_ovn,
self.nb_ovn,
self.sb_ovn,
ovn_conf.get_ovn_neutron_sync_mode(),
self
)
@ -344,7 +348,7 @@ class OVNMechanismDriver(api.MechanismDriver):
# This sync neutron DB to OVN-SB DB only in inconsistent states
self.sb_synchronizer = ovn_db_sync.OvnSbSynchronizer(
self._plugin,
self._sb_ovn,
self.sb_ovn,
self
)
self.sb_synchronizer.sync()
@ -464,7 +468,7 @@ class OVNMechanismDriver(api.MechanismDriver):
def _get_max_tunid(self):
try:
return int(self._nb_ovn.nb_global.options.get('max_tunid'))
return int(self.nb_ovn.nb_global.options.get('max_tunid'))
except (ValueError, TypeError):
# max_tunid may be absent in older OVN versions, return None
pass
@ -680,7 +684,7 @@ class OVNMechanismDriver(api.MechanismDriver):
port['id'])
return False
if not self._sb_ovn.chassis_exists(host):
if not self.sb_ovn.chassis_exists(host):
LOG.debug('No provisioning block for port %(port_id)s since no '
'OVN chassis for host: %(host)s',
{'port_id': port['id'], 'host': host})
@ -897,7 +901,7 @@ class OVNMechanismDriver(api.MechanismDriver):
chassis_physnets = []
try:
datapath_type, iface_types, chassis_physnets = (
self._sb_ovn.get_chassis_data_for_ml2_bind_port(context.host))
self.sb_ovn.get_chassis_data_for_ml2_bind_port(context.host))
iface_types = iface_types.split(',') if iface_types else []
except RuntimeError:
LOG.debug('Refusing to bind port %(port_id)s due to '
@ -970,12 +974,12 @@ class OVNMechanismDriver(api.MechanismDriver):
def _update_dnat_entry_if_needed(self, port_id, up=True):
"""Update DNAT entry if using distributed floating ips."""
if not self._nb_ovn:
self._nb_ovn = self._ovn_client._nb_idl
if not self.nb_ovn:
self.nb_ovn = self._ovn_client._nb_idl
nat = self._nb_ovn.db_find('NAT',
('logical_port', '=', port_id),
('type', '=', 'dnat_and_snat')).execute()
nat = self.nb_ovn.db_find('NAT',
('logical_port', '=', port_id),
('type', '=', 'dnat_and_snat')).execute()
if not nat:
return
# We take first entry as one port can only have one FIP
@ -984,23 +988,23 @@ class OVNMechanismDriver(api.MechanismDriver):
# TODO(dalvarez): Remove this code in T cycle when we're sure that
# all DNAT entries have the external_id.
if not nat['external_ids'].get(ovn_const.OVN_FIP_EXT_MAC_KEY):
self._nb_ovn.db_set('NAT', nat['_uuid'],
('external_ids',
{ovn_const.OVN_FIP_EXT_MAC_KEY:
nat['external_mac']})).execute()
self.nb_ovn.db_set('NAT', nat['_uuid'],
('external_ids',
{ovn_const.OVN_FIP_EXT_MAC_KEY:
nat['external_mac']})).execute()
if up and ovn_conf.is_ovn_distributed_floating_ip():
mac = nat['external_ids'][ovn_const.OVN_FIP_EXT_MAC_KEY]
if nat['external_mac'] != mac:
LOG.debug("Setting external_mac of port %s to %s",
port_id, mac)
self._nb_ovn.db_set(
self.nb_ovn.db_set(
'NAT', nat['_uuid'], ('external_mac', mac)).execute(
check_error=True)
else:
if nat['external_mac']:
LOG.debug("Clearing up external_mac of port %s", port_id)
self._nb_ovn.db_clear(
self.nb_ovn.db_clear(
'NAT', nat['_uuid'], 'external_mac').execute(
check_error=True)
@ -1080,10 +1084,10 @@ class OVNMechanismDriver(api.MechanismDriver):
def delete_mac_binding_entries(self, external_ip):
"""Delete all MAC_Binding entries associated to this IP address"""
mac_binds = self._sb_ovn.db_find_rows(
mac_binds = self.sb_ovn.db_find_rows(
'MAC_Binding', ('ip', '=', external_ip)).execute() or []
for entry in mac_binds:
self._sb_ovn.db_destroy('MAC_Binding', entry.uuid).execute()
self.sb_ovn.db_destroy('MAC_Binding', entry.uuid).execute()
def update_segment_host_mapping(self, host, phy_nets):
"""Update SegmentHostMapping in DB"""
@ -1109,7 +1113,7 @@ class OVNMechanismDriver(api.MechanismDriver):
if not phynet:
return
host_phynets_map = self._sb_ovn.get_chassis_hostname_and_physnets()
host_phynets_map = self.sb_ovn.get_chassis_hostname_and_physnets()
hosts = {host for host, phynets in host_phynets_map.items()
if phynet in phynets}
segment_service_db.map_segment_to_hosts(context, segment.id, hosts)
@ -1144,7 +1148,7 @@ class OVNMechanismDriver(api.MechanismDriver):
:returns: (bool) True if nb_cfg was updated. False if it was updated
recently and this call didn't trigger any update.
"""
last_ping = self._nb_ovn.nb_global.external_ids.get(
last_ping = self.nb_ovn.nb_global.external_ids.get(
ovn_const.OVN_LIVENESS_CHECK_EXT_ID_KEY)
if last_ping:
interval = max(cfg.CONF.agent_down_time // 2, 1)
@ -1153,9 +1157,9 @@ class OVNMechanismDriver(api.MechanismDriver):
if timeutils.utcnow(with_timezone=True) < next_ping:
return False
with self._nb_ovn.create_transaction(check_error=True,
bump_nb_cfg=True) as txn:
txn.add(self._nb_ovn.check_liveness())
with self.nb_ovn.create_transaction(check_error=True,
bump_nb_cfg=True) as txn:
txn.add(self.nb_ovn.check_liveness())
return True
def list_availability_zones(self, context, filters=None):
@ -1166,7 +1170,7 @@ class OVNMechanismDriver(api.MechanismDriver):
# the availability zones from the agents API itself. That would
# allow us to do things like: Do not schedule router ports on
# chassis that are offline (via the "alive" attribute for agents).
for ch in self._sb_ovn.chassis_list().execute(check_error=True):
for ch in self.sb_ovn.chassis_list().execute(check_error=True):
# Only take in consideration gateway chassis because that's where
# the router ports are scheduled on
if not ovn_utils.is_gateway_chassis(ch):
@ -1209,7 +1213,7 @@ def update_agent(self, context, id, agent, _driver=None):
if not agent.get('admin_state_up', True):
pass
elif 'description' in agent:
_driver._sb_ovn.set_chassis_neutron_description(
_driver.sb_ovn.set_chassis_neutron_description(
chassis_name, agent['description'],
agent_type).execute(check_error=True)
return agent
@ -1232,15 +1236,15 @@ def delete_agent(self, context, id, _driver=None):
# will still show as up. The recreated Chassis will cause all kinds of
# events to fire. But again, undefined behavior.
chassis_name = agent['configurations']['chassis_name']
_driver._sb_ovn.chassis_del(chassis_name, if_exists=True).execute(
_driver.sb_ovn.chassis_del(chassis_name, if_exists=True).execute(
check_error=True)
# Send a specific event that all API workers can get to delete the agent
# from their caches. Ideally we could send a single transaction that both
# created and deleted the key, but alas python-ovs is too "smart"
_driver._sb_ovn.db_set(
_driver.sb_ovn.db_set(
'SB_Global', '.', ('external_ids', {'delete_agent': str(id)})).execute(
check_error=True)
_driver._sb_ovn.db_remove(
_driver.sb_ovn.db_remove(
'SB_Global', '.', 'external_ids', delete_agent=str(id),
if_exists=True).execute(check_error=True)

@ -100,7 +100,7 @@ class ChassisEvent(row_event.RowEvent):
event = self.ROW_CREATE
if event == self.ROW_CREATE:
default_group = self.driver._nb_ovn.ha_chassis_group_get(
default_group = self.driver.nb_ovn.ha_chassis_group_get(
ovn_const.HA_CHASSIS_GROUP_DEFAULT_NAME).execute(
check_error=True)
@ -110,12 +110,12 @@ class ChassisEvent(row_event.RowEvent):
[ch.priority for ch in default_group.ha_chassis],
default=ovn_const.HA_CHASSIS_GROUP_HIGHEST_PRIORITY)
self.driver._nb_ovn.ha_chassis_group_add_chassis(
self.driver.nb_ovn.ha_chassis_group_add_chassis(
ovn_const.HA_CHASSIS_GROUP_DEFAULT_NAME, row.name,
priority=min_priority - 1).execute(check_error=True)
elif event == self.ROW_DELETE:
self.driver._nb_ovn.ha_chassis_group_del_chassis(
self.driver.nb_ovn.ha_chassis_group_del_chassis(
ovn_const.HA_CHASSIS_GROUP_DEFAULT_NAME,
row.name, if_exists=True).execute(check_error=True)
@ -200,8 +200,8 @@ class PortBindingChassisUpdateEvent(row_event.RowEvent):
if row.type == ovn_const.OVN_CHASSIS_REDIRECT:
return False
try:
lsp = self.driver._nb_ovn.lookup('Logical_Switch_Port',
row.logical_port)
lsp = self.driver.nb_ovn.lookup('Logical_Switch_Port',
row.logical_port)
except idlutils.RowNotFound:
LOG.warning("Logical Switch Port %(port)s not found for "
"Port_Binding %(binding)s",

@ -44,7 +44,7 @@ class OVNTrunkHandler(object):
self.plugin_driver = plugin_driver
def _set_sub_ports(self, parent_port, subports):
txn = self.plugin_driver._nb_ovn.transaction
txn = self.plugin_driver.nb_ovn.transaction
context = n_context.get_admin_context()
for port in subports:
with db_api.CONTEXT_WRITER.using(context), (
@ -52,7 +52,7 @@ class OVNTrunkHandler(object):
self._set_binding_profile(context, port, parent_port, ovn_txn)
def _unset_sub_ports(self, subports):
txn = self.plugin_driver._nb_ovn.transaction
txn = self.plugin_driver.nb_ovn.transaction
context = n_context.get_admin_context()
for port in subports:
with db_api.CONTEXT_WRITER.using(context), (
@ -91,7 +91,7 @@ class OVNTrunkHandler(object):
LOG.debug("Port not found while trying to set "
"binding_profile: %s", subport.port_id)
return
ovn_txn.add(self.plugin_driver._nb_ovn.set_lswitch_port(
ovn_txn.add(self.plugin_driver.nb_ovn.set_lswitch_port(
lport_name=subport.port_id,
parent_name=parent_port,
tag=subport.segmentation_id))
@ -125,7 +125,7 @@ class OVNTrunkHandler(object):
LOG.debug("Port not found while trying to unset "
"binding_profile: %s", subport.port_id)
return
ovn_txn.add(self.plugin_driver._nb_ovn.set_lswitch_port(
ovn_txn.add(self.plugin_driver.nb_ovn.set_lswitch_port(
lport_name=subport.port_id,
parent_name=[],
up=False,

@ -324,8 +324,8 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase,
self.mech_driver.post_fork_initialize(
mock.ANY, mock.ANY, trigger_cls.trigger)
self.nb_api = self.mech_driver._nb_ovn
self.sb_api = self.mech_driver._sb_ovn
self.nb_api = self.mech_driver.nb_ovn
self.sb_api = self.mech_driver.sb_ovn
def _collect_processes_logs(self):
timestamp = datetime.now().strftime('%y-%m-%d_%H-%M-%S')
@ -360,8 +360,8 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase,
if self.maintenance_worker:
self.mech_driver.nb_synchronizer.stop()
self.mech_driver.sb_synchronizer.stop()
self.mech_driver._nb_ovn.ovsdb_connection.stop()
self.mech_driver._sb_ovn.ovsdb_connection.stop()
self.mech_driver.nb_ovn.ovsdb_connection.stop()
self.mech_driver.sb_ovn.ovsdb_connection.stop()
def restart(self):
self.stop()

@ -98,7 +98,7 @@ class TestNBDbResources(base.TestOVNFunctionalBase):
def _get_subnet_dhcp_mac(self, subnet):
mac_key = 'server_id' if subnet['ip_version'] == 6 else 'server_mac'
dhcp_options = self.mech_driver._nb_ovn.get_subnet_dhcp_options(
dhcp_options = self.mech_driver.nb_ovn.get_subnet_dhcp_options(
subnet['id'])['subnet']
return dhcp_options.get('options', {}).get(
mac_key) if dhcp_options else None

@ -137,10 +137,10 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
'options': {'server_id': '01:02:03:04:05:06'}})
n1_s1_dhcp_options_uuid = (
self.mech_driver._nb_ovn.get_subnet_dhcp_options(
self.mech_driver.nb_ovn.get_subnet_dhcp_options(
n1_s1['subnet']['id'])['subnet']['uuid'])
n1_s2_dhcpv6_options_uuid = (
self.mech_driver._nb_ovn.get_subnet_dhcp_options(
self.mech_driver.nb_ovn.get_subnet_dhcp_options(
n1_s2['subnet']['id'])['subnet']['uuid'])
update_port_ids_v4 = []
update_port_ids_v6 = []
@ -328,7 +328,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
'dns_server': '8.8.8.8'}})
self.missed_dhcp_options.extend([
opts['uuid']
for opts in self.mech_driver._nb_ovn.get_subnets_dhcp_options(
for opts in self.mech_driver.nb_ovn.get_subnets_dhcp_options(
[n2_s1['subnet']['id'], n2_s2['subnet']['id']])])
for port_id in update_port_ids_v4:
@ -651,10 +651,10 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
n3_s2 = self.deserialize(self.fmt, res)
if not restart_ovsdb_processes:
# Test using original mac when syncing.
dhcp_mac_v4 = (self.mech_driver._nb_ovn.get_subnet_dhcp_options(
dhcp_mac_v4 = (self.mech_driver.nb_ovn.get_subnet_dhcp_options(
n3_s1['subnet']['id'])['subnet'].get('options', {})
.get('server_mac'))
dhcp_mac_v6 = (self.mech_driver._nb_ovn.get_subnet_dhcp_options(
dhcp_mac_v6 = (self.mech_driver.nb_ovn.get_subnet_dhcp_options(
n3_s2['subnet']['id'])['subnet'].get('options', {})
.get('server_id'))
self.assertTrue(dhcp_mac_v4 is not None)
@ -891,7 +891,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
utils.ovn_provnet_port_name(seg['id']))
# Get the list of lswitch ids stored in the OVN plugin IDL
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
plugin_lswitch_ids = [
row.name.replace('neutron-', '') for row in (
_plugin_nb_ovn._tables['Logical_Switch'].rows.values())]
@ -951,7 +951,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
db_net_ids = {net['id'] for net in db_networks['networks']}
# Retrieve all localports in OVN
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
plugin_metadata_ports = [row.name for row in (
_plugin_nb_ovn._tables['Logical_Switch_Port'].rows.values())
if row.type == ovn_const.LSP_TYPE_LOCALPORT]
@ -977,7 +977,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
if not utils.is_network_device_port(port) and
port['id'] not in self.lport_dhcp_ignored)
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
plugin_lport_ids = [
row.name for row in (
_plugin_nb_ovn._tables['Logical_Switch_Port'].rows.values())
@ -1063,7 +1063,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
def _validate_dhcp_opts(self, should_match=True):
observed_plugin_dhcp_options_rows = []
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
for row in _plugin_nb_ovn._tables['DHCP_Options'].rows.values():
opts = dict(row.options)
ids = dict(row.external_ids)
@ -1118,7 +1118,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
# Get the neutron DB ACLs.
db_acls = []
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
# ACLs due to SGs and default drop port group
for sg in self._list('security-groups')['security_groups']:
@ -1210,7 +1210,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
fip['floating_ip_address'] + fip['fixed_ip_address'] +
'dnat_and_snat' + mac_address + fip_port)
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
plugin_lrouter_ids = [
row.name.replace('neutron-', '') for row in (
_plugin_nb_ovn._tables['Logical_Router'].rows.values())]
@ -1261,7 +1261,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
try:
lrouter = idlutils.row_by_value(
self.mech_driver._nb_ovn.idl, 'Logical_Router', 'name',
self.mech_driver.nb_ovn.idl, 'Logical_Router', 'name',
'neutron-' + str(router_id), None)
lports = getattr(lrouter, 'ports', [])
plugin_lrouter_port_ids = [lport.name.replace('lrp-', '')
@ -1395,7 +1395,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
ext_ip, int(ext_port),
int_ip, int(int_port))
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
db_pfs = []
fips = self._list('floatingips')
for fip in fips['floatingips']:
@ -1426,7 +1426,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
nb_pfs, db_pfs)
def _validate_port_groups(self, should_match=True):
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
db_pgs = []
for sg in self._list('security-groups')['security_groups']:
@ -1469,7 +1469,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
self._delete('ports', port['id'])
ports_to_delete -= 1
_plugin_nb_ovn = self.mech_driver._nb_ovn
_plugin_nb_ovn = self.mech_driver.nb_ovn
plugin_metadata_ports = [row.name for row in (
_plugin_nb_ovn._tables['Logical_Switch_Port'].rows.values())
if row.type == ovn_const.LSP_TYPE_LOCALPORT]
@ -1505,7 +1505,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
def _sync_resources(self, mode):
nb_synchronizer = ovn_db_sync.OvnNbSynchronizer(
self.plugin, self.mech_driver._nb_ovn, self.mech_driver._sb_ovn,
self.plugin, self.mech_driver.nb_ovn, self.mech_driver.sb_ovn,
mode, self.mech_driver)
self.addCleanup(nb_synchronizer.stop)
nb_synchronizer.do_sync()
@ -1552,7 +1552,7 @@ class TestOvnSbSync(base.TestOVNFunctionalBase):
def setUp(self):
super(TestOvnSbSync, self).setUp(maintenance_worker=True)
self.sb_synchronizer = ovn_db_sync.OvnSbSynchronizer(
self.plugin, self.mech_driver._sb_ovn, self.mech_driver)
self.plugin, self.mech_driver.sb_ovn, self.mech_driver)
self.addCleanup(self.sb_synchronizer.stop)
self.ctx = context.get_admin_context()

@ -146,7 +146,7 @@ class TestNBDbMonitor(base.TestOVNFunctionalBase):
"""
net_name = 'network1'
row_event = WaitForDataPathBindingCreateEvent(net_name)
self.mech_driver._sb_ovn.idl.notify_handler.watch_event(row_event)
self.mech_driver.sb_ovn.idl.notify_handler.watch_event(row_event)
self._make_network(self.fmt, net_name, True)
self.assertTrue(row_event.wait())
dp = self.sb_api.db_find(
@ -158,7 +158,7 @@ class TestNBDbMonitor(base.TestOVNFunctionalBase):
# Ensure that the MAC_Binding entry gets deleted after creating a FIP
row_event = WaitForMACBindingDeleteEvent(macb_id)
self.mech_driver._sb_ovn.idl.notify_handler.watch_event(row_event)
self.mech_driver.sb_ovn.idl.notify_handler.watch_event(row_event)
fip = self._create_fip(port, '100.0.0.21')
self.assertTrue(row_event.wait())
@ -170,7 +170,7 @@ class TestNBDbMonitor(base.TestOVNFunctionalBase):
# Ensure that the MAC_Binding entry gets deleted after deleting the FIP
row_event = WaitForMACBindingDeleteEvent(macb_id)
self.mech_driver._sb_ovn.idl.notify_handler.watch_event(row_event)
self.mech_driver.sb_ovn.idl.notify_handler.watch_event(row_event)
self.l3_plugin.delete_floatingip(self.context, fip['id'])
self.assertTrue(row_event.wait())
@ -205,8 +205,8 @@ class TestNBDbMonitor(base.TestOVNFunctionalBase):
self._test_port_binding_and_status(port['id'], 'unbind', 'DOWN')
def _create_workers(self, row_event, worker_num):
self.mech_driver._nb_ovn.idl.notify_handler.watch_event(row_event)
worker_list = [self.mech_driver._nb_ovn]
self.mech_driver.nb_ovn.idl.notify_handler.watch_event(row_event)
worker_list = [self.mech_driver.nb_ovn]
# Create 10 fake workers
for _ in range(worker_num):

@ -28,7 +28,7 @@ class TestACLs(base.BaseTestCase):
def setUp(self):
super(TestACLs, self).setUp()
self.driver = mock.Mock()
self.driver._nb_ovn = fakes.FakeOvsdbNbOvnIdl()
self.driver.nb_ovn = fakes.FakeOvsdbNbOvnIdl()
self.plugin = fakes.FakePlugin()
self.admin_context = mock.Mock()
self.fake_port = fakes.FakePort.create_one_port({

@ -826,7 +826,7 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase):
delete_dhcp_options_list = ['UUID2', 'UUID4', 'UUID5']
ovn_nb_synchronizer = ovn_db_sync.OvnNbSynchronizer(
self.plugin, self.mech_driver._nb_ovn, self.mech_driver._sb_ovn,
self.plugin, self.mech_driver.nb_ovn, self.mech_driver.sb_ovn,
'repair', self.mech_driver)
self._test_ovn_nb_sync_helper(ovn_nb_synchronizer,
self.networks,
@ -874,7 +874,7 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase):
del_port_groups_list = []
ovn_nb_synchronizer = ovn_db_sync.OvnNbSynchronizer(
self.plugin, self.mech_driver._nb_ovn, self.mech_driver._sb_ovn,
self.plugin, self.mech_driver.nb_ovn, self.mech_driver.sb_ovn,
'log', self.mech_driver)
self._test_ovn_nb_sync_helper(ovn_nb_synchronizer,
self.networks,
@ -905,7 +905,7 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase):
expected_added,
expected_deleted):
ovn_nb_synchronizer = ovn_db_sync.OvnNbSynchronizer(
self.plugin, self.mech_driver._nb_ovn, self.mech_driver._sb_ovn,
self.plugin, self.mech_driver.nb_ovn, self.mech_driver.sb_ovn,
'repair', self.mech_driver)
add_routes, del_routes = ovn_nb_synchronizer. \
_calculate_routes_differences(ovn_routes, db_routes)
@ -1112,7 +1112,7 @@ class TestOvnSbSyncML2(test_mech_driver.OVNMechanismDriverTestCase):
def test_ovn_sb_sync(self):
ovn_sb_synchronizer = ovn_db_sync.OvnSbSynchronizer(
self.plugin,
self.mech_driver._sb_ovn,
self.mech_driver.sb_ovn,
self.mech_driver)
ovn_api = ovn_sb_synchronizer.ovn_api
hostname_with_physnets = {'hostname1': ['physnet1', 'physnet2'],

@ -365,7 +365,7 @@ class TestPortBindingChassisUpdateEvent(base.BaseTestCase):
pbtable = fakes.FakeOvsdbTable.create_one_ovsdb_table(
attrs={'name': 'Port_Binding'})
ovsdb_row = fakes.FakeOvsdbRow.create_one_ovsdb_row
self.driver._nb_ovn.lookup.return_value = ovsdb_row(attrs={'up': True})
self.driver.nb_ovn.lookup.return_value = ovsdb_row(attrs={'up': True})
self._test_event(
self.event.ROW_UPDATE,
ovsdb_row(attrs={'_table': pbtable, 'chassis': 'one',
@ -611,7 +611,7 @@ class TestChassisEvent(base.BaseTestCase):
def setUp(self):
super(TestChassisEvent, self).setUp()
self.driver = mock.Mock()
self.nb_ovn = self.driver._nb_ovn
self.nb_ovn = self.driver.nb_ovn
self.driver._ovn_client.is_external_ports_supported.return_value = True
self.event = ovsdb_monitor.ChassisEvent(self.driver)
self.is_gw_ch_mock = mock.patch.object(

@ -65,7 +65,19 @@ from neutron.tests.unit.plugins.ml2 import test_security_group
OVN_PROFILE = ovn_const.OVN_PORT_BINDING_PROFILE
class TestOVNMechanismDriverBase(test_plugin.Ml2PluginV2TestCase):
class MechDriverSetupBase:
def setUp(self):
super().setUp()
mm = directory.get_plugin().mechanism_manager
self.mech_driver = mm.mech_drivers['ovn'].obj
self.mech_driver.nb_ovn = fakes.FakeOvsdbNbOvnIdl()
self.mech_driver.sb_ovn = fakes.FakeOvsdbSbOvnIdl()
self.mech_driver._post_fork_event.set()
self.mech_driver._ovn_client._qos_driver = mock.Mock()
class TestOVNMechanismDriverBase(MechDriverSetupBase,
test_plugin.Ml2PluginV2TestCase):
_mechanism_drivers = ['logger', 'ovn']
_extension_drivers = ['port_security', 'dns']
@ -87,18 +99,13 @@ class TestOVNMechanismDriverBase(test_plugin.Ml2PluginV2TestCase):
cfg.CONF.set_override('vlan_transparent', True)
mock.patch.object(impl_idl_ovn.Backend, 'schema_helper').start()
super().setUp()
mm = directory.get_plugin().mechanism_manager
self.mech_driver = mm.mech_drivers['ovn'].obj
neutron_agent.AgentCache(self.mech_driver)
# Because AgentCache is a singleton and we get a new mech_driver each
# setUp(), override the AgentCache driver.
neutron_agent.AgentCache().driver = self.mech_driver
self.mech_driver._nb_ovn = fakes.FakeOvsdbNbOvnIdl()
self.mech_driver._sb_ovn = fakes.FakeOvsdbSbOvnIdl()
self.mech_driver._ovn_client._qos_driver = mock.Mock()
self.nb_ovn = self.mech_driver._nb_ovn
self.sb_ovn = self.mech_driver._sb_ovn
self.nb_ovn = self.mech_driver.nb_ovn
self.sb_ovn = self.mech_driver.sb_ovn
self.fake_subnet = fakes.FakeSubnet.create_one_subnet().info()
@ -166,15 +173,15 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
self.assertEqual(2, m_ovsdb_api.get_port_group.call_count)
def test__get_max_tunid_no_key_set(self):
self.mech_driver._nb_ovn.nb_global.options.get.return_value = None
self.mech_driver.nb_ovn.nb_global.options.get.return_value = None
self.assertIsNone(self.mech_driver._get_max_tunid())
def test__get_max_tunid_wrong_key_value(self):
self.mech_driver._nb_ovn.nb_global.options.get.return_value = '11wrong'
self.mech_driver.nb_ovn.nb_global.options.get.return_value = '11wrong'
self.assertIsNone(self.mech_driver._get_max_tunid())
def test__get_max_tunid_key_set(self):
self.mech_driver._nb_ovn.nb_global.options.get.return_value = '100'
self.mech_driver.nb_ovn.nb_global.options.get.return_value = '100'
self.assertEqual(100, self.mech_driver._get_max_tunid())
def _test__validate_network_segments_id_succeed(self, val):
@ -183,7 +190,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
"segmentation_id": val,
"physical_network": "physnet1",
}
self.mech_driver._nb_ovn.nb_global.options.get.return_value = '200'
self.mech_driver.nb_ovn.nb_global.options.get.return_value = '200'
self.mech_driver._validate_network_segments([segment])
def test__validate_network_segments_id_below_max_limit(self):
@ -1261,7 +1268,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
self.assertEqual(call_get_dhcp_opts, get_opts.called)
self.assertEqual(
call_add_dhcp_opts,
self.mech_driver._nb_ovn.add_dhcp_options.called)
self.mech_driver.nb_ovn.add_dhcp_options.called)
def test_add_subnet_dhcp_options_in_ovn(self):
subnet = {'ip_version': const.IP_VERSION_4}
@ -1299,7 +1306,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'gateway_ip': '10.0.0.1', 'enable_dhcp': True,
'dns_nameservers': [], 'host_routes': []}
network = {'id': 'network-id', 'mtu': 1000}
txn = self.mech_driver._nb_ovn.transaction().__enter__.return_value
txn = self.mech_driver.nb_ovn.transaction().__enter__.return_value
dhcp_option_command = mock.Mock()
txn.add.return_value = dhcp_option_command
@ -1342,8 +1349,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'subnet-id', port_id=port_dhcp_options['external_ids']['port_id'],
**port_dhcp_options) for port_dhcp_options in ports_dhcp_options])
self.assertEqual(len(add_dhcp_calls),
self.mech_driver._nb_ovn.add_dhcp_options.call_count)
self.mech_driver._nb_ovn.add_dhcp_options.assert_has_calls(
self.mech_driver.nb_ovn.add_dhcp_options.call_count)
self.mech_driver.nb_ovn.add_dhcp_options.assert_has_calls(
add_dhcp_calls, any_order=True)
# Check setting lport rows
@ -1354,8 +1361,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
mock.call(lport_name='port-id-3',
dhcpv4_options=dhcp_option_command)]
self.assertEqual(len(set_lsp_calls),
self.mech_driver._nb_ovn.set_lswitch_port.call_count)
self.mech_driver._nb_ovn.set_lswitch_port.assert_has_calls(
self.mech_driver.nb_ovn.set_lswitch_port.call_count)
self.mech_driver.nb_ovn.set_lswitch_port.assert_has_calls(
set_lsp_calls, any_order=True)
@mock.patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'get_ports')
@ -1378,7 +1385,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'ipv6_address_mode': 'dhcpv6-stateless',
'dns_nameservers': [], 'host_routes': []}
network = {'id': 'network-id', 'mtu': 1000}
txn = self.mech_driver._nb_ovn.transaction().__enter__.return_value
txn = self.mech_driver.nb_ovn.transaction().__enter__.return_value
dhcp_option_command = mock.Mock()
txn.add.return_value = dhcp_option_command
@ -1410,8 +1417,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'subnet-id', port_id=port_dhcp_options['external_ids']['port_id'],
**port_dhcp_options) for port_dhcp_options in ports_dhcp_options])
self.assertEqual(len(add_dhcp_calls),
self.mech_driver._nb_ovn.add_dhcp_options.call_count)
self.mech_driver._nb_ovn.add_dhcp_options.assert_has_calls(
self.mech_driver.nb_ovn.add_dhcp_options.call_count)
self.mech_driver.nb_ovn.add_dhcp_options.assert_has_calls(
add_dhcp_calls, any_order=True)
# Check setting lport rows
@ -1422,8 +1429,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
mock.call(lport_name='port-id-3',
dhcpv6_options=dhcp_option_command)]
self.assertEqual(len(set_lsp_calls),
self.mech_driver._nb_ovn.set_lswitch_port.call_count)
self.mech_driver._nb_ovn.set_lswitch_port.assert_has_calls(
self.mech_driver.nb_ovn.set_lswitch_port.call_count)
self.mech_driver.nb_ovn.set_lswitch_port.assert_has_calls(
set_lsp_calls, any_order=True)
def test_enable_subnet_dhcp_options_in_ovn_ipv6_slaac(self):
@ -1433,13 +1440,13 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
self.mech_driver._ovn_client._enable_subnet_dhcp_options(
subnet, network, mock.Mock())
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver._nb_ovn.set_lswitch_port.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.set_lswitch_port.assert_not_called()
def _test_remove_subnet_dhcp_options_in_ovn(self, ip_version):
opts = {'subnet': {'uuid': 'subnet-uuid'},
'ports': [{'uuid': 'port1-uuid'}]}
self.mech_driver._nb_ovn.get_subnet_dhcp_options.return_value = opts
self.mech_driver.nb_ovn.get_subnet_dhcp_options.return_value = opts
self.mech_driver._ovn_client._remove_subnet_dhcp_options(
'subnet-id', mock.Mock())
@ -1447,8 +1454,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
delete_dhcp_calls = [mock.call('subnet-uuid'), mock.call('port1-uuid')]
self.assertEqual(
len(delete_dhcp_calls),
self.mech_driver._nb_ovn.delete_dhcp_options.call_count)
self.mech_driver._nb_ovn.delete_dhcp_options.assert_has_calls(
self.mech_driver.nb_ovn.delete_dhcp_options.call_count)
self.mech_driver.nb_ovn.delete_dhcp_options.assert_has_calls(
delete_dhcp_calls, any_order=True)
def test_remove_subnet_dhcp_options_in_ovn_ipv4(self):
@ -1472,7 +1479,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'dns_server': '{8.8.8.8}',
'lease_time': str(12 * 60 * 60),
'mtu': str(1000)}}, 'ports': []}
self.mech_driver._nb_ovn.get_subnet_dhcp_options.return_value =\
self.mech_driver.nb_ovn.get_subnet_dhcp_options.return_value =\
orignal_options
self.mech_driver._ovn_client._update_subnet_dhcp_options(
@ -1487,7 +1494,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'server_mac': '01:02:03:04:05:06',
'lease_time': str(12 * 60 * 60),
'mtu': str(1000)}}
self.mech_driver._nb_ovn.add_dhcp_options.assert_called_once_with(
self.mech_driver.nb_ovn.add_dhcp_options.assert_called_once_with(
subnet['id'], **new_options)
def test_update_subnet_dhcp_options_in_ovn_ipv4_not_change(self):
@ -1505,12 +1512,12 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'dns_server': '{8.8.8.8}',
'lease_time': str(12 * 60 * 60),
'mtu': str(1000)}}, 'ports': []}
self.mech_driver._nb_ovn.get_subnet_dhcp_options.return_value =\
self.mech_driver.nb_ovn.get_subnet_dhcp_options.return_value =\
orignal_options
self.mech_driver._ovn_client._update_subnet_dhcp_options(
subnet, network, mock.Mock())
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
def test_update_subnet_dhcp_options_in_ovn_ipv6(self):
subnet = {'id': 'subnet-id', 'ip_version': 6, 'cidr': '10::0/64',
@ -1524,7 +1531,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'cidr': subnet['cidr'], 'options': {
'dhcpv6_stateless': 'true',
'server_id': '01:02:03:04:05:06'}}, 'ports': []}
self.mech_driver._nb_ovn.get_subnet_dhcp_options.return_value =\
self.mech_driver.nb_ovn.get_subnet_dhcp_options.return_value =\
orignal_options
self.mech_driver._ovn_client._update_subnet_dhcp_options(
subnet, network, mock.Mock())
@ -1536,7 +1543,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'dhcpv6_stateless': 'true',
'dns_server': '{10::3}',
'server_id': '01:02:03:04:05:06'}}
self.mech_driver._nb_ovn.add_dhcp_options.assert_called_once_with(
self.mech_driver.nb_ovn.add_dhcp_options.assert_called_once_with(
subnet['id'], **new_options)
def test_update_subnet_dhcp_options_in_ovn_ipv6_not_change(self):
@ -1550,12 +1557,12 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'cidr': subnet['cidr'], 'options': {
'dhcpv6_stateless': 'true',
'server_id': '01:02:03:04:05:06'}}, 'ports': []}
self.mech_driver._nb_ovn.get_subnet_dhcp_options.return_value =\
self.mech_driver.nb_ovn.get_subnet_dhcp_options.return_value =\
orignal_options
self.mech_driver._ovn_client._update_subnet_dhcp_options(
subnet, network, mock.Mock())
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
def test_update_subnet_dhcp_options_in_ovn_ipv6_slaac(self):
subnet = {'id': 'subnet-id', 'ip_version': 6, 'enable_dhcp': True,
@ -1563,8 +1570,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
network = {'id': 'network-id'}
self.mech_driver._ovn_client._update_subnet_dhcp_options(
subnet, network, mock.Mock())
self.mech_driver._nb_ovn.get_subnet_dhcp_options.assert_not_called()
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.get_subnet_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
def test_update_subnet_postcommit_ovn_do_nothing(self):
context = fakes.FakeSubnetContext(
@ -1610,7 +1617,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
umd.assert_called_once_with(mock.ANY, 'id', subnet_id='subnet_id')
def test_update_subnet_postcommit_disable_dhcp(self):
self.mech_driver._nb_ovn.get_subnet_dhcp_options.return_value = {
self.mech_driver.nb_ovn.get_subnet_dhcp_options.return_value = {
'subnet': mock.sentinel.subnet, 'ports': []}
context = fakes.FakeSubnetContext(
subnet={'enable_dhcp': False, 'id': 'subnet_id', 'ip_version': 4,
@ -1627,7 +1634,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
umd.assert_called_once_with(mock.ANY, 'id', subnet_id='subnet_id')
def test_update_subnet_postcommit_update_dhcp(self):
self.mech_driver._nb_ovn.get_subnet_dhcp_options.return_value = {
self.mech_driver.nb_ovn.get_subnet_dhcp_options.return_value = {
'subnet': mock.sentinel.subnet, 'ports': []}
context = fakes.FakeSubnetContext(
subnet={'enable_dhcp': True, 'ip_version': 4, 'network_id': 'id',
@ -1798,7 +1805,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
chassis_private = self._add_chassis(5)
for agent_type in (ovn_const.OVN_CONTROLLER_AGENT,
ovn_const.OVN_METADATA_AGENT):
self.mech_driver._nb_ovn.nb_global.nb_cfg = 5
self.mech_driver.nb_ovn.nb_global.nb_cfg = 5
agent = self._add_chassis_agent(5, agent_type, chassis_private)
self.assertTrue(agent.alive, "Agent of type %s alive=%s" %
(agent.agent_type, agent.alive))
@ -1810,7 +1817,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
chassis_private = self._add_chassis(nb_cfg)
for agent_type in (ovn_const.OVN_CONTROLLER_AGENT,
ovn_const.OVN_METADATA_AGENT):
self.mech_driver._nb_ovn.nb_global.nb_cfg = nb_cfg + 1
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg + 1
now = timeutils.utcnow()
updated_at = now - datetime.timedelta(cfg.CONF.agent_down_time + 1)
agent = self._add_chassis_agent(nb_cfg, agent_type,
@ -1823,7 +1830,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
chassis_private = self._add_chassis(nb_cfg)
for agent_type in (ovn_const.OVN_CONTROLLER_AGENT,
ovn_const.OVN_METADATA_AGENT):
self.mech_driver._nb_ovn.nb_global.nb_cfg = nb_cfg + 2
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg + 2
agent = self._add_chassis_agent(nb_cfg, agent_type,
chassis_private)
self.assertTrue(agent.alive, "Agent of type %s alive=%s" %
@ -1834,7 +1841,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
chassis_private = self._add_chassis(nb_cfg)
for agent_type in (ovn_const.OVN_CONTROLLER_AGENT,
ovn_const.OVN_METADATA_AGENT):
self.mech_driver._nb_ovn.nb_global.nb_cfg = nb_cfg + 2
self.mech_driver.nb_ovn.nb_global.nb_cfg = nb_cfg + 2
now = timeutils.utcnow(with_timezone=True)
updated_at = now - datetime.timedelta(cfg.CONF.agent_down_time + 1)
agent = self._add_chassis_agent(nb_cfg, agent_type,
@ -2035,7 +2042,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
self._test_should_post_fork_initialize(enabled, disabled)
class OVNMechanismDriverTestCase(test_plugin.Ml2PluginV2TestCase):
class OVNMechanismDriverTestCase(MechDriverSetupBase,
test_plugin.Ml2PluginV2TestCase):
_mechanism_drivers = ['logger', 'ovn']
def setUp(self):
@ -2059,13 +2067,6 @@ class OVNMechanismDriverTestCase(test_plugin.Ml2PluginV2TestCase):
self.driver.node_uuid = node_uuid
self.driver.hash_ring_group = 'fake_hash_ring_group'
mm = directory.get_plugin().mechanism_manager
self.mech_driver = mm.mech_drivers['ovn'].obj
nb_ovn = fakes.FakeOvsdbNbOvnIdl()
sb_ovn = fakes.FakeOvsdbSbOvnIdl()
self.mech_driver._nb_ovn = nb_ovn
self.mech_driver._sb_ovn = sb_ovn
self.mech_driver._ovn_client._qos_driver = mock.Mock()
self.mech_driver._insert_port_provisioning_block = mock.Mock()
p = mock.patch.object(ovn_utils, 'get_revision_number', return_value=1)
p.start()
@ -2193,19 +2194,13 @@ class TestOVNMechanismDriverPortSecurity(
pass
class TestOVNMechanismDriverSegment(test_segment.HostSegmentMappingTestCase):
class TestOVNMechanismDriverSegment(MechDriverSetupBase,
test_segment.HostSegmentMappingTestCase):
_mechanism_drivers = ['logger', 'ovn']
def setUp(self):
mock.patch.object(impl_idl_ovn.Backend, 'schema_helper').start()
super(TestOVNMechanismDriverSegment, self).setUp()
mm = directory.get_plugin().mechanism_manager
self.mech_driver = mm.mech_drivers['ovn'].obj
nb_ovn = fakes.FakeOvsdbNbOvnIdl()
sb_ovn = fakes.FakeOvsdbSbOvnIdl()
self.mech_driver._nb_ovn = nb_ovn
self.mech_driver._sb_ovn = sb_ovn
self.mech_driver._ovn_client._qos_driver = mock.Mock()
p = mock.patch.object(ovn_utils, 'get_revision_number', return_value=1)
p.start()
self.addCleanup(p.stop)
@ -2261,7 +2256,7 @@ class TestOVNMechanismDriverSegment(test_segment.HostSegmentMappingTestCase):
def test_update_segment_host_mapping_with_new_segment(self):
hostname_with_physnets = {'hostname1': ['phys_net1', 'phys_net2'],
'hostname2': ['phys_net1']}
ovn_sb_api = self.mech_driver._sb_ovn
ovn_sb_api = self.mech_driver.sb_ovn
ovn_sb_api.get_chassis_hostname_and_physnets.return_value = (
hostname_with_physnets)
self.mech_driver.subscribe()
@ -2278,7 +2273,7 @@ class TestOVNMechanismDriverSegment(test_segment.HostSegmentMappingTestCase):
self.assertFalse(set(segments_host_db2))
def test_create_segment_create_localnet_port(self):
ovn_nb_api = self.mech_driver._nb_ovn
ovn_nb_api = self.mech_driver.nb_ovn
with self.network() as network:
net = network['network']
new_segment = self._test_create_segment(
@ -2313,7 +2308,7 @@ class TestOVNMechanismDriverSegment(test_segment.HostSegmentMappingTestCase):
self.assertEqual(len(segments), 3)
def test_delete_segment_delete_localnet_port(self):
ovn_nb_api = self.mech_driver._nb_ovn
ovn_nb_api = self.mech_driver.nb_ovn
with self.network() as network:
net = network['network']
segment = self._test_create_segment(
@ -2325,7 +2320,7 @@ class TestOVNMechanismDriverSegment(test_segment.HostSegmentMappingTestCase):
lswitch_name=ovn_utils.ovn_name(net['id']))
def test_delete_segment_delete_localnet_port_compat_name(self):
ovn_nb_api = self.mech_driver._nb_ovn
ovn_nb_api = self.mech_driver.nb_ovn
with self.network() as network:
net = network['network']
seg_1 = self._test_create_segment(
@ -2381,7 +2376,7 @@ class TestOVNMechanismDriverSegment(test_segment.HostSegmentMappingTestCase):
def test_create_segments_subnet_metadata_ip_allocation(self):
self._test_segments_helper()
ovn_nb_api = self.mech_driver._nb_ovn
ovn_nb_api = self.mech_driver.nb_ovn
# Assert that metadata address has been allocated from previously
# created subnet.
@ -2434,7 +2429,7 @@ class TestOVNMechanismDriverSegment(test_segment.HostSegmentMappingTestCase):
def test_create_delete_segment_distributed_service_port_not_touched(self):
self._test_segments_helper()
ovn_nb_api = self.mech_driver._nb_ovn
ovn_nb_api = self.mech_driver.nb_ovn
# Delete second subnet
self._delete('subnets', self.sub_2['subnet']['id'])
@ -2808,11 +2803,11 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
'options': {'server_id': '01:02:03:04:05:06',
'domain_search': 'foo-domain'}}
self.mech_driver._nb_ovn.add_dhcp_options.return_value = 'foo-val'
self.mech_driver.nb_ovn.add_dhcp_options.return_value = 'foo-val'
dhcp_options = self.mech_driver._ovn_client._get_port_dhcp_options(
port, ip_version)
self.assertEqual({'cmd': 'foo-val'}, dhcp_options)
self.mech_driver._nb_ovn.add_dhcp_options.assert_called_once_with(
self.mech_driver.nb_ovn.add_dhcp_options.assert_called_once_with(
'foo-subnet', port_id='foo-port', **expected_dhcp_options)
def test__get_port_dhcp_options_port_dhcp_opts_set_v4(self):
@ -2856,7 +2851,7 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
# Since the port has no extra DHCPv4/v6 options defined, no new
# DHCP_Options row should be created and logical switch port DHCPv4/v6
# options should point to the subnet DHCPv4/v6 options.
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
def test__get_port_dhcp_options_port_dhcp_opts_not_set_v4(self):
self._test__get_port_dhcp_options_port_dhcp_opts_not_set(ip_version=4)
@ -2893,7 +2888,7 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
1,
self.mech_driver._ovn_client._get_subnet_dhcp_options_for_port.
call_count)
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
# Set dhcp_disabled with ip_version specified by this test case to
# true, no dhcp options will be get since it's dhcp_disabled now for
@ -2909,7 +2904,7 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
0,
self.mech_driver._ovn_client._get_subnet_dhcp_options_for_port.
call_count)
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
# Set dhcp_disabled with ip_version specified by this test case to
# false, and set dhcp_disabled with ip_version not in test to true.
@ -2926,7 +2921,7 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
1,
self.mech_driver._ovn_client._get_subnet_dhcp_options_for_port.
call_count)
self.mech_driver._nb_ovn.add_dhcp_options.assert_not_called()
self.mech_driver.nb_ovn.add_dhcp_options.assert_not_called()
def test__get_port_dhcp_options_port_dhcp_disabled_v4(self):
self._test__get_port_dhcp_options_port_dhcp_disabled(ip_version=4)
@ -2960,7 +2955,7 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
ovn_const.DHCPV6_STATELESS_OPT: 'true'}}}
return [fake_rows[row] for row in fake_rows if row in subnets]
self.mech_driver._nb_ovn.get_subnets_dhcp_options.side_effect = fake
self.mech_driver.nb_ovn.get_subnets_dhcp_options.side_effect = fake
if ip_version == 4:
expected_opts = 'foo' if enable_dhcp else None
@ -2988,7 +2983,7 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
enable_dhcp=False)
class TestOVNMechanismDriverSecurityGroup(
class TestOVNMechanismDriverSecurityGroup(MechDriverSetupBase,
test_security_group.Ml2SecurityGroupsTestCase):
# This set of test cases is supplement to test_acl.py, the purpose is to
# test acl methods invoking. Content correctness of args of acl methods
@ -3001,13 +2996,6 @@ class TestOVNMechanismDriverSecurityGroup(
cfg.CONF.set_override('dns_servers', ['8.8.8.8'], group='ovn')
mock.patch.object(impl_idl_ovn.Backend, 'schema_helper').start()
super(TestOVNMechanismDriverSecurityGroup, self).setUp()
mm = directory.get_plugin().mechanism_manager
self.mech_driver = mm.mech_drivers['ovn'].obj
nb_ovn = fakes.FakeOvsdbNbOvnIdl()
sb_ovn = fakes.FakeOvsdbSbOvnIdl()
self.mech_driver._nb_ovn = nb_ovn
self.mech_driver._sb_ovn = sb_ovn
self.mech_driver._ovn_client._qos_driver = mock.Mock()
self.ctx = context.get_admin_context()
revision_plugin.RevisionPlugin()
@ -3053,7 +3041,7 @@ class TestOVNMechanismDriverSecurityGroup(
external_ids={'neutron:security_group_id': sg['id']},
name=expected_pg_name),
]
self.mech_driver._nb_ovn.pg_add.assert_has_calls(