Browse Source

Merge "functional: Collect OVN DBs logs"

tags/7.0.0.0rc1
Zuul 1 month ago
parent
commit
978738121d

+ 24
- 2
networking_ovn/tests/functional/base.py View File

@@ -12,7 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.

from datetime import datetime
import os
import shutil
import time

import fixtures
@@ -110,8 +112,9 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
group='ovn')

super(TestOVNFunctionalBase, self).setUp()
self.test_log_dir = os.path.join(DEFAULT_LOG_DIR, self.id())
base.setup_test_logging(
cfg.CONF, DEFAULT_LOG_DIR, "%s.txt" % self.id())
cfg.CONF, self.test_log_dir, "testrun.txt")

mm = directory.get_plugin().mechanism_manager
self.mech_driver = mm.mech_drivers['ovn'].obj
@@ -119,6 +122,7 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
self.ovsdb_server_mgr = None
self.ovn_northd_mgr = None
self.maintenance_worker = maintenance_worker
self.temp_dir = self.useFixture(fixtures.TempDir()).path
self._start_ovsdb_server_and_idls()
self._start_ovn_northd()

@@ -155,7 +159,6 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
protocol=self._ovsdb_protocol))

def _start_ovsdb_server_and_idls(self):
self.temp_dir = self.useFixture(fixtures.TempDir()).path
# 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.
@@ -229,12 +232,30 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
trigger_cls.trigger.__self__.__class__ = worker.MaintenanceWorker
cfg.CONF.set_override('neutron_sync_mode', 'off', 'ovn')

self.addCleanup(self._collect_processes_logs)
self.addCleanup(self.stop)

# mech_driver.post_fork_initialize creates the IDL connections
self.mech_driver.post_fork_initialize(
mock.ANY, mock.ANY, trigger_cls.trigger)

def _collect_processes_logs(self):
for database in ("nb", "sb"):
for file_suffix in ("log", "db"):
src_filename = "ovn_%(db)s.%(suffix)s" % {
'db': database,
'suffix': file_suffix
}
dst_filename = "ovn_%(db)s-%(timestamp)s.%(suffix)s" % {
'db': database,
'suffix': file_suffix,
'timestamp': datetime.now().strftime('%y-%m-%d_%H-%M-%S'),
}

filepath = os.path.join(self.temp_dir, src_filename)
shutil.copyfile(
filepath, os.path.join(self.test_log_dir, dst_filename))

def stop(self):
if self.maintenance_worker:
self.mech_driver.nb_synchronizer.stop()
@@ -263,6 +284,7 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
self.nb_api.ovsdb_connection = None
self.sb_api.ovsdb_connection = None

self.ovsdb_server_mgr.delete_dbs()
self._start_ovsdb_server_and_idls()
self._start_ovn_northd()


+ 18
- 3
networking_ovn/tests/functional/resources/process.py View File

@@ -41,13 +41,15 @@ class DaemonProcessFixture(fixtures.Fixture):

class OvnNorthd(DaemonProcessFixture):

def __init__(self, temp_dir, ovn_nb_db, ovn_sb_db, protocol='unix'):
def __init__(self, temp_dir, ovn_nb_db, ovn_sb_db, protocol='unix',
debug=True):
super(OvnNorthd, self).__init__(temp_dir)
self.ovn_nb_db = ovn_nb_db
self.ovn_sb_db = ovn_sb_db
self.protocol = protocol
self.unixctl_path = self.temp_dir + '/ovn_northd.ctl'
self.log_file_path = self.temp_dir + '/ovn_northd.log'
self.debug = debug
if self.protocol == 'ssl':
self.private_key = os.path.join(self.temp_dir, 'ovn-privkey.pem')
self.certificate = os.path.join(self.temp_dir, 'ovn-cert.pem')
@@ -72,6 +74,8 @@ class OvnNorthd(DaemonProcessFixture):
ovn_northd_cmd.append('--private-key=%s' % self.private_key)
ovn_northd_cmd.append('--certificate=%s' % self.certificate)
ovn_northd_cmd.append('--ca-cert=%s' % self.ca_cert)
if self.debug:
ovn_northd_cmd.append('--verbose')
obj, _ = utils.create_process(ovn_northd_cmd)
obj.communicate()

@@ -86,7 +90,7 @@ class OvnNorthd(DaemonProcessFixture):
class OvsdbServer(DaemonProcessFixture):

def __init__(self, temp_dir, ovs_dir, ovn_nb_db=True, ovn_sb_db=False,
protocol='unix'):
protocol='unix', debug=True):
super(OvsdbServer, self).__init__(temp_dir)
self.ovs_dir = ovs_dir
self.ovn_nb_db = ovn_nb_db
@@ -98,6 +102,7 @@ class OvsdbServer(DaemonProcessFixture):
self.certificate = os.path.join(self.temp_dir, 'ovn-cert.pem')
self.ca_cert = os.path.join(self.temp_dir, 'controllerca',
'cacert.pem')
self.debug = debug

def _setUp(self):
if self.ovn_nb_db:
@@ -143,6 +148,13 @@ class OvsdbServer(DaemonProcessFixture):
os.path.join(self.temp_dir, 'pki.log'), '--force']
utils.execute(pki_req_sign)

def delete_dbs(self):
for ovsdb in self.ovsdb_server_processes:
try:
os.remove(ovsdb['db_path'])
except OSError:
pass

def start(self):
pki_done = False
for ovsdb_process in self.ovsdb_server_processes:
@@ -161,7 +173,8 @@ class OvsdbServer(DaemonProcessFixture):
'--log-file=%s' % (ovsdb_process['log_file_path']),
'--remote=punix:%s' % (ovsdb_process['remote_path']),
'--remote=%s' % (ovsdb_process['connection']),
'--unixctl=%s' % (ovsdb_process['unixctl_path'])]
'--unixctl=%s' % (ovsdb_process['unixctl_path']),
'--detach']
if ovsdb_process['protocol'] == 'ssl':
if not pki_done:
pki_done = True
@@ -170,6 +183,8 @@ class OvsdbServer(DaemonProcessFixture):
ovsdb_server_cmd.append('--certificate=%s' % self.certificate)
ovsdb_server_cmd.append('--ca-cert=%s' % self.ca_cert)
ovsdb_server_cmd.append(ovsdb_process['db_path'])
if self.debug:
ovsdb_server_cmd.append('--verbose')
obj, _ = utils.create_process(ovsdb_server_cmd)
obj.communicate()


Loading…
Cancel
Save