]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add update binding:profile with physical_network
authorIrena Berezovsky <irenab@mellanox.com>
Tue, 18 Mar 2014 14:35:35 +0000 (16:35 +0200)
committerIrena Berezovsky <irenab@mellanox.com>
Wed, 19 Mar 2014 08:08:09 +0000 (10:08 +0200)
Add temporary solution in order to support multiple physical networks
by mlnx ML2 MechanismDriver.
Due to non merged patches in nova that should support propagating
physical_network retrieved from port binding:profile attribute
to VIF/Network object.
The code will be removed once relevant nova patches are merged.
The code is disabled by default and should be enabled via
ml2_conf_mlnx.ini config file.

Change-Id: I815f9e28774efd47bccd1c57481e6ba89075792b
Closes-bug: #1291209

etc/neutron/plugins/ml2/ml2_conf_mlnx.ini
neutron/plugins/ml2/drivers/mlnx/config.py
neutron/plugins/ml2/drivers/mlnx/mech_mlnx.py
neutron/tests/unit/ml2/drivers/test_mech_mlnx.py

index 46139aed85a93c3146a8ade0ad6b4ea7d133187f..01b0797cf20463f14fbe91307585ef63756d5975 100644 (file)
@@ -2,3 +2,5 @@
 # (StrOpt) Type of Network Interface to allocate for VM:
 # mlnx_direct or hostdev according to libvirt terminology
 # vnic_type = mlnx_direct
+# (BoolOpt) Enable server compatibility with old nova
+# apply_profile_patch = False
index eac221b76119d6ea47f7bf0f49acddf4091af57e..d8c8b1cb75fd17f0c63644c946608ff9d64364bb 100644 (file)
@@ -23,6 +23,9 @@ eswitch_opts = [
                default=portbindings.VIF_TYPE_MLNX_DIRECT,
                help=_("Type of VM network interface: mlnx_direct or "
                       "hostdev")),
+    cfg.BoolOpt('apply_profile_patch',
+                default=False,
+                help=_("Enable server compatibility with old nova ")),
 ]
 
 
index 13d7b50516a43dfe257449700a12b671075a1fc5..fd91020e49a996ab9c013aa8ad72abb17ff179b8 100644 (file)
@@ -18,6 +18,7 @@ from oslo.config import cfg
 
 from neutron.common import constants
 from neutron.extensions import portbindings
+from neutron.openstack.common import jsonutils
 from neutron.openstack.common import log
 from neutron.plugins.ml2 import driver_api as api
 from neutron.plugins.ml2.drivers import mech_agent
@@ -48,6 +49,7 @@ class MlnxMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
             cfg.CONF.ESWITCH.vnic_type,
             {portbindings.CAP_PORT_FILTER: False},
             portbindings.VNIC_TYPES)
+        self.update_profile = cfg.CONF.ESWITCH.apply_profile_patch
 
     def check_segment_for_agent(self, segment, agent):
         mappings = agent['configurations'].get('interface_mappings', {})
@@ -70,6 +72,13 @@ class MlnxMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
             context.set_binding(segment[api.ID],
                                 vif_type,
                                 self.vif_details)
+            # REVISIT(irenab): Temporary solution till nova support
+            # will be merged for physical_network propagation
+            # via VIF object to VIFDriver (required by mlnx vif plugging).
+            if self.update_profile:
+                profile = {'physical_network':
+                           segment['physical_network']}
+                context._binding.profile = jsonutils.dumps(profile)
 
     def _get_vif_type(self, requested_vnic_type):
         if requested_vnic_type == portbindings.VNIC_MACVTAP:
index 382e54e6ea021caa9078c0dfdfef4c9baa7076ae..f1c2863ba1d26a0310536ead854ace30dc1b16b1 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+
+import mock
+from oslo.config import cfg
+
 from neutron.common import constants
 from neutron.extensions import portbindings
+from neutron.plugins.ml2 import driver_api as api
 from neutron.plugins.ml2.drivers.mlnx import mech_mlnx
 from neutron.tests.unit.ml2 import _test_mech_agent as base
 
@@ -87,3 +92,27 @@ class MlnxMechanismVnicTypeTestCase(MlnxMechanismBaseTestCase,
     def test_vnic_type_normal(self):
         self._check_vif_type_for_vnic_type(portbindings.VNIC_NORMAL,
                                            self.VIF_TYPE)
+
+
+class MlnxMechanismProfileTestCase(MlnxMechanismBaseTestCase):
+    def setUp(self):
+        cfg.CONF.set_override('apply_profile_patch', True, 'ESWITCH')
+        super(MlnxMechanismProfileTestCase, self).setUp()
+
+    def test_profile_contains_physical_net(self):
+        VLAN_SEGMENTS = [{api.ID: 'vlan_segment_id',
+                          api.NETWORK_TYPE: 'vlan',
+                          api.PHYSICAL_NETWORK: 'fake_physical_network',
+                          api.SEGMENTATION_ID: 1234}]
+
+        context = base.FakePortContext(self.AGENT_TYPE,
+                                       self.AGENTS,
+                                       VLAN_SEGMENTS,
+                                       portbindings.VNIC_DIRECT)
+        context._binding = mock.Mock()
+        context._binding.profile = {}
+        segment = VLAN_SEGMENTS[0]
+        agent = self.AGENTS[0]
+        self.driver.try_to_bind_segment_for_agent(context, segment, agent)
+        self.assertEqual('{"physical_network": "fake_physical_network"}',
+                         context._binding.profile)