]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix SR-IOV mech driver to set port status to down when agent is required
authorMoshe Levi <moshele@mellanox.com>
Thu, 11 Jun 2015 09:24:03 +0000 (12:24 +0300)
committerMoshe Levi <moshele@mellanox.com>
Thu, 18 Jun 2015 11:17:24 +0000 (14:17 +0300)
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 <irenab.dev@gmail.com>
Closes-Bug: #1464186

Change-Id: Ibd9b31b4f2393b8732253d5cbfd36e8b5614860d

neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py
neutron/tests/unit/plugins/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py

index 56aa810a5d6d37f5f9c3113916988b44d2fe30d0..5d9d6f83671022e4773904f960acb8ef3f3dfdf8 100644 (file)
@@ -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
index 8a94920cf0fcb9a11fab73fdffb28998efddf28c..ffe807689337c2c8660b6e110a287791c62d52e2 100644 (file)
@@ -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']):