From: Moshe Levi Date: Thu, 11 Jun 2015 09:24:03 +0000 (+0300) Subject: Fix SR-IOV mech driver to set port status to down when agent is required X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=63e318f5f8159f108cf1e7a82c952fa5f882870f;p=openstack-build%2Fneutron-build.git Fix SR-IOV mech driver to set port status to down when agent is required SR-IOV mech driver has 2 modes agent and agent-less. Currently in both modes port status are active. This patch update the port status to down when using agent mode. This will allow the SR-IOV agent to get port update notification and apply its additional functionality when launching vm. Co-Authored-By: Berezovsky Irena Closes-Bug: #1464186 Change-Id: Ibd9b31b4f2393b8732253d5cbfd36e8b5614860d --- diff --git a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py index 56aa810a5..5d9d6f836 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py @@ -121,10 +121,12 @@ class SriovNicSwitchMechanismDriver(api.MechanismDriver): def try_to_bind(self, context, agent=None): for segment in context.segments_to_bind: if self.check_segment(segment, agent): + port_status = (constants.PORT_STATUS_ACTIVE if agent is None + else constants.PORT_STATUS_DOWN) context.set_binding(segment[api.ID], self.vif_type, self._get_vif_details(segment), - constants.PORT_STATUS_ACTIVE) + port_status) LOG.debug("Bound using segment: %s", segment) return True return False diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py index 8a94920cf..ffe807689 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py @@ -196,15 +196,15 @@ class SriovSwitchMechProfileFailTestCase(SriovNicSwitchMechanismBaseTestCase): class SriovSwitchMechVifDetailsTestCase(SriovNicSwitchMechanismBaseTestCase): - def test_vif_details_contains_vlan_id(self): - VLAN_SEGMENTS = [{api.ID: 'vlan_segment_id', - api.NETWORK_TYPE: 'vlan', - api.PHYSICAL_NETWORK: 'fake_physical_network', - api.SEGMENTATION_ID: 1234}] + VLAN_SEGMENTS = [{api.ID: 'vlan_segment_id', + api.NETWORK_TYPE: 'vlan', + api.PHYSICAL_NETWORK: 'fake_physical_network', + api.SEGMENTATION_ID: 1234}] + def test_vif_details_contains_vlan_id(self): context = TestFakePortContext(self.AGENT_TYPE, self.AGENTS, - VLAN_SEGMENTS, + self.VLAN_SEGMENTS, portbindings.VNIC_DIRECT) self.driver.bind_port(context) @@ -224,6 +224,27 @@ class SriovSwitchMechVifDetailsTestCase(SriovNicSwitchMechanismBaseTestCase): with testtools.ExpectedException(exc.SriovUnsupportedNetworkType): self.driver._get_vif_details(segment) + def test_get_vif_details_without_agent(self): + cfg.CONF.set_override('agent_required', False, 'ml2_sriov') + self.driver = mech_driver.SriovNicSwitchMechanismDriver() + self.driver.initialize() + context = TestFakePortContext(self.AGENT_TYPE, + self.AGENTS, + self.VLAN_SEGMENTS, + portbindings.VNIC_DIRECT) + + self.driver.bind_port(context) + self.assertEqual(constants.PORT_STATUS_ACTIVE, context._bound_state) + + def test_get_vif_details_with_agent(self): + context = TestFakePortContext(self.AGENT_TYPE, + self.AGENTS, + self.VLAN_SEGMENTS, + portbindings.VNIC_DIRECT) + + self.driver.bind_port(context) + self.assertEqual(constants.PORT_STATUS_DOWN, context._bound_state) + class SriovSwitchMechConfigTestCase(SriovNicSwitchMechanismBaseTestCase): def _set_config(self, pci_devs=['aa:bb']):