Add WaitForPortCreateEvent in BaseOVSTestCase

When a port is created, the test case will wait until the IDL event
is raised and the port is effectively created and the local DB
cache is updated.

Conflicts:
      neutron/tests/functional/agent/common/test_ovs_lib.py

Change-Id: I660baccde67a040731538276fc6dff05a10efb68
Related-Bug: #1910717
(cherry picked from commit e0f15c5982)
This commit is contained in:
Rodolfo Alonso Hernandez 2021-01-11 16:58:49 +00:00
parent 4f06660447
commit c121b1caa9
1 changed files with 15 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import functools
import mock
from neutron_lib.services.qos import constants as qos_constants
from oslo_utils import uuidutils
from ovsdbapp.backend.ovs_idl import event
import six
from neutron.agent.common import ovs_lib
@ -37,6 +38,17 @@ OTHER_CONFIG_DEFAULT = {six.u('max-rate'): six.u(str(MAX_RATE_DEFAULT)),
six.u('min-rate'): six.u(str(MIN_RATE_DEFAULT))}
class WaitForPortCreateEvent(event.WaitEvent):
event_name = 'WaitForPortCreateEvent'
def __init__(self, port_name):
table = 'Port'
events = (self.ROW_CREATE,)
conditions = (('name', '=', port_name),)
super(WaitForPortCreateEvent, self).__init__(
events, table, conditions, timeout=5)
class BaseOVSTestCase(base.BaseSudoTestCase):
def setUp(self):
@ -111,8 +123,11 @@ class BaseOVSTestCase(base.BaseSudoTestCase):
self.elements_to_clean['bridges'].append(self.br_name)
def _create_port(self, port_name):
row_event = WaitForPortCreateEvent(port_name)
self.ovs.ovsdb.idl.notify_handler.watch_event(row_event)
self.ovs.ovsdb.add_port(self.br_name, port_name).execute(
check_error=True)
self.assertTrue(row_event.wait())
def _find_port_uuid(self, port_name):
return self.ovs.ovsdb.db_get('Port', port_name, '_uuid').execute()