From 352f5ac674dde0d76ebe92d80b2cb02638b80ade Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Fri, 14 Jun 2019 10:35:46 +0200 Subject: [PATCH] Fix update of network's segmentation id In patch [1] there was added usage of context parameter in method get_vif_type in openvswitch mech_driver. This exposed that previously "wrong" context was passed to this method in _update_segmentation_id() method in ml2 plugin and that caused raising AttributeError as "Context" object didn't have attribute 'current'. This patch adds new method "get_supported_vif_type" to mechanism drivers and this method don't need context to return what vif_types are supported regarding agent type. [1] https://review.opendev.org/#/c/658784/ Change-Id: Ic6c738db28208e5009f78bb52598eb3c141f639f Related-Bug: #1832985 --- neutron/plugins/ml2/drivers/mech_agent.py | 4 ++++ .../openvswitch/mech_driver/mech_openvswitch.py | 12 +++++++----- neutron/plugins/ml2/plugin.py | 4 ++-- .../tests/unit/plugins/ml2/drivers/mechanism_test.py | 3 +++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/neutron/plugins/ml2/drivers/mech_agent.py b/neutron/plugins/ml2/drivers/mech_agent.py index f24ec9d85ab..e13d97d2ae4 100644 --- a/neutron/plugins/ml2/drivers/mech_agent.py +++ b/neutron/plugins/ml2/drivers/mech_agent.py @@ -279,6 +279,10 @@ class SimpleAgentMechanismDriverBase(AgentMechanismDriverBase): def get_vif_details(self, context, agent, segment): return self.vif_details + def get_supported_vif_type(self, agent): + """Return supported vif type appropriate for the agent.""" + return self.vif_type + def get_vif_type(self, context, agent, segment): """Return the vif type appropriate for the agent and segment.""" return self.vif_type 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 48bc3a62ab7..25f3832a708 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py +++ b/neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py @@ -132,11 +132,7 @@ class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): return super(OpenvswitchMechanismDriver, self).bind_port(context) - def get_vif_type(self, context, agent, segment): - if (context.current.get(portbindings.VNIC_TYPE) == - portbindings.VNIC_DIRECT): - return portbindings.VIF_TYPE_OVS - + def get_supported_vif_type(self, agent): caps = agent['configurations'].get('ovs_capabilities', {}) if (any(x in caps.get('iface_types', []) for x in [a_const.OVS_DPDK_VHOST_USER, @@ -146,6 +142,12 @@ class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): return portbindings.VIF_TYPE_VHOST_USER return self.vif_type + def get_vif_type(self, context, agent, segment): + if (context.current.get(portbindings.VNIC_TYPE) == + portbindings.VNIC_DIRECT): + return portbindings.VIF_TYPE_OVS + return self.get_supported_vif_type(agent) + def get_vhost_mode(self, iface_types): # NOTE(sean-k-mooney): this function converts the ovs vhost user # driver mode into the qemu vhost user mode. If OVS is the server, diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 5da2b32be04..f9c6c7decfa 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -846,8 +846,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, agents = self.get_agents( context, filters={'agent_type': [agent_type]}) for agent in agents: - vif_types.append(mech_driver.obj.get_vif_type( - context, agent, segments[0])) + vif_types.append( + mech_driver.obj.get_supported_vif_type(agent)) filter_obj = obj_utils.NotIn(vif_types) filters = {portbindings.VIF_TYPE: diff --git a/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py b/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py index 8bedf3397a9..a17ed2d987a 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py @@ -277,6 +277,9 @@ class TestMechanismDriverWithAgent(mech_agent.AgentMechanismDriverBase, self.bound_ports = set() self._agent_type = 'test_mechanism_driver_agent' + def get_supported_vif_type(self, agent): + return VIF_TYPE_TEST + def get_vif_type(self, context, agent, segment): return VIF_TYPE_TEST