From 6a89dbfe47ae1f384e08fede3bb6afae2ada7b9c Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Wed, 31 Jul 2019 13:41:34 +0100 Subject: [PATCH] Only set "unknown" in LSP that makes sense Prior to this patch, the "unknown" address was being set the logical switch ports solely based on whether the port security was enabled or disabled. That's not how it's intended to work. With this patch the "unknown" address is only set to the normal logical switch ports, those which types are "router", "localnet" or "localport" won't be affected. The maintenance task was updated to correct this behavior for existing ports (the maintenance was suppose to be removed in the T cycle, this patch bumps it to U cycle instead due to this change). Closes-Bug: #1838535 Related-Bug: #1815270 Change-Id: I3c01bd7d1685c8a7e13a55e545e98baf19e9a0f9 Signed-off-by: Lucas Alvares Gomes --- networking_ovn/common/constants.py | 5 +++++ networking_ovn/common/maintenance.py | 21 +++++++++++++++------ networking_ovn/common/ovn_client.py | 24 +++++++++++++----------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/networking_ovn/common/constants.py b/networking_ovn/common/constants.py index 1a82e0ff3..2e4dcb0cf 100644 --- a/networking_ovn/common/constants.py +++ b/networking_ovn/common/constants.py @@ -167,3 +167,8 @@ HASH_RING_ML2_GROUP = 'mechanism_driver' # Maximum chassis count where a gateway port can be hosted MAX_GW_CHASSIS = 5 + +UNKNOWN_ADDR = 'unknown' + +# TODO(lucasagomes): Create constants for other LSP types +LSP_TYPE_LOCALNET = 'localnet' diff --git a/networking_ovn/common/maintenance.py b/networking_ovn/common/maintenance.py index ef5bff967..5ab252d6a 100644 --- a/networking_ovn/common/maintenance.py +++ b/networking_ovn/common/maintenance.py @@ -403,7 +403,7 @@ class DBInconsistenciesPeriodics(object): raise periodics.NeverAgain() - # TODO(lucasagomes): Remove this in the T cycle + # TODO(lucasagomes): Remove this in the U cycle # A static spacing value is used here, but this method will only run # once per lock due to the use of periodics.NeverAgain(). @periodics.periodic(spacing=600, run_immediately=True) @@ -413,13 +413,22 @@ class DBInconsistenciesPeriodics(object): return for port in self._nb_idl.lsp_list().execute(check_error=True): + + if port.type == ovn_const.LSP_TYPE_LOCALNET: + continue + addresses = port.addresses - if not port.port_security and 'unknown' not in addresses: - addresses.append('unknown') - elif port.port_security and 'unknown' in addresses: - addresses.remove('unknown') + type_ = port.type.strip() + if not port.port_security: + if not type_ and ovn_const.UNKNOWN_ADDR not in addresses: + addresses.append(ovn_const.UNKNOWN_ADDR) + elif type_ and ovn_const.UNKNOWN_ADDR in addresses: + addresses.remove(ovn_const.UNKNOWN_ADDR) else: - continue + if type_ and ovn_const.UNKNOWN_ADDR in addresses: + addresses.remove(ovn_const.UNKNOWN_ADDR) + elif not type_ and ovn_const.UNKNOWN_ADDR in addresses: + addresses.remove(ovn_const.UNKNOWN_ADDR) self._nb_idl.lsp_set_addresses( port.name, addresses=addresses).execute(check_error=True) diff --git a/networking_ovn/common/ovn_client.py b/networking_ovn/common/ovn_client.py index ac94828d5..ecefa6b89 100644 --- a/networking_ovn/common/ovn_client.py +++ b/networking_ovn/common/ovn_client.py @@ -204,7 +204,7 @@ class OVNClient(object): port_type = 'vtep' options = {'vtep-physical-switch': vtep_physical_switch, 'vtep-logical-switch': vtep_logical_switch} - addresses = ["unknown"] + addresses = [ovn_const.UNKNOWN_ADDR] parent_name = [] tag = [] port_security = [] @@ -227,20 +227,22 @@ class OVNClient(object): addresses = [address] addresses.extend(new_macs) - if not port_security: - # Port security is disabled for this port. - # So this port can send traffic with any mac address. - # OVN allows any mac address from a port if "unknown" - # is added to the Logical_Switch_Port.addresses column. - # So add it. - addresses.append("unknown") - # Only adjust the OVN type if the port is not owned by Neutron # DHCP agents. if (port['device_owner'] == const.DEVICE_OWNER_DHCP and not port['device_id'].startswith('dhcp')): port_type = 'localport' + # The "unknown" address should only be set for the normal LSP + # ports (the ones which type is empty) + if not port_security and not port_type: + # Port security is disabled for this port. + # So this port can send traffic with any mac address. + # OVN allows any mac address from a port if "unknown" + # is added to the Logical_Switch_Port.addresses column. + # So add it. + addresses.append(ovn_const.UNKNOWN_ADDR) + dhcpv4_options = self._get_port_dhcp_options(port, const.IP_VERSION_4) dhcpv6_options = self._get_port_dhcp_options(port, const.IP_VERSION_6) @@ -1362,9 +1364,9 @@ class OVNClient(object): txn.add(self._nb_idl.create_lswitch_port( lport_name=utils.ovn_provnet_port_name(network['id']), lswitch_name=utils.ovn_name(network['id']), - addresses=['unknown'], + addresses=[ovn_const.UNKNOWN_ADDR], external_ids={}, - type='localnet', + type=ovn_const.LSP_TYPE_LOCALNET, tag=tag if tag else [], options={'network_name': physnet}))