Browse Source

Merge "[OVN] OVN driver to adapt to enable_distributed_floating_ip changes" into stable/train

changes/32/749832/1
Zuul 3 weeks ago
committed by Gerrit Code Review
parent
commit
521f2b932f
5 changed files with 45 additions and 27 deletions
  1. +7
    -7
      networking_ovn/common/ovn_client.py
  2. +12
    -12
      networking_ovn/ml2/mech_driver.py
  3. +3
    -0
      networking_ovn/tests/functional/test_ovn_db_sync.py
  4. +21
    -7
      networking_ovn/tests/unit/l3/test_l3_ovn.py
  5. +2
    -1
      networking_ovn/tests/unit/ml2/test_mech_driver.py

+ 7
- 7
networking_ovn/common/ovn_client.py View File

@@ -627,6 +627,8 @@ class OVNClient(object):
commands = []
context = n_context.get_admin_context()
fip_db = self._l3_plugin._get_floatingip(context, floatingip['id'])
port_db = self._plugin.get_port(
context, fip_db['floating_port_id'])

gw_lrouter_name = utils.ovn_name(router_id)
# TODO(chandrav): Since the floating ip port is not
@@ -644,18 +646,16 @@ class OVNClient(object):
ovn_const.OVN_REV_NUM_EXT_ID_KEY: str(utils.get_revision_number(
floatingip, ovn_const.TYPE_FLOATINGIPS)),
ovn_const.OVN_FIP_PORT_EXT_ID_KEY: floatingip['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: gw_lrouter_name}
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: gw_lrouter_name,
ovn_const.OVN_FIP_EXT_MAC_KEY: port_db['mac_address']}
columns = {'type': 'dnat_and_snat',
'logical_ip': floatingip['fixed_ip_address'],
'external_ip': floatingip['floating_ip_address']}
'external_ip': floatingip['floating_ip_address'],
'logical_port': floatingip['port_id']}

if config.is_ovn_distributed_floating_ip():
port = self._plugin.get_port(
context, fip_db['floating_port_id'])
columns['logical_port'] = floatingip['port_id']
ext_ids[ovn_const.OVN_FIP_EXT_MAC_KEY] = port['mac_address']
if self._nb_idl.lsp_get_up(floatingip['port_id']).execute():
columns['external_mac'] = port['mac_address']
columns['external_mac'] = port_db['mac_address']

# TODO(dalvarez): remove this check once the minimum OVS required
# version contains the column (when OVS 2.8.2 is released).


+ 12
- 12
networking_ovn/ml2/mech_driver.py View File

@@ -800,9 +800,6 @@ 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 config.is_ovn_distributed_floating_ip():
return

if not self._nb_ovn:
self._nb_ovn = self._ovn_client._nb_idl

@@ -822,17 +819,20 @@ class OVNMechanismDriver(api.MechanismDriver):
{ovn_const.OVN_FIP_EXT_MAC_KEY:
nat['external_mac']})).execute()

if up:
if up and config.is_ovn_distributed_floating_ip():
mac = nat['external_ids'][ovn_const.OVN_FIP_EXT_MAC_KEY]
LOG.debug("Setting external_mac of port %s to %s",
port_id, mac)
self._nb_ovn.db_set(
'NAT', nat['_uuid'],
('external_mac', mac)).execute(check_error=True)
if nat['external_mac'] != mac:
LOG.debug("Setting external_mac of port %s to %s",
port_id, mac)
self._nb_ovn.db_set(
'NAT', nat['_uuid'], ('external_mac', mac)).execute(
check_error=True)
else:
LOG.debug("Clearing up external_mac of port %s", port_id)
self._nb_ovn.db_clear(
'NAT', nat['_uuid'], 'external_mac').execute(check_error=True)
if nat['external_mac']:
LOG.debug("Clearing up external_mac of port %s", port_id)
self._nb_ovn.db_clear(
'NAT', nat['_uuid'], 'external_mac').execute(
check_error=True)

def _should_notify_nova(self, db_port):
# NOTE(twilson) It is possible for a test to override a config option


+ 3
- 0
networking_ovn/tests/functional/test_ovn_db_sync.py View File

@@ -76,6 +76,9 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
self.expected_ports_with_unknown_addr = []
ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', True,
group='ovn')
ovn_config.cfg.CONF.set_override(
'enable_distributed_floating_ip', True, group='ovn')


def _api_for_resource(self, resource):
if resource in ['security-groups']:


+ 21
- 7
networking_ovn/tests/unit/l3/test_l3_ovn.py View File

@@ -891,12 +891,14 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_FIP_PORT_EXT_ID_KEY:
self.fake_floating_ip['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: utils.ovn_name(
self.fake_floating_ip['router_id'])}
self.fake_floating_ip['router_id']),
ovn_const.OVN_FIP_EXT_MAC_KEY: 'aa:aa:aa:aa:aa:aa'}
self.l3_inst._ovn.add_nat_rule_in_lrouter.assert_called_once_with(
'neutron-router-id',
type='dnat_and_snat',
logical_ip='10.0.0.10',
external_ip='192.168.0.10',
logical_port='port_id',
external_ids=expected_ext_ids)
self.l3_inst._ovn.delete_lswitch_port.assert_called_once_with(
'fip-port-id', 'neutron-fip-net-id')
@@ -967,12 +969,14 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_FIP_PORT_EXT_ID_KEY:
self.fake_floating_ip['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: utils.ovn_name(
self.fake_floating_ip['router_id'])}
self.fake_floating_ip['router_id']),
ovn_const.OVN_FIP_EXT_MAC_KEY: 'aa:aa:aa:aa:aa:aa'}
self.l3_inst._ovn.add_nat_rule_in_lrouter.assert_called_once_with(
'neutron-router-id',
type='dnat_and_snat',
logical_ip='10.0.0.10',
external_ip='192.168.0.10',
logical_port='port_id',
external_ids=expected_ext_ids)
self.l3_inst._ovn.delete_lswitch_port.assert_called_once_with(
'fip-port-id', 'neutron-fip-net-id')
@@ -992,12 +996,14 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_FIP_PORT_EXT_ID_KEY:
self.fake_floating_ip['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: utils.ovn_name(
self.fake_floating_ip['router_id'])}
self.fake_floating_ip['router_id']),
ovn_const.OVN_FIP_EXT_MAC_KEY: 'aa:aa:aa:aa:aa:aa'}
self.l3_inst._ovn.add_nat_rule_in_lrouter.assert_called_once_with(
'neutron-router-id',
type='dnat_and_snat',
logical_ip='10.0.0.10',
external_ip='192.168.0.10',
logical_port='port_id',
external_ids=expected_ext_ids)
self.l3_inst._ovn.delete_lswitch_port.assert_called_once_with(
'fip-port-id', 'neutron-fip-net-id')
@@ -1161,12 +1167,14 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_FIP_PORT_EXT_ID_KEY:
self.fake_floating_ip_new['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: utils.ovn_name(
self.fake_floating_ip_new['router_id'])}
self.fake_floating_ip_new['router_id']),
ovn_const.OVN_FIP_EXT_MAC_KEY: 'aa:aa:aa:aa:aa:aa'}
self.l3_inst._ovn.add_nat_rule_in_lrouter.assert_called_once_with(
'neutron-new-router-id',
type='dnat_and_snat',
logical_ip='10.10.10.10',
external_ip='192.168.0.10',
logical_port='new-port_id',
external_ids=expected_ext_ids)

@mock.patch('neutron.db.l3_db.L3_NAT_dbonly_mixin._get_floatingip')
@@ -1185,12 +1193,14 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_FIP_PORT_EXT_ID_KEY:
self.fake_floating_ip_new['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: utils.ovn_name(
self.fake_floating_ip_new['router_id'])}
self.fake_floating_ip_new['router_id']),
ovn_const.OVN_FIP_EXT_MAC_KEY: 'aa:aa:aa:aa:aa:aa'}
self.l3_inst._ovn.add_nat_rule_in_lrouter.assert_called_once_with(
'neutron-new-router-id',
type='dnat_and_snat',
logical_ip='10.10.10.10',
external_ip='192.168.0.10',
logical_port='new-port_id',
external_ids=expected_ext_ids)

@mock.patch('neutron.db.db_base_plugin_v2.NeutronDbPluginV2.get_network')
@@ -1251,12 +1261,14 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_FIP_PORT_EXT_ID_KEY:
self.fake_floating_ip_new['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: utils.ovn_name(
self.fake_floating_ip_new['router_id'])}
self.fake_floating_ip_new['router_id']),
ovn_const.OVN_FIP_EXT_MAC_KEY: 'aa:aa:aa:aa:aa:aa'}
self.l3_inst._ovn.add_nat_rule_in_lrouter.assert_called_once_with(
'neutron-new-router-id',
type='dnat_and_snat',
logical_ip='10.10.10.10',
external_ip='192.168.0.10',
logical_port='foo',
external_ids=expected_ext_ids)

@mock.patch('neutron.db.l3_db.L3_NAT_dbonly_mixin._get_floatingip')
@@ -1284,12 +1296,14 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_FIP_PORT_EXT_ID_KEY:
self.fake_floating_ip_new['port_id'],
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: utils.ovn_name(
self.fake_floating_ip_new['router_id'])}
self.fake_floating_ip_new['router_id']),
ovn_const.OVN_FIP_EXT_MAC_KEY: 'aa:aa:aa:aa:aa:aa'}
self.l3_inst._ovn.add_nat_rule_in_lrouter.assert_called_once_with(
'neutron-new-router-id',
type='dnat_and_snat',
logical_ip='10.10.10.10',
external_ip='192.168.0.10',
logical_port='port_id',
external_ids=expected_ext_ids)

@mock.patch('neutron.db.l3_db.L3_NAT_dbonly_mixin.get_floatingips')


+ 2
- 1
networking_ovn/tests/unit/ml2/test_mech_driver.py View File

@@ -1566,7 +1566,8 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase):
fake_nat_uuid = uuidutils.generate_uuid()
nat_row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
attrs={'_uuid': fake_nat_uuid, 'external_ids': {
ovn_const.OVN_FIP_EXT_MAC_KEY: fake_ext_mac_key}})
ovn_const.OVN_FIP_EXT_MAC_KEY: fake_ext_mac_key},
'external_mac': 'aa:aa:aa:aa:aa:aa'})

fake_db_find = mock.Mock()
fake_db_find.execute.return_value = [nat_row]


Loading…
Cancel
Save