Browse Source

functional: Remove additional OVSDB connections

The functional test base created an explicit connections to the OVSDB
servers. However, there are other connections created by the mech_driver
itself. This patch replaces the explicit connections with the ones from
the mech_driver to avoid races in test between DB connections. e.g.
Connection1 creates resource and connection2 uses the resource - there
is a need every time to wait for connection2 to sync the DB to its local
replica.

Closes-bug: #1845003

Change-Id: Ib770a6c83192c06593463734d3f74f83eff513b4
changes/68/685668/2
Jakub Libosvar 1 month ago
parent
commit
c1b6bf1acd

+ 4
- 40
networking_ovn/tests/functional/base.py View File

@@ -15,7 +15,6 @@
from datetime import datetime
import os
import shutil
import time

import fixtures
import mock
@@ -36,7 +35,6 @@ from ovsdbapp.backend.ovs_idl import connection
# Load all the models to register them into SQLAlchemy metadata before using
# the SqlFixture
from networking_ovn.db import models # noqa
from networking_ovn.ovsdb import impl_idl_ovn
from networking_ovn.ovsdb import ovsdb_monitor
from networking_ovn.ovsdb import worker
from networking_ovn.tests import base
@@ -162,7 +160,7 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
# Start 2 ovsdb-servers one each for OVN NB DB and OVN SB DB
# ovsdb-server with OVN SB DB can be used to test the chassis up/down
# events.
mgr = self.ovsdb_server_mgr = self.useFixture(
self.ovsdb_server_mgr = self.useFixture(
process.OvsdbServer(self.temp_dir, self.OVS_INSTALL_SHARE_PATH,
ovn_nb_db=True, ovn_sb_db=True,
protocol=self._ovsdb_protocol))
@@ -179,7 +177,6 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
set_cfg('ovn_sb_certificate', self.ovsdb_server_mgr.certificate, 'ovn')
set_cfg('ovn_sb_ca_cert', self.ovsdb_server_mgr.ca_cert, 'ovn')

num_attempts = 0
# 5 seconds should be more than enough for the transaction to complete
# for the test cases.
# This also fixes the bug #1607639.
@@ -187,42 +184,6 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
'ovsdb_connection_timeout', 5,
'ovn')

# Created monitor IDL connection to the OVN NB DB.
# This monitor IDL connection can be used to
# - Verify that the ML2 OVN driver has written to the OVN NB DB
# as expected.
# - Create and delete resources in OVN NB DB outside of the
# ML2 OVN driver scope to test scenarios like ovn_nb_sync.
while num_attempts < 3:
try:
con = self.useFixture(ConnectionFixture(
constr=mgr.get_ovsdb_connection_path(),
schema='OVN_Northbound')).connection
self.nb_api = impl_idl_ovn.OvsdbNbOvnIdl(con)
break
except Exception:
LOG.exception("Error connecting to the OVN_Northbound DB")
num_attempts += 1
time.sleep(1)

num_attempts = 0

# Create monitor IDL connection to the OVN SB DB.
# This monitor IDL connection can be used to
# - Create chassis rows
# - Update chassis columns etc.
while num_attempts < 3:
try:
con = self.useFixture(ConnectionFixture(
constr=mgr.get_ovsdb_connection_path('sb'),
schema='OVN_Southbound')).connection
self.sb_api = impl_idl_ovn.OvsdbSbOvnIdl(con)
break
except Exception:
LOG.exception("Error connecting to the OVN_Southbound DB")
num_attempts += 1
time.sleep(1)

class TriggerCls(mock.MagicMock):
def trigger(self):
pass
@@ -239,6 +200,9 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
self.mech_driver.post_fork_initialize(
mock.ANY, mock.ANY, trigger_cls.trigger)

self.nb_api = self.mech_driver._nb_ovn
self.sb_api = self.mech_driver._sb_ovn

def _collect_processes_logs(self):
for database in ("nb", "sb"):
for file_suffix in ("log", "db"):

+ 1
- 3
networking_ovn/tests/functional/test_metadata_agent.py View File

@@ -19,7 +19,6 @@ from oslo_config import fixture as fixture_config
from oslo_utils import uuidutils
from ovsdbapp.backend.ovs_idl import event
from ovsdbapp.backend.ovs_idl import idlutils
from ovsdbapp import event as ovsdb_event

from networking_ovn.agent.metadata import agent
from networking_ovn.agent.metadata import ovsdb
@@ -65,8 +64,7 @@ class TestMetadataAgent(base.TestOVNFunctionalBase):

def setUp(self):
super(TestMetadataAgent, self).setUp()
self.handler = ovsdb_event.RowEventHandler()
self.sb_api.idl.notify = self.handler.notify
self.handler = self.sb_api.idl.notify_handler
# We only have OVN NB and OVN SB running for functional tests
mock.patch.object(ovsdb, 'MetadataAgentOvsIdl').start()
self._mock_get_ovn_br = mock.patch.object(

Loading…
Cancel
Save