Merge "Move mech driver VNIC validation to SimpleAgentMechanismDriverBase"

This commit is contained in:
Zuul 2021-07-20 16:42:57 +00:00 committed by Gerrit Code Review
commit 9f8ff42a48
5 changed files with 52 additions and 52 deletions

View File

@ -42,8 +42,7 @@ class AgentMechanismDriverBase(api.MechanismDriver, metaclass=abc.ABCMeta):
__init__(), and must implement try_to_bind_segment_for_agent().
"""
def __init__(self, agent_type,
supported_vnic_types=[portbindings.VNIC_NORMAL]):
def __init__(self, agent_type, supported_vnic_types):
"""Initialize base class for specific L2 agent type.
:param agent_type: Constant identifying agent type in agents_db
@ -144,9 +143,12 @@ class AgentMechanismDriverBase(api.MechanismDriver, metaclass=abc.ABCMeta):
:param vnic_types: The supported_vnic_types list
:param prohibit_list: The prohibit_list as in vnic_type_prohibit_list
:return The prohibited vnic_types
:return The supported vnic_types minus those ones present in
prohibit_list
"""
if not prohibit_list:
LOG.info("%s's supported_vnic_types: %s", self.agent_type,
vnic_types)
return vnic_types
# Not valid values in the prohibit_list:
@ -166,6 +168,9 @@ class AgentMechanismDriverBase(api.MechanismDriver, metaclass=abc.ABCMeta):
if len(supported_vnic_types) < 1:
raise ValueError(_("All possible vnic_types were prohibited for "
"%s mechanism driver!") % self.agent_type)
LOG.info("%s's supported_vnic_types: %s", self.agent_type,
supported_vnic_types)
return supported_vnic_types
def _possible_agents_for_port(self, context):
@ -254,16 +259,22 @@ class SimpleAgentMechanismDriverBase(AgentMechanismDriverBase,
"""
def __init__(self, agent_type, vif_type, vif_details,
supported_vnic_types=[portbindings.VNIC_NORMAL]):
supported_vnic_types=None, vnic_type_prohibit_list=None):
"""Initialize base class for specific L2 agent type.
:param agent_type: Constant identifying agent type in agents_db
:param vif_type: Value for binding:vif_type when bound
:param vif_details: Dictionary with details for VIF driver when bound
:param supported_vnic_types: The binding:vnic_type values we can bind
:param vnic_type_prohibit_list: VNIC types administratively prohibited
by the mechanism driver
"""
supported_vnic_types = (supported_vnic_types or
[portbindings.VNIC_NORMAL])
super(SimpleAgentMechanismDriverBase, self).__init__(
agent_type, supported_vnic_types)
self.supported_vnic_types = self.prohibit_list_supported_vnic_types(
self.supported_vnic_types, vnic_type_prohibit_list)
self.vif_type = vif_type
self.vif_details = {portbindings.VIF_DETAILS_CONNECTIVITY:
portbindings.CONNECTIVITY_LEGACY}

View File

@ -35,6 +35,12 @@ FLAT_VLAN = 0
mech_sriov_conf.register_sriov_mech_driver_opts()
SRIOV_SUPPORTED_VNIC_TYPES = [
portbindings.VNIC_DIRECT,
portbindings.VNIC_MACVTAP,
portbindings.VNIC_DIRECT_PHYSICAL,
portbindings.VNIC_ACCELERATOR_DIRECT,
]
class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
@ -53,32 +59,22 @@ class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
resource_provider_uuid5_namespace = uuid.UUID(
'87f1895c-73bb-11e8-9008-c4d987b2a692')
def __init__(self,
agent_type=constants.AGENT_TYPE_NIC_SWITCH,
vif_details={portbindings.CAP_PORT_FILTER: False,
portbindings.VIF_DETAILS_CONNECTIVITY:
portbindings.CONNECTIVITY_L2},
supported_vnic_types=[
portbindings.VNIC_DIRECT,
portbindings.VNIC_MACVTAP,
portbindings.VNIC_DIRECT_PHYSICAL,
portbindings.VNIC_ACCELERATOR_DIRECT,
]):
def __init__(self):
"""Initialize base class for SriovNicSwitch L2 agent type.
:param agent_type: Constant identifying agent type in agents_db
:param vif_details: Dictionary with details for VIF driver when bound
:param supported_vnic_types: The binding:vnic_type values we can bind
"""
self.agent_type = agent_type
# TODO(lajoskatona): move this prohibition to
# SimpleAgentMechanismDriverBase. By that, prohibition and validation
# of the vnic_types would be available for all mechanism drivers.
self.supported_vnic_types = self.prohibit_list_supported_vnic_types(
vnic_types=supported_vnic_types,
prohibit_list=cfg.CONF.SRIOV_DRIVER.vnic_type_prohibit_list
)
agent_type = constants.AGENT_TYPE_NIC_SWITCH
vif_details = {portbindings.CAP_PORT_FILTER: False,
portbindings.VIF_DETAILS_CONNECTIVITY:
portbindings.CONNECTIVITY_L2}
supported_vnic_types = SRIOV_SUPPORTED_VNIC_TYPES
prohibit_list = cfg.CONF.SRIOV_DRIVER.vnic_type_prohibit_list
super().__init__(agent_type, None, vif_details,
supported_vnic_types=supported_vnic_types,
vnic_type_prohibit_list=prohibit_list)
# NOTE(ndipanov): PF passthrough requires a different vif type
self.vnic_type_for_vif_type = (

View File

@ -64,24 +64,18 @@ class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
# We are using OVS mechanism driver because the openvswitch (>=2.8.0)
# support hardware offload via tc and that allow us to manage the VF by
# OpenFlow control plane using representor net-device.
supported_vnic_types = [portbindings.VNIC_NORMAL,
portbindings.VNIC_DIRECT,
portbindings.VNIC_SMARTNIC,
portbindings.VNIC_VHOST_VDPA,
]
prohibit_list = cfg.CONF.OVS_DRIVER.vnic_type_prohibit_list
super(OpenvswitchMechanismDriver, self).__init__(
constants.AGENT_TYPE_OVS,
portbindings.VIF_TYPE_OVS,
vif_details)
# TODO(lajoskatona): move this prohibition to
# SimpleAgentMechanismDriverBase. By that, prohibition and validation
# of the vnic_types would be available for all mechanism drivers.
self.supported_vnic_types = self.prohibit_list_supported_vnic_types(
vnic_types=[portbindings.VNIC_NORMAL,
portbindings.VNIC_DIRECT,
portbindings.VNIC_SMARTNIC,
portbindings.VNIC_VHOST_VDPA,
],
prohibit_list=cfg.CONF.OVS_DRIVER.vnic_type_prohibit_list
)
LOG.info("%s's supported_vnic_types: %s",
self.agent_type, self.supported_vnic_types)
vif_details,
supported_vnic_types=supported_vnic_types,
vnic_type_prohibit_list=prohibit_list)
ovs_qos_driver.register()
log_driver.register()

View File

@ -227,15 +227,11 @@ class SriovSwitchMechVnicTypesTestCase(SriovNicSwitchMechanismBaseTestCase):
def setUp(self):
self.override_vnic_types = [portbindings.VNIC_DIRECT,
portbindings.VNIC_MACVTAP]
self.driver_with_vnic_types = \
mech_driver.SriovNicSwitchMechanismDriver(
supported_vnic_types=self.override_vnic_types)
self.default_supported_vnics = [
portbindings.VNIC_DIRECT,
portbindings.VNIC_MACVTAP,
portbindings.VNIC_DIRECT_PHYSICAL,
portbindings.VNIC_ACCELERATOR_DIRECT,
]
self.default_supported_vnics = list(
mech_driver.SRIOV_SUPPORTED_VNIC_TYPES)
mech_driver.SRIOV_SUPPORTED_VNIC_TYPES = self.override_vnic_types
self.driver_with_vnic_types = (
mech_driver.SriovNicSwitchMechanismDriver())
self.prohibit_list_cfg = {
'SRIOV_DRIVER': {
'vnic_type_prohibit_list': []
@ -244,8 +240,10 @@ class SriovSwitchMechVnicTypesTestCase(SriovNicSwitchMechanismBaseTestCase):
super(SriovSwitchMechVnicTypesTestCase, self).setUp()
def test_default_vnic_types(self):
mech_driver.SRIOV_SUPPORTED_VNIC_TYPES = self.default_supported_vnics
mech_sriov = mech_driver.SriovNicSwitchMechanismDriver()
self.assertEqual(self.default_supported_vnics,
self.driver.supported_vnic_types)
mech_sriov.supported_vnic_types)
def test_override_default_vnic_types(self):
self.assertEqual(
@ -262,8 +260,8 @@ class SriovSwitchMechVnicTypesTestCase(SriovNicSwitchMechanismBaseTestCase):
mech_sriov_conf.register_sriov_mech_driver_opts)
self.useFixture(fake_conf_fixture)
test_driver = mech_driver.SriovNicSwitchMechanismDriver(
supported_vnic_types=self.default_supported_vnics)
mech_driver.SRIOV_SUPPORTED_VNIC_TYPES = self.default_supported_vnics
test_driver = mech_driver.SriovNicSwitchMechanismDriver()
supported_vnic_types = test_driver.supported_vnic_types
self.assertNotIn(portbindings.VNIC_MACVTAP, supported_vnic_types)

View File

@ -279,7 +279,8 @@ class TestMechanismDriverWithAgent(mech_agent.AgentMechanismDriverBase,
"""Test mechanism driver with agent for testing mechanism driver api."""
def __init__(self):
super(TestMechanismDriverWithAgent, self).__init__('test_agent_type')
super(TestMechanismDriverWithAgent, self).__init__(
'test_agent_type', [portbindings.VNIC_NORMAL])
self.bound_ports = set()
self._agent_type = 'test_mechanism_driver_agent'