Fix linuxbridge trunk subport RPC event handler

The part of the linuxbridge trunk driver that actually triggered
the dataplane wiring for subport changes was incorrectly trying to
fetch the trunk using the trunk ID with a method expecting the port
ID. This would always result in it thinking the trunk wasn't on the
host and returning without wiring.

This fixes it by adding another method to fetch trunks by trunk ID.
All of the other operations in this function already expect trunk IDs.

This was discovered and the fix verified with the scenario test in
the dependent patch.

Change-Id: I25324bc1445cc083799ff54f8508a9505517ce84
Closes-Bug: #1625136
This commit is contained in:
Kevin Benton 2016-09-19 04:21:27 -07:00
parent c2f279ab62
commit 19f3e9a50e
2 changed files with 13 additions and 3 deletions

View File

@ -77,7 +77,7 @@ class LinuxBridgeTrunkDriver(trunk_rpc.TrunkSkeleton):
affected_trunks.add(s['trunk_id'])
method(s['trunk_id'], s)
for trunk_id in affected_trunks:
trunk = self._tapi.get_trunk(context, trunk_id)
trunk = self._tapi.get_trunk_by_id(context, trunk_id)
if not trunk:
continue
self.wire_trunk(context, trunk)
@ -191,6 +191,10 @@ class _TrunkAPI(object):
for sub in trunk.sub_ports:
self._sub_port_id_to_trunk_port_id[sub.port_id] = trunk.port_id
def get_trunk_by_id(self, context, trunk_id):
"""Gets trunk object based on trunk_id. None if not in cache."""
return self._trunk_by_id.get(trunk_id)
def get_trunk(self, context, port_id):
"""Gets trunk object for port_id. None if not trunk."""
if port_id not in self._trunk_by_port_id:

View File

@ -66,14 +66,14 @@ class LinuxBridgeTrunkDriverTestCase(base.BaseTestCase):
self.plumber.delete_trunk_subports.assert_called_once_with(self.trunk)
def test_handle_subports_deleted(self):
self.tapi.get_trunk.return_value = self.trunk
self.tapi.get_trunk_by_id.return_value = self.trunk
self.lbd.handle_subports(self.trunk.sub_ports, events.DELETED)
self.assertEqual(20, len(self.tapi.delete_trunk_subport.mock_calls))
# should have tried to wire trunk at the end with state
self.plumber.trunk_on_host.assert_called_once_with(self.trunk)
def test_handle_subports_created(self):
self.tapi.get_trunk.return_value = self.trunk
self.tapi.get_trunk_by_id.return_value = self.trunk
self.lbd.handle_subports(self.trunk.sub_ports, events.CREATED)
self.assertEqual(20, len(self.tapi.put_trunk_subport.mock_calls))
# should have tried to wire trunk at the end with state
@ -191,6 +191,12 @@ class TrunkAPITestCase(base.BaseTestCase):
self.tapi.put_trunk_subport(
'non_trunk_id', self.trunk.sub_ports[0])
def test_get_trunk_by_id(self):
self.tapi.put_trunk(self.trunk.port_id, self.trunk)
self.assertEqual(self.trunk,
self.tapi.get_trunk_by_id('ctx', self.trunk.id))
self.assertIsNone(self.tapi.get_trunk_by_id('ctx', 'other_id'))
def test_put_trunk_subport(self):
self.tapi.put_trunk(self.trunk.port_id, self.trunk)
new = trunk.SubPort(id=uuidutils.generate_uuid(),