Watch for 'new' events in ovsdb monitor for ofport

This adjusts the event handling logic in the ovs interface
monitor to watch for 'new' events as well because this is
when ofports are assigned to the interface. Previously we
were only watching for 'insert' events, which would never
include the ofport so this led to every port being skipped
initially by the OVS agent and then picked up on the next
polling interval.

Closes-Bug: #1560464
Change-Id: I46ac508a839c6db779323d5afb083f3425f96e87
(cherry picked from commit 62e88623d9)
This commit is contained in:
Kevin Benton 2016-03-17 05:19:19 -07:00 committed by Ihar Hrachyshka
parent 6d9774b058
commit 1d51172bab
2 changed files with 24 additions and 0 deletions

View File

@ -26,6 +26,7 @@ LOG = logging.getLogger(__name__)
OVSDB_ACTION_INITIAL = 'initial'
OVSDB_ACTION_INSERT = 'insert'
OVSDB_ACTION_DELETE = 'delete'
OVSDB_ACTION_NEW = 'new'
class OvsdbMonitor(async_process.AsyncProcess):
@ -85,6 +86,7 @@ class SimpleInterfaceMonitor(OvsdbMonitor):
def process_events(self):
devices_added = []
devices_removed = []
dev_to_ofport = {}
for row in self.iter_stdout():
json = jsonutils.loads(row).get('data')
for ovs_id, action, name, ofport, external_ids in json:
@ -99,8 +101,14 @@ class SimpleInterfaceMonitor(OvsdbMonitor):
devices_added.append(device)
elif action == OVSDB_ACTION_DELETE:
devices_removed.append(device)
elif action == OVSDB_ACTION_NEW:
dev_to_ofport[name] = ofport
self.new_events['added'].extend(devices_added)
self.new_events['removed'].extend(devices_removed)
# update any events with ofports received from 'new' action
for event in self.new_events['added']:
event['ofport'] = dev_to_ofport.get(event['name'], event['ofport'])
def start(self, block=False, timeout=5):
super(SimpleInterfaceMonitor, self).start()

View File

@ -24,6 +24,7 @@ Tests in this module will be skipped unless:
from oslo_config import cfg
from neutron.agent.common import ovs_lib
from neutron.agent.linux import ovsdb_monitor
from neutron.agent.linux import utils
from neutron.tests.common import net_helpers
@ -133,3 +134,18 @@ class TestSimpleInterfaceMonitor(BaseMonitorTest):
devices = self.monitor.get_events()
self.assertTrue(devices.get('added'),
'Initial call should always be true')
def test_get_events_includes_ofport(self):
utils.wait_until_true(lambda: self.monitor.has_updates)
self.monitor.get_events() # clear initial events
br = self.useFixture(net_helpers.OVSBridgeFixture())
p1 = self.useFixture(net_helpers.OVSPortFixture(br.bridge))
def p1_event_has_ofport():
if not self.monitor.has_updates:
return
for e in self.monitor.new_events['added']:
if (e['name'] == p1.port.name and
e['ofport'] != ovs_lib.UNASSIGNED_OFPORT):
return True
utils.wait_until_true(p1_event_has_ofport)