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
This commit is contained in:
Slawek Kaplonski 2019-06-14 10:35:46 +02:00
parent 144e6501bd
commit 352f5ac674
4 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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,

View File

@ -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:

View File

@ -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