diff --git a/neutron/plugins/ml2/drivers/mlnx/mech_mlnx.py b/neutron/plugins/ml2/drivers/mlnx/mech_mlnx.py index fd91020e49..97eb03a4c1 100644 --- a/neutron/plugins/ml2/drivers/mlnx/mech_mlnx.py +++ b/neutron/plugins/ml2/drivers/mlnx/mech_mlnx.py @@ -69,6 +69,9 @@ class MlnxMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): if self.check_segment_for_agent(segment, agent): vif_type = self._get_vif_type( context.current[portbindings.VNIC_TYPE]) + if segment[api.NETWORK_TYPE] in ['flat', 'vlan']: + self.vif_details['physical_network'] = segment[ + 'physical_network'] context.set_binding(segment[api.ID], vif_type, self.vif_details) diff --git a/neutron/tests/unit/ml2/drivers/test_mech_mlnx.py b/neutron/tests/unit/ml2/drivers/test_mech_mlnx.py index f1c2863ba1..343af4233e 100644 --- a/neutron/tests/unit/ml2/drivers/test_mech_mlnx.py +++ b/neutron/tests/unit/ml2/drivers/test_mech_mlnx.py @@ -116,3 +116,24 @@ class MlnxMechanismProfileTestCase(MlnxMechanismBaseTestCase): self.driver.try_to_bind_segment_for_agent(context, segment, agent) self.assertEqual('{"physical_network": "fake_physical_network"}', context._binding.profile) + + +class MlnxMechanismVifDetailsTestCase(MlnxMechanismBaseTestCase): + def setUp(self): + super(MlnxMechanismVifDetailsTestCase, self).setUp() + + def test_vif_details_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) + segment = VLAN_SEGMENTS[0] + agent = self.AGENTS[0] + self.driver.try_to_bind_segment_for_agent(context, segment, agent) + set({"physical_network": "fake_physical_network"}).issubset( + set(context._bound_vif_details.items()))