diff --git a/neutron/agent/common/ovsdb_monitor.py b/neutron/agent/common/ovsdb_monitor.py index a6d71665af1..a3a575568d3 100644 --- a/neutron/agent/common/ovsdb_monitor.py +++ b/neutron/agent/common/ovsdb_monitor.py @@ -16,6 +16,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from neutron.agent.common import async_process +from neutron.agent.common import ovs_lib from neutron.agent.ovsdb import api as ovsdb from neutron.agent.ovsdb.native import helpers from neutron.common import utils @@ -108,6 +109,11 @@ class SimpleInterfaceMonitor(OvsdbMonitor): external_ids = ovsdb.val_to_py(external_ids) if ofport: ofport = ovsdb.val_to_py(ofport) + if ofport == ovs_lib.INVALID_OFPORT: + LOG.debug("Ofport of port %(name)s is %(ofport)s. " + "Skipping its event.", + {'name': name, 'ofport': ofport}) + continue device = {'name': name, 'ofport': ofport, 'external_ids': external_ids} diff --git a/neutron/tests/unit/agent/common/test_ovsdb_monitor.py b/neutron/tests/unit/agent/common/test_ovsdb_monitor.py index fc645ee61d9..71043b18021 100644 --- a/neutron/tests/unit/agent/common/test_ovsdb_monitor.py +++ b/neutron/tests/unit/agent/common/test_ovsdb_monitor.py @@ -85,3 +85,12 @@ class TestSimpleInterfaceMonitor(base.BaseTestCase): self.monitor.process_events() self.assertEqual(self.monitor.new_events['added'][0]['ofport'], ovs_lib.UNASSIGNED_OFPORT) + + def process_event_invalid_of_port(self): + output = '{"data":[["e040fbec-0579-4990-8324-d338da33ae88","insert",' + output += '"m50",-1,["map",[]]]],"headings":["row","action",' + output += '"name","ofport","external_ids"]}' + with mock.patch.object( + self.monitor, 'iter_stdout', return_value=[output]): + self.monitor.process_events() + self.assertEqual([], self.monitor.new_events['added'])