From 299c3f887161cad41805ff703f815ceb7c1d3567 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Thu, 17 Nov 2016 09:13:28 -0500 Subject: [PATCH] Move SR-IOV VIF type constants to the portbindings extension While referencing VIF types during the QoS plugin drivers refactor I noticed that SR-IOV had the VIF type constants defined in the mech_driver itself, instead of the portbindings extension. I wanted to make all the VIF type constants available from a single place instead of scattered. Change-Id: Iabb7e5e953c4509c39b2029839752b88af87387b --- neutron/extensions/portbindings.py | 3 +++ .../ml2/drivers/mech_sriov/mech_driver/mech_driver.py | 11 +++++------ .../mech_driver/test_mech_sriov_nic_switch.py | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/neutron/extensions/portbindings.py b/neutron/extensions/portbindings.py index 3fa4a2b1be5..1070e5bb580 100644 --- a/neutron/extensions/portbindings.py +++ b/neutron/extensions/portbindings.py @@ -89,6 +89,9 @@ VIF_TYPE_OTHER = 'other' # which is defined further below. E.g. Macvtap agent uses # vnic_type 'normal'. VIF_TYPE_MACVTAP = 'macvtap' +# SR-IOV VIF types +VIF_TYPE_HW_VEB = 'hw_veb' +VIF_TYPE_HOSTDEV_PHY = 'hostdev_physical' # VNIC_TYPE: It's used to determine which mechanism driver to use to bind a # port. It can be specified via the Neutron API. Default is normal, 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 fe09950b784..2acce410923 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 @@ -27,8 +27,6 @@ from neutron.services.qos import qos_consts LOG = log.getLogger(__name__) -VIF_TYPE_HW_VEB = 'hw_veb' -VIF_TYPE_HOSTDEV_PHY = 'hostdev_physical' FLAT_VLAN = 0 @@ -66,9 +64,9 @@ class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): self.supported_vnic_types = supported_vnic_types # NOTE(ndipanov): PF passthrough requires a different vif type self.vnic_type_for_vif_type = ( - {vtype: VIF_TYPE_HOSTDEV_PHY + {vtype: portbindings.VIF_TYPE_HOSTDEV_PHY if vtype == portbindings.VNIC_DIRECT_PHYSICAL - else VIF_TYPE_HW_VEB + else portbindings.VIF_TYPE_HW_VEB for vtype in self.supported_vnic_types}) self.vif_details = vif_details @@ -118,8 +116,9 @@ class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): def try_to_bind_segment_for_agent(self, context, segment, agent): vnic_type = context.current.get(portbindings.VNIC_TYPE, portbindings.VNIC_DIRECT) - vif_type = self.vnic_type_for_vif_type.get(vnic_type, - VIF_TYPE_HW_VEB) + vif_type = self.vnic_type_for_vif_type.get( + vnic_type, portbindings.VIF_TYPE_HW_VEB) + if not self.check_segment_for_agent(segment, agent): return False port_status = (constants.PORT_STATUS_ACTIVE if agent is None diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py index aba559d4ced..3d9b20ae605 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py @@ -52,7 +52,7 @@ class TestFakePortContext(base.FakePortContext): class SriovNicSwitchMechanismBaseTestCase(base.AgentMechanismBaseTestCase): - VIF_TYPE = mech_driver.VIF_TYPE_HW_VEB + VIF_TYPE = portbindings.VIF_TYPE_HW_VEB CAP_PORT_FILTER = False AGENT_TYPE = constants.AGENT_TYPE_NIC_SWITCH VLAN_SEGMENTS = base.AgentMechanismVlanTestCase.VLAN_SEGMENTS @@ -135,15 +135,15 @@ class SriovSwitchMechVnicTypeTestCase(SriovNicSwitchMechanismBaseTestCase): def test_vnic_type_direct(self): self._check_vif_type_for_vnic_type(portbindings.VNIC_DIRECT, - mech_driver.VIF_TYPE_HW_VEB) + portbindings.VIF_TYPE_HW_VEB) def test_vnic_type_macvtap(self): self._check_vif_type_for_vnic_type(portbindings.VNIC_MACVTAP, - mech_driver.VIF_TYPE_HW_VEB) + portbindings.VIF_TYPE_HW_VEB) def test_vnic_type_direct_physical(self): self._check_vif_type_for_vnic_type(portbindings.VNIC_DIRECT_PHYSICAL, - mech_driver.VIF_TYPE_HOSTDEV_PHY) + portbindings.VIF_TYPE_HOSTDEV_PHY) class SriovSwitchMechVifDetailsTestCase(SriovNicSwitchMechanismBaseTestCase):