Merge "Fix linuxbridge trunk subport RPC event handler"

This commit is contained in:
Jenkins 2016-09-20 01:18:32 +00:00 committed by Gerrit Code Review
commit 4eb9bc14e7
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(),