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.
Conflicts:
neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py
neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py
neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py
neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py
neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py
neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py
Closes-Bug: #1929197
Closes-Bug: #1928794
Closes-Bug: #1929633
Change-Id: If947581b90ced42981c4611c32de8f428a052c69
(cherry picked from commit 90980f496c
)
This commit is contained in:
parent
089d902961
commit
3139bbcbe6
|
@ -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:
|
||||
|
|
|
@ -153,24 +153,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 = [
|
||||
|
@ -347,7 +351,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)
|
||||
|
@ -367,8 +371,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
|
||||
)
|
||||
|
@ -377,7 +381,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()
|
||||
|
@ -488,7 +492,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
|
||||
|
@ -703,7 +707,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})
|
||||
|
@ -920,7 +924,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 '
|
||||
|
@ -993,12 +997,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
|
||||
|
@ -1007,23 +1011,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)
|
||||
|
||||
|
@ -1140,7 +1144,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)
|
||||
|
@ -1152,11 +1156,11 @@ class OVNMechanismDriver(api.MechanismDriver):
|
|||
it resides. If metadata is disabled or DHCP is not enabled for its
|
||||
subnets, this function will return right away.
|
||||
"""
|
||||
if ovn_conf.is_ovn_metadata_enabled() and self._sb_ovn:
|
||||
if ovn_conf.is_ovn_metadata_enabled() and self.sb_ovn:
|
||||
# Wait until metadata service has been setup for this port in the
|
||||
# chassis it resides.
|
||||
result = (
|
||||
self._sb_ovn.get_logical_port_chassis_and_datapath(port_id))
|
||||
self.sb_ovn.get_logical_port_chassis_and_datapath(port_id))
|
||||
if not result:
|
||||
LOG.warning("Logical port %s doesn't exist in OVN", port_id)
|
||||
return
|
||||
|
@ -1188,7 +1192,7 @@ class OVNMechanismDriver(api.MechanismDriver):
|
|||
try:
|
||||
n_utils.wait_until_true(
|
||||
lambda: datapath in
|
||||
self._sb_ovn.get_chassis_metadata_networks(chassis),
|
||||
self.sb_ovn.get_chassis_metadata_networks(chassis),
|
||||
timeout=METADATA_READY_WAIT_TIMEOUT,
|
||||
exception=MetadataServiceReadyWaitTimeoutException)
|
||||
except MetadataServiceReadyWaitTimeoutException:
|
||||
|
@ -1244,7 +1248,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)
|
||||
|
@ -1253,9 +1257,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):
|
||||
|
@ -1266,7 +1270,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):
|
||||
|
@ -1309,7 +1313,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
|
||||
|
@ -1332,15 +1336,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)
|
||||
|
||||
|
|
|
@ -43,7 +43,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()
|
||||
db_parent_port = port_obj.Port.get_object(context, id=parent_port)
|
||||
parent_port_status = db_parent_port.status
|
||||
|
@ -54,7 +54,7 @@ class OVNTrunkHandler(object):
|
|||
parent_port_status, 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), (
|
||||
|
@ -94,7 +94,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))
|
||||
|
@ -128,7 +128,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
|
||||
|
|
|
@ -138,10 +138,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 = []
|
||||
|
@ -337,7 +337,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:
|
||||
|
@ -663,10 +663,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)
|
||||
|
@ -907,7 +907,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())]
|
||||
|
@ -967,7 +967,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 == 'localport']
|
||||
|
@ -993,7 +993,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())
|
||||
|
@ -1079,7 +1079,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)
|
||||
|
@ -1134,7 +1134,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']:
|
||||
|
@ -1226,7 +1226,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())]
|
||||
|
@ -1277,7 +1277,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-', '')
|
||||
|
@ -1411,7 +1411,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']:
|
||||
|
@ -1442,7 +1442,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']:
|
||||
|
@ -1485,7 +1485,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 == 'localport']
|
||||
|
@ -1521,7 +1521,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()
|
||||
|
@ -1568,7 +1568,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()
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ class TestNBDbMonitor(base.TestOVNFunctionalBase):
|
|||
self.mech_driver.sb_ovn.idl.update_tables(
|
||||
['MAC_Binding'], self.mech_driver.sb_schema_helper.schema_json)
|
||||
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(
|
||||
|
@ -243,8 +243,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({
|
||||
|
|
|
@ -810,7 +810,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,
|
||||
|
@ -858,7 +858,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,
|
||||
|
@ -889,7 +889,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'],
|
||||
|
|
|
@ -636,7 +636,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(
|
||||
|
|
|
@ -68,7 +68,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']
|
||||
|
@ -91,18 +103,13 @@ class TestOVNMechanismDriverBase(test_plugin.Ml2PluginV2TestCase):
|
|||
cfg.CONF.set_override('ovsdb_connection_timeout', 30, group='ovn')
|
||||
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()
|
||||
|
||||
|
@ -193,15 +200,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):
|
||||
|
@ -210,7 +217,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):
|
||||
|
@ -1286,7 +1293,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}
|
||||
|
@ -1324,7 +1331,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
|
||||
|
||||
|
@ -1367,8 +1374,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
|
||||
|
@ -1379,8 +1386,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')
|
||||
|
@ -1403,7 +1410,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
|
||||
|
||||
|
@ -1435,8 +1442,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
|
||||
|
@ -1447,8 +1454,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):
|
||||
|
@ -1458,13 +1465,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())
|
||||
|
||||
|
@ -1472,8 +1479,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):
|
||||
|
@ -1497,7 +1504,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(
|
||||
|
@ -1512,7 +1519,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):
|
||||
|
@ -1530,12 +1537,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',
|
||||
|
@ -1549,7 +1556,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())
|
||||
|
@ -1561,7 +1568,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):
|
||||
|
@ -1575,12 +1582,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,
|
||||
|
@ -1588,8 +1595,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(
|
||||
|
@ -1634,7 +1641,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
|
|||
umd.assert_called_once_with(mock.ANY, 'id', subnet=subnet)
|
||||
|
||||
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': []}
|
||||
subnet = {'enable_dhcp': False, 'id': 'subnet_id', 'ip_version': 4,
|
||||
'network_id': 'id'}
|
||||
|
@ -1650,7 +1657,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
|
|||
umd.assert_called_once_with(mock.ANY, 'id', subnet=subnet)
|
||||
|
||||
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': []}
|
||||
subnet = {'enable_dhcp': True, 'id': 'subnet_id', 'ip_version': 4,
|
||||
'network_id': 'id'}
|
||||
|
@ -1869,7 +1876,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))
|
||||
|
@ -1881,7 +1888,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,
|
||||
|
@ -1894,7 +1901,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" %
|
||||
|
@ -1905,7 +1912,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,
|
||||
|
@ -2062,7 +2069,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
|
|||
self.assertEqual(sorted(expected_candidates), sorted(candidates))
|
||||
|
||||
|
||||
class OVNMechanismDriverTestCase(test_plugin.Ml2PluginV2TestCase):
|
||||
class OVNMechanismDriverTestCase(MechDriverSetupBase,
|
||||
test_plugin.Ml2PluginV2TestCase):
|
||||
_mechanism_drivers = ['logger', 'ovn']
|
||||
|
||||
def setUp(self):
|
||||
|
@ -2086,13 +2094,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()
|
||||
|
@ -2220,19 +2221,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)
|
||||
|
@ -2288,7 +2283,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()
|
||||
|
@ -2305,7 +2300,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(
|
||||
|
@ -2340,7 +2335,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(
|
||||
|
@ -2352,7 +2347,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(
|
||||
|
@ -2413,7 +2408,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.
|
||||
|
@ -2466,7 +2461,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'])
|
||||
|
@ -2911,11 +2906,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):
|
||||
|
@ -2959,7 +2954,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)
|
||||
|
@ -2996,7 +2991,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
|
||||
|
@ -3012,7 +3007,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.
|
||||
|
@ -3029,7 +3024,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)
|
||||
|
@ -3063,7 +3058,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
|
||||
|
@ -3091,7 +3086,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
|
||||
|
@ -3109,13 +3104,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()
|
||||
|
||||
|
@ -3161,7 +3149,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(
|
||||
self.mech_driver.nb_ovn.pg_add.assert_has_calls(
|
||||
expected_pg_add_calls)
|
||||
|
||||
def test_delete_security_group(self):
|
||||
|
@ -3172,7 +3160,7 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
expected_pg_del_calls = [
|
||||
mock.call(if_exists=True, name=expected_pg_name),
|
||||
]
|
||||
self.mech_driver._nb_ovn.pg_del.assert_has_calls(
|
||||
self.mech_driver.nb_ovn.pg_del.assert_has_calls(
|
||||
expected_pg_del_calls)
|
||||
|
||||
def test_create_port(self):
|
||||
|
@ -3187,47 +3175,47 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
mock.call('neutron_pg_drop', mock.ANY),
|
||||
mock.call(expected_pg_name, mock.ANY)
|
||||
]
|
||||
self.mech_driver._nb_ovn.pg_add_ports.assert_has_calls(
|
||||
self.mech_driver.nb_ovn.pg_add_ports.assert_has_calls(
|
||||
expected_pg_add_ports_calls)
|
||||
|
||||
# Assert add_acl() is not used anymore
|
||||
self.assertFalse(self.mech_driver._nb_ovn.add_acl.called)
|
||||
self.assertFalse(self.mech_driver.nb_ovn.add_acl.called)
|
||||
|
||||
def test_create_port_with_sg_default_rules(self):
|
||||
with self.network() as n, self.subnet(n):
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
sg = self._create_sg('sg')
|
||||
self._make_port(self.fmt, n['network']['id'],
|
||||
security_groups=[sg['id']])
|
||||
# egress traffic for ipv4 and ipv6 is allowed by default
|
||||
self.assertEqual(
|
||||
2, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
2, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
|
||||
def test_create_port_with_empty_sg(self):
|
||||
with self.network() as n, self.subnet(n):
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
sg = self._create_empty_sg('sg')
|
||||
# Implicit egress rules for ipv4 and ipv6
|
||||
self.assertEqual(2, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver._nb_ovn.pg_add.reset_mock()
|
||||
self.mech_driver._nb_ovn.pg_add_ports.reset_mock()
|
||||
self.assertEqual(2, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_add_ports.reset_mock()
|
||||
|
||||
self._make_port(self.fmt, n['network']['id'],
|
||||
security_groups=[sg['id']])
|
||||
self.assertFalse(self.mech_driver._nb_ovn.pg_acl_add.called)
|
||||
self.assertFalse(self.mech_driver._nb_ovn.pg_add.called)
|
||||
self.assertEqual(1, self.mech_driver._nb_ovn.pg_add_ports.called)
|
||||
self.assertFalse(self.mech_driver.nb_ovn.pg_acl_add.called)
|
||||
self.assertFalse(self.mech_driver.nb_ovn.pg_add.called)
|
||||
self.assertEqual(1, self.mech_driver.nb_ovn.pg_add_ports.called)
|
||||
|
||||
def test_create_port_with_multi_sgs_duplicate_rules(self):
|
||||
with self.network() as n, self.subnet(n):
|
||||
self.mech_driver._nb_ovn.pg_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_add.reset_mock()
|
||||
sg1 = self._create_empty_sg('sg1')
|
||||
sg2 = self._create_empty_sg('sg2')
|
||||
self.assertEqual(
|
||||
2, self.mech_driver._nb_ovn.pg_add.call_count)
|
||||
2, self.mech_driver.nb_ovn.pg_add.call_count)
|
||||
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
self._create_sg_rule(sg1['id'], 'ingress', const.PROTO_NAME_TCP,
|
||||
port_range_min=22, port_range_max=23,
|
||||
remote_ip_prefix='20.0.0.0/24')
|
||||
|
@ -3235,13 +3223,13 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
port_range_min=22, port_range_max=23,
|
||||
remote_ip_prefix='20.0.0.0/24')
|
||||
self.assertEqual(
|
||||
2, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
2, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
|
||||
self._make_port(self.fmt, n['network']['id'],
|
||||
security_groups=[sg1['id'], sg2['id']])
|
||||
# Default drop group, two security groups
|
||||
self.assertEqual(
|
||||
3, self.mech_driver._nb_ovn.pg_add_ports.call_count)
|
||||
3, self.mech_driver.nb_ovn.pg_add_ports.call_count)
|
||||
|
||||
@mock.patch('neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb.'
|
||||
'ovn_client.OVNClient.is_external_ports_supported',
|
||||
|
@ -3249,7 +3237,7 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
def _test_create_port_with_vnic_type(self, vnic_type):
|
||||
fake_grp = 'fake-default-ha-group-uuid'
|
||||
row = fakes.FakeOvsdbRow.create_one_ovsdb_row(attrs={'uuid': fake_grp})
|
||||
self.mech_driver._nb_ovn.ha_chassis_group_get.return_value.\
|
||||
self.mech_driver.nb_ovn.ha_chassis_group_get.return_value.\
|
||||
execute.return_value = row
|
||||
|
||||
with self.network() as n, self.subnet(n):
|
||||
|
@ -3260,9 +3248,9 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
|
||||
# Assert create_lswitch_port was called with the relevant
|
||||
# parameters
|
||||
_, kwargs = self.mech_driver._nb_ovn.create_lswitch_port.call_args
|
||||
_, kwargs = self.mech_driver.nb_ovn.create_lswitch_port.call_args
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.create_lswitch_port.call_count)
|
||||
1, self.mech_driver.nb_ovn.create_lswitch_port.call_count)
|
||||
self.assertEqual(ovn_const.LSP_TYPE_EXTERNAL, kwargs['type'])
|
||||
self.assertEqual(fake_grp, kwargs['ha_chassis_group'])
|
||||
|
||||
|
@ -3291,7 +3279,7 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
remote_ip_prefix='30.0.0.0/24')
|
||||
data = {'port': {'security_groups': [sg1['id'], sg2['id']]}}
|
||||
|
||||
self.mech_driver._nb_ovn.pg_add_ports.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_add_ports.reset_mock()
|
||||
req = self.new_update_request('ports', data, p['id'])
|
||||
req.get_response(self.api)
|
||||
|
||||
|
@ -3306,17 +3294,17 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
self._make_port(self.fmt, n['network']['id'],
|
||||
security_groups=[sg['id']])
|
||||
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
sg_r = self._create_sg_rule(sg['id'], 'ingress',
|
||||
const.PROTO_NAME_UDP,
|
||||
ethertype=const.IPv6)
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
|
||||
self.mech_driver._nb_ovn.pg_acl_del.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_del.reset_mock()
|
||||
self._delete_sg_rule(sg_r['id'])
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_del.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_del.call_count)
|
||||
|
||||
def test_update_sg_duplicate_rule(self):
|
||||
with self.network() as n, self.subnet(n):
|
||||
|
@ -3329,21 +3317,21 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
security_groups=[sg1['id'], sg2['id']])
|
||||
# One default drop rule, two SGs
|
||||
self.assertEqual(
|
||||
3, self.mech_driver._nb_ovn.pg_add_ports.call_count)
|
||||
3, self.mech_driver.nb_ovn.pg_add_ports.call_count)
|
||||
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
# Add a new duplicate rule to sg2. It's expected to be added.
|
||||
sg2_r = self._create_sg_rule(sg2['id'], 'ingress',
|
||||
const.PROTO_NAME_UDP,
|
||||
port_range_min=22, port_range_max=23)
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
|
||||
self.mech_driver._nb_ovn.pg_acl_del.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_del.reset_mock()
|
||||
# Delete the duplicate rule. It's expected to be deleted.
|
||||
self._delete_sg_rule(sg2_r['id'])
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_del.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_del.call_count)
|
||||
|
||||
def test_update_sg_duplicate_rule_multi_ports(self):
|
||||
with self.network() as n, self.subnet(n):
|
||||
|
@ -3351,7 +3339,7 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
sg2 = self._create_empty_sg('sg2')
|
||||
sg3 = self._create_empty_sg('sg3')
|
||||
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
self._create_sg_rule(sg1['id'], 'ingress',
|
||||
const.PROTO_NAME_UDP,
|
||||
remote_group_id=sg3['id'])
|
||||
|
@ -3367,36 +3355,36 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
|
||||
# No matter how many ports are there, there are two rules only
|
||||
self.assertEqual(
|
||||
2, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
2, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
|
||||
# Add a rule to sg1 duplicate with sg2. It's expected to be added.
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
sg1_r = self._create_sg_rule(sg1['id'], 'egress',
|
||||
const.PROTO_NAME_TCP,
|
||||
port_range_min=60, port_range_max=70)
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
|
||||
# Add a rule to sg2 duplicate with sg1 but not duplicate with sg3.
|
||||
# It's expected to be added as well.
|
||||
self.mech_driver._nb_ovn.pg_acl_add.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_add.reset_mock()
|
||||
sg2_r = self._create_sg_rule(sg2['id'], 'ingress',
|
||||
const.PROTO_NAME_UDP,
|
||||
remote_group_id=sg3['id'])
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_add.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_add.call_count)
|
||||
|
||||
# Delete the duplicate rule in sg1. It's expected to be deleted.
|
||||
self.mech_driver._nb_ovn.pg_acl_del.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_del.reset_mock()
|
||||
self._delete_sg_rule(sg1_r['id'])
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_del.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_del.call_count)
|
||||
|
||||
# Delete the duplicate rule in sg2. It's expected to be deleted.
|
||||
self.mech_driver._nb_ovn.pg_acl_del.reset_mock()
|
||||
self.mech_driver.nb_ovn.pg_acl_del.reset_mock()
|
||||
self._delete_sg_rule(sg2_r['id'])
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.pg_acl_del.call_count)
|
||||
1, self.mech_driver.nb_ovn.pg_acl_del.call_count)
|
||||
|
||||
def test_delete_port_with_security_groups_port_doesnt_remove_pg(self):
|
||||
with self.network(set_context=True, tenant_id='test') as net1:
|
||||
|
@ -3406,30 +3394,26 @@ class TestOVNMechanismDriverSecurityGroup(
|
|||
self.fmt, net1['network']['id'],
|
||||
security_groups=[sg['id']])['port']
|
||||
fake_lsp = fakes.FakeOVNPort.from_neutron_port(port)
|
||||
self.mech_driver._nb_ovn.lookup.return_value = fake_lsp
|
||||
self.mech_driver._nb_ovn.delete_lswitch_port.reset_mock()
|
||||
self.mech_driver._nb_ovn.delete_acl.reset_mock()
|
||||
self.mech_driver.nb_ovn.lookup.return_value = fake_lsp
|
||||
self.mech_driver.nb_ovn.delete_lswitch_port.reset_mock()
|
||||
self.mech_driver.nb_ovn.delete_acl.reset_mock()
|
||||
self._delete('ports', port['id'])
|
||||
self.assertEqual(
|
||||
1, self.mech_driver._nb_ovn.delete_lswitch_port.call_count)
|
||||
self.assertFalse(self.mech_driver._nb_ovn.pg_del.called)
|
||||
self.assertFalse(self.mech_driver._nb_ovn.delete_acl.called)
|
||||
1, self.mech_driver.nb_ovn.delete_lswitch_port.call_count)
|
||||
self.assertFalse(self.mech_driver.nb_ovn.pg_del.called)
|
||||
self.assertFalse(self.mech_driver.nb_ovn.delete_acl.called)
|
||||
|
||||
|
||||
class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
|
||||
class TestOVNMechanismDriverMetadataPort(MechDriverSetupBase,
|
||||
test_plugin.Ml2PluginV2TestCase):
|
||||
|
||||
_mechanism_drivers = ['logger', 'ovn']
|
||||
|
||||
def setUp(self):
|
||||
mock.patch.object(impl_idl_ovn.Backend, 'schema_helper').start()
|
||||
super(TestOVNMechanismDriverMetadataPort, self).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._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.ctx = context.get_admin_context()
|
||||
ovn_conf.cfg.CONF.set_override('ovn_metadata_enabled', True,
|
||||
group='ovn')
|
||||
|
|
|
@ -37,7 +37,7 @@ class TestTrunkHandler(base.BaseTestCase):
|
|||
self.plugin_driver = mock.Mock()
|
||||
self.plugin_driver._plugin = mock.Mock()
|
||||
self.plugin_driver._plugin.update_port = mock.Mock()
|
||||
self.plugin_driver._nb_ovn = fake_resources.FakeOvsdbNbOvnIdl()
|
||||
self.plugin_driver.nb_ovn = fake_resources.FakeOvsdbNbOvnIdl()
|
||||
self.handler = trunk_driver.OVNTrunkHandler(self.plugin_driver)
|
||||
self.trunk_1 = mock.Mock()
|
||||
self.trunk_1.port_id = "trunk-1"
|
||||
|
@ -107,7 +107,7 @@ class TestTrunkHandler(base.BaseTestCase):
|
|||
def test_create_trunk(self):
|
||||
self.trunk_1.sub_ports = []
|
||||
self.handler.trunk_created(self.trunk_1)
|
||||
self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.plugin_driver.nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.mock_update_pb.assert_not_called()
|
||||
|
||||
self.trunk_1.sub_ports = [self.sub_port_1, self.sub_port_2]
|
||||
|
@ -132,13 +132,13 @@ class TestTrunkHandler(base.BaseTestCase):
|
|||
tag=s_port.segmentation_id)
|
||||
for trunk, s_port in [(self.trunk_1, self.sub_port_1),
|
||||
(self.trunk_1, self.sub_port_2)]]
|
||||
self._assert_calls(self.plugin_driver._nb_ovn.set_lswitch_port, calls)
|
||||
self._assert_calls(self.plugin_driver.nb_ovn.set_lswitch_port, calls)
|
||||
self.mock_clear_levels.assert_not_called()
|
||||
|
||||
def test_create_trunk_port_not_found(self):
|
||||
self.trunk_1.sub_ports = [self.sub_port_4]
|
||||
self.handler.trunk_created(self.trunk_1)
|
||||
self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.plugin_driver.nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.mock_update_pb.assert_not_called()
|
||||
|
||||
def test_create_trunk_port_db_exception(self):
|
||||
|
@ -151,12 +151,12 @@ class TestTrunkHandler(base.BaseTestCase):
|
|||
'vif_type': portbindings.VIF_TYPE_OVS},
|
||||
host='foo.com', port_id=self.sub_port_1.port_id)
|
||||
self.mock_port_update.assert_not_called()
|
||||
self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.plugin_driver.nb_ovn.set_lswitch_port.assert_not_called()
|
||||
|
||||
def test_delete_trunk(self):
|
||||
self.trunk_1.sub_ports = []
|
||||
self.handler.trunk_deleted(self.trunk_1)
|
||||
self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.plugin_driver.nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.mock_update_pb.assert_not_called()
|
||||
self.mock_clear_levels.assert_not_called()
|
||||
|
||||
|
@ -199,7 +199,7 @@ class TestTrunkHandler(base.BaseTestCase):
|
|||
up=False)
|
||||
for trunk, s_port in [(self.trunk_1, self.sub_port_1),
|
||||
(self.trunk_1, self.sub_port_2)]]
|
||||
self._assert_calls(self.plugin_driver._nb_ovn.set_lswitch_port, calls)
|
||||
self._assert_calls(self.plugin_driver.nb_ovn.set_lswitch_port, calls)
|
||||
|
||||
def test_delete_trunk_key_not_found(self):
|
||||
self.sub_port_1_obj.bindings[0].profile.update({
|
||||
|
@ -227,12 +227,12 @@ class TestTrunkHandler(base.BaseTestCase):
|
|||
tag=[],
|
||||
up=False)
|
||||
for trunk, s_port in [(self.trunk_1, self.sub_port_1)]]
|
||||
self._assert_calls(self.plugin_driver._nb_ovn.set_lswitch_port, calls)
|
||||
self._assert_calls(self.plugin_driver.nb_ovn.set_lswitch_port, calls)
|
||||
|
||||
def test_delete_trunk_port_not_found(self):
|
||||
self.trunk_1.sub_ports = [self.sub_port_4]
|
||||
self.handler.trunk_deleted(self.trunk_1)
|
||||
self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.plugin_driver.nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.mock_update_pb.assert_not_called()
|
||||
self.mock_clear_levels.assert_not_called()
|
||||
|
||||
|
@ -245,7 +245,7 @@ class TestTrunkHandler(base.BaseTestCase):
|
|||
'vif_type': portbindings.VIF_TYPE_UNBOUND},
|
||||
host='foo.com', port_id=self.sub_port_1.port_id)
|
||||
self.mock_port_update.assert_not_called()
|
||||
self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.plugin_driver.nb_ovn.set_lswitch_port.assert_not_called()
|
||||
self.mock_clear_levels.assert_not_called()
|
||||
|
||||
def test_subports_added(self):
|
||||
|
|
Loading…
Reference in New Issue