Skip to content

Commit ac7a86e

Browse files
gotostackbrianphaley
authored andcommitted
Always get local vlan from port other_config
For openvswitch security group, due to some extreme case, if ofport is processed once, the openvswitch security driver will cache some old ofport informations with different local vlan from current assignment. So this patch changes the local_vlan get method to the port other_config, this value should be managed by ovs_agent properly, we can rely on that. Closes-Bug: #2071451 Change-Id: I7ad7df72807c95571ef3156c99072852d1c4f494 (cherry picked from commit ae587c3)
1 parent 1605036 commit ac7a86e

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

neutron/agent/linux/openvswitch_firewall/firewall.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,22 @@ def get_ofport(self, port):
703703
port_id = port['device']
704704
return self.sg_port_map.ports.get(port_id)
705705

706+
def _create_of_port(self, port, ovs_port):
707+
# Should always try to get the local vlan tag from
708+
# the OVSDB Port other_config, since the ovs-agent's
709+
# LocalVlanManager always allocated/updated it and then
710+
# set_db_attribute to Port other_config before this.
711+
port_vlan_id = self._get_port_vlan_tag(ovs_port.port_name)
712+
segment_id = self._get_port_segmentation_id(
713+
ovs_port.port_name)
714+
network_type = self._get_port_network_type(
715+
ovs_port.port_name)
716+
physical_network = self._get_port_physical_network(
717+
ovs_port.port_name)
718+
return OFPort(port, ovs_port, port_vlan_id,
719+
segment_id,
720+
network_type, physical_network)
721+
706722
def get_or_create_ofport(self, port):
707723
"""Get ofport specified by port['device'], checking and reflecting
708724
ofport changes.
@@ -713,22 +729,12 @@ def get_or_create_ofport(self, port):
713729
try:
714730
of_port = self.sg_port_map.ports[port_id]
715731
except KeyError:
716-
port_vlan_id = self._get_port_vlan_tag(ovs_port.port_name)
717-
segment_id = self._get_port_segmentation_id(
718-
ovs_port.port_name)
719-
network_type = self._get_port_network_type(
720-
ovs_port.port_name)
721-
physical_network = self._get_port_physical_network(
722-
ovs_port.port_name)
723-
of_port = OFPort(port, ovs_port, port_vlan_id,
724-
segment_id,
725-
network_type, physical_network)
732+
of_port = self._create_of_port(port, ovs_port)
726733
self.sg_port_map.create_port(of_port, port)
727734
else:
728735
if of_port.ofport != ovs_port.ofport:
729736
self.sg_port_map.remove_port(of_port)
730-
of_port = OFPort(port, ovs_port, of_port.vlan_tag,
731-
of_port.segment_id)
737+
of_port = self._create_of_port(port, ovs_port)
732738
self.sg_port_map.create_port(of_port, port)
733739
else:
734740
self.sg_port_map.update_port(of_port, port)

neutron/tests/unit/agent/linux/openvswitch_firewall/test_firewall.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,21 @@ def test_get_or_create_ofport_changed(self):
658658
self.assertIn(of_port.id, self.firewall.sg_port_map.ports.keys())
659659
self.assertEqual(port.ofport, 2)
660660

661+
def test_get_or_create_ofport_changed_and_local_vlan_changed(self):
662+
port_dict = {
663+
'device': 'port-id',
664+
'security_groups': [123, 456]}
665+
of_port = create_ofport(port_dict)
666+
self.firewall.sg_port_map.ports[of_port.id] = of_port
667+
fake_ovs_port = FakeOVSPort('port', 2, '00:00:00:00:00:00')
668+
self.mock_bridge.br.get_vif_port_by_id.return_value = \
669+
fake_ovs_port
670+
self.mock_bridge.br.db_get_val.return_value = {"tag": 10}
671+
port = self.firewall.get_or_create_ofport(port_dict)
672+
self.assertIn(of_port.id, self.firewall.sg_port_map.ports.keys())
673+
self.assertEqual(port.ofport, 2)
674+
self.assertEqual(port.vlan_tag, 10)
675+
661676
def test_get_or_create_ofport_missing(self):
662677
port_dict = {
663678
'device': 'port-id',

0 commit comments

Comments
 (0)