From 0fe6c0b8ca8a5704242766472d94d5ca86832363 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 26 Jan 2022 17:37:07 +0000 Subject: [PATCH] Use the "connectivity" property of "MechanismDriver" The base class "MechanismDriver" now has a property called "connectivity". This patch overrides the default value in the in-tree drivers. The method "_check_drivers_connectivity" now uses this property that is available in all drivers. Depends-On: https://review.opendev.org/c/openstack/neutron-lib/+/826501 Closes-Bug: #1959125 bp boot-vm-with-unaddressed-port Related-Bug: #1821058 Change-Id: I91734835b07d804365b46adfb26e984557107d80 --- .../linuxbridge/mech_driver/mech_linuxbridge.py | 6 +++++- .../ml2/drivers/macvtap/mech_driver/mech_macvtap.py | 6 +++++- neutron/plugins/ml2/drivers/mech_agent.py | 2 +- .../ml2/drivers/mech_sriov/mech_driver/mech_driver.py | 6 +++++- .../openvswitch/mech_driver/mech_openvswitch.py | 6 +++++- .../plugins/ml2/drivers/ovn/mech_driver/mech_driver.py | 10 ++++++---- neutron/plugins/ml2/managers.py | 4 +--- .../tests/unit/plugins/ml2/drivers/mech_fake_agent.py | 8 ++++++++ 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py b/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py index 07063bbfa20..c63da7fd2f4 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/mech_driver/mech_linuxbridge.py @@ -35,13 +35,17 @@ class LinuxbridgeMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): sg_enabled = securitygroups_rpc.is_firewall_enabled() vif_details = {portbindings.CAP_PORT_FILTER: sg_enabled, portbindings.VIF_DETAILS_CONNECTIVITY: - portbindings.CONNECTIVITY_L2} + self.connectivity} super(LinuxbridgeMechanismDriver, self).__init__( constants.AGENT_TYPE_LINUXBRIDGE, portbindings.VIF_TYPE_BRIDGE, vif_details) lb_qos_driver.register() + @property + def connectivity(self): + return portbindings.CONNECTIVITY_L2 + def get_allowed_network_types(self, agent): return (agent['configurations'].get('tunnel_types', []) + [constants.TYPE_LOCAL, constants.TYPE_FLAT, diff --git a/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py b/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py index 31bcc45c00c..e43abab6cae 100644 --- a/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py +++ b/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py @@ -40,12 +40,16 @@ class MacvtapMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): def __init__(self): vif_details = {portbindings.CAP_PORT_FILTER: False, portbindings.VIF_DETAILS_CONNECTIVITY: - portbindings.CONNECTIVITY_L2} + self.connectivity} super(MacvtapMechanismDriver, self).__init__( constants.AGENT_TYPE_MACVTAP, portbindings.VIF_TYPE_MACVTAP, vif_details) + @property + def connectivity(self): + return portbindings.CONNECTIVITY_L2 + def get_allowed_network_types(self, agent): return [constants.TYPE_FLAT, constants.TYPE_VLAN] diff --git a/neutron/plugins/ml2/drivers/mech_agent.py b/neutron/plugins/ml2/drivers/mech_agent.py index bbca9bc6251..4f34001a203 100644 --- a/neutron/plugins/ml2/drivers/mech_agent.py +++ b/neutron/plugins/ml2/drivers/mech_agent.py @@ -296,7 +296,7 @@ class SimpleAgentMechanismDriverBase(AgentMechanismDriverBase, self.supported_vnic_types, vnic_type_prohibit_list) self.vif_type = vif_type self.vif_details = {portbindings.VIF_DETAILS_CONNECTIVITY: - portbindings.CONNECTIVITY_LEGACY} + self.connectivity} self.vif_details.update(vif_details) def try_to_bind_segment_for_agent(self, context, segment, agent): diff --git a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py index 393e1c1ff1c..2a4a639ba15 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py @@ -69,7 +69,7 @@ class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): agent_type = constants.AGENT_TYPE_NIC_SWITCH vif_details = {portbindings.CAP_PORT_FILTER: False, portbindings.VIF_DETAILS_CONNECTIVITY: - portbindings.CONNECTIVITY_L2} + self.connectivity} supported_vnic_types = SRIOV_SUPPORTED_VNIC_TYPES prohibit_list = cfg.CONF.SRIOV_DRIVER.vnic_type_prohibit_list super().__init__(agent_type, None, vif_details, @@ -85,6 +85,10 @@ class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): self.vif_details = vif_details sriov_qos_driver.register() + @property + def connectivity(self): + return portbindings.CONNECTIVITY_L2 + def get_allowed_network_types(self, agent): return (constants.TYPE_FLAT, constants.TYPE_VLAN) diff --git a/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py b/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py index c0bb857a929..e7dfd9a67d7 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py +++ b/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py @@ -58,7 +58,7 @@ class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): sg_enabled = securitygroups_rpc.is_firewall_enabled() vif_details = {portbindings.CAP_PORT_FILTER: sg_enabled, portbindings.VIF_DETAILS_CONNECTIVITY: - portbindings.CONNECTIVITY_L2} + self.connectivity} # NOTE(moshele): Bind DIRECT (SR-IOV) port allows # to offload the OVS flows using tc to the SR-IOV NIC. # We are using OVS mechanism driver because the openvswitch (>=2.8.0) @@ -80,6 +80,10 @@ class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): ovs_qos_driver.register() log_driver.register() + @property + def connectivity(self): + return portbindings.CONNECTIVITY_L2 + def get_allowed_network_types(self, agent): return (agent['configurations'].get('tunnel_types', []) + [constants.TYPE_LOCAL, constants.TYPE_FLAT, diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py index e92aba70595..2145b9d3204 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py @@ -194,19 +194,21 @@ class OVNMechanismDriver(api.MechanismDriver): self.vif_details = { portbindings.VIF_TYPE_OVS: { portbindings.CAP_PORT_FILTER: self.sg_enabled, - portbindings.VIF_DETAILS_CONNECTIVITY: - portbindings.CONNECTIVITY_L2, + portbindings.VIF_DETAILS_CONNECTIVITY: self.connectivity, }, portbindings.VIF_TYPE_VHOST_USER: { portbindings.CAP_PORT_FILTER: False, portbindings.VHOST_USER_MODE: portbindings.VHOST_USER_MODE_SERVER, portbindings.VHOST_USER_OVS_PLUG: True, - portbindings.VIF_DETAILS_CONNECTIVITY: - portbindings.CONNECTIVITY_L2, + portbindings.VIF_DETAILS_CONNECTIVITY: self.connectivity, }, } + @property + def connectivity(self): + return portbindings.CONNECTIVITY_L2 + def supported_extensions(self, extensions): return set(ovn_extensions.ML2_SUPPORTED_API_EXTENSIONS) & extensions diff --git a/neutron/plugins/ml2/managers.py b/neutron/plugins/ml2/managers.py index 6268e2956e5..b60ffb8483e 100644 --- a/neutron/plugins/ml2/managers.py +++ b/neutron/plugins/ml2/managers.py @@ -1055,9 +1055,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): return drivers return [d for d in drivers if - getattr(d.obj, 'vif_details', {}).get( - portbindings.VIF_DETAILS_CONNECTIVITY) == - portbindings.CONNECTIVITY_L2] + d.obj.connectivity == portbindings.CONNECTIVITY_L2] def get_workers(self): workers = [] diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py b/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py index ed0bad07c43..4008c75a59c 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_fake_agent.py @@ -64,6 +64,10 @@ class FakeAgentMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): def get_mappings(self, agent): return dict(agent['configurations'].get('interface_mappings', {})) + @property + def connectivity(self): + return portbindings.CONNECTIVITY_L2 + class AnotherFakeAgentMechanismDriver(FakeAgentMechanismDriver): pass @@ -76,3 +80,7 @@ class FakeAgentMechanismDriverL3(FakeAgentMechanismDriver): super(FakeAgentMechanismDriverL3, self).__init__() self.vif_details[portbindings.VIF_DETAILS_CONNECTIVITY] = ( portbindings.CONNECTIVITY_L3) + + @property + def connectivity(self): + return portbindings.CONNECTIVITY_L3