Browse Source

Ensure vif_details are unique per VIF

The Neutron framework assumes that the details of a vif are the same
cross all nics [1]. But with networking DPM they aren't! The vlan
detail might be different for each vif, depending to which network
it belongs.

The current implementation had a big bug: If first a vif attached to
a vlan network was processed, the vlan id is stored in the instance
drivers instance variable self.vif_details. Now if after that
a flat vif is processed, self.vif_details did still contain the
vlan property.

The solution is to make a copy of self.vif_details each time we process
it.

[1] 7e3d6a18fb/neutron/plugins/ml2/drivers/mech_agent.py (L142,L143)

Change-Id: I0cc09c20c308879e198a7fefd8c2d68c8591847e
Andreas Scheuring 1 year ago
parent
commit
cb114a5ba0
2 changed files with 25 additions and 1 deletions
  1. 1
    1
      networking_dpm/ml2/mech_dpm.py
  2. 24
    0
      networking_dpm/tests/unit/ml2/test_mech_dpm.py

+ 1
- 1
networking_dpm/ml2/mech_dpm.py View File

@@ -76,7 +76,7 @@ class DPMMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
76 76
         # per physical network is supported
77 77
         object_id = object_ids[0]
78 78
 
79
-        vif_details_segment = self.vif_details
79
+        vif_details_segment = self.vif_details.copy()
80 80
 
81 81
         network_type = segment[api.NETWORK_TYPE]
82 82
         if network_type == p_constants.TYPE_VLAN:

+ 24
- 0
networking_dpm/tests/unit/ml2/test_mech_dpm.py View File

@@ -108,3 +108,27 @@ class DPMMechanismVlanTestCase(DPMMechanismBaseTestCase,
108 108
                                        vnic_type=self.VNIC_TYPE)
109 109
         self.driver.bind_port(context)
110 110
         self._check_unbound(context)
111
+
112
+
113
+class DPMMechanismMixedTestCase(DPMMechanismBaseTestCase):
114
+    def test_vlan_flat_mixed(self):
115
+        """Ensure that vif_details are unique per vif"""
116
+
117
+        driver = mech_dpm.DPMMechanismDriver()
118
+        flat_segment = DPMMechanismFlatTestCase.FLAT_SEGMENTS[1]
119
+        vlan_segment = DPMMechanismVlanTestCase.VLAN_SEGMENTS[1]
120
+
121
+        context = base.FakePortContext(self.AGENT_TYPE,
122
+                                       self.AGENTS,
123
+                                       segments=[vlan_segment, flat_segment],
124
+                                       vnic_type=self.VNIC_TYPE)
125
+
126
+        result = driver.try_to_bind_segment_for_agent(context, vlan_segment,
127
+                                                      self.AGENT)
128
+        self.assertTrue(result)
129
+        self.assertEqual(1234, context._bound_vif_details.get("vlan"))
130
+
131
+        result = driver.try_to_bind_segment_for_agent(context, flat_segment,
132
+                                                      self.AGENT)
133
+        self.assertTrue(result)
134
+        self.assertIsNone(context._bound_vif_details.get("vlan"))

Loading…
Cancel
Save