Make NEC Plugin ignore duplicated messgae from the agent

Fixes: bug #1208708
Change-Id: I7d2b779fd0a7356c03e5ef911a98c164a53903ce
This commit is contained in:
Ryota MIBU 2013-08-05 13:42:45 +09:00
parent 1ec7a1ff76
commit 23ac6df865
2 changed files with 28 additions and 0 deletions

View File

@ -537,6 +537,11 @@ class NECPluginV2RPCCallbacks(object):
id = p['id']
portinfo = ndb.get_portinfo(session, id)
if portinfo:
if (portinfo.datapath_id == datapath_id and
portinfo.port_no == p['port_no']):
LOG.debug(_("update_ports(): ignore unchanged portinfo in "
"port_added message (port_id=%s)."), id)
continue
ndb.del_portinfo(session, id)
ndb.add_portinfo(session, id, datapath_id, p['port_no'],
mac=p.get('mac', ''))

View File

@ -283,6 +283,29 @@ class TestNecPortsV2Callback(NecPluginV2TestCase):
self.assertEqual(2, self.ofc.create_ofc_port.call_count)
self.assertEqual(1, self.ofc.delete_ofc_port.call_count)
def test_portinfo_readd(self):
with self.port() as port:
port_id = port['port']['id']
self.plugin.get_port(self.context, port_id)
portinfo = {'id': port_id, 'port_no': 123}
self.rpcapi_update_ports(added=[portinfo])
sport = self.plugin.get_port(self.context, port_id)
self.assertEqual(sport['status'], 'ACTIVE')
self.assertEqual(self.ofc.create_ofc_port.call_count, 1)
self.assertEqual(self.ofc.delete_ofc_port.call_count, 0)
self.assertIsNotNone(self._get_portinfo(port_id))
portinfo = {'id': port_id, 'port_no': 123}
self.rpcapi_update_ports(added=[portinfo])
sport = self.plugin.get_port(self.context, port_id)
self.assertEqual(sport['status'], 'ACTIVE')
self.assertEqual(self.ofc.create_ofc_port.call_count, 1)
self.assertEqual(self.ofc.delete_ofc_port.call_count, 0)
self.assertIsNotNone(self._get_portinfo(port_id))
class TestNecPluginDbTest(NecPluginV2TestCase):