test_integration: Add log collection to Host

This allows collecting logs when a test context is not available.
This commit is contained in:
Petr Viktorin 2013-06-27 10:40:39 +02:00
parent 65dfcb7cec
commit 4b439356b7
3 changed files with 36 additions and 23 deletions

View File

@ -58,6 +58,7 @@ class IntegrationTest(object):
cls.replicas = domain.replicas[:cls.num_replicas]
cls.clients = domain.clients[:cls.num_clients]
for host in cls.get_all_hosts():
host.add_log_collector(cls.collect_log)
cls.prepare_host(host)
try:
@ -83,15 +84,17 @@ class IntegrationTest(object):
if cls.topology == 'none':
return
elif cls.topology == 'star':
tasks.install_master(cls.master, collect_log=cls.collect_log)
tasks.install_master(cls.master)
for replica in cls.replicas:
tasks.install_replica(cls.master, replica,
collect_log=cls.collect_log)
tasks.install_replica(cls.master, replica)
else:
raise ValueError('Unknown topology %s' % cls.topology)
@classmethod
def teardown_class(cls):
for host in cls.get_all_hosts():
host.remove_log_collector(cls.collect_log)
try:
cls.uninstall()
finally:
@ -101,11 +104,11 @@ class IntegrationTest(object):
@classmethod
def uninstall(cls):
tasks.uninstall_master(cls.master, collect_log=cls.collect_log)
tasks.uninstall_master(cls.master)
for replica in cls.replicas:
tasks.uninstall_master(replica, collect_log=cls.collect_log)
tasks.uninstall_master(replica)
for client in cls.clients:
tasks.uninstall_client(client, collect_log=cls.collect_log)
tasks.uninstall_client(client)
@classmethod
def collect_log(cls, host, filename):

View File

@ -160,11 +160,21 @@ class Host(object):
self._command_index = 0
self.log_collectors = []
def __repr__(self):
template = ('<{s.__module__}.{s.__class__.__name__} '
'{s.hostname} ({s.role})>')
return template.format(s=self)
def add_log_collector(self, collector):
"""Register a log collector for this host"""
self.log_collectors.append(collector)
def remove_log_collector(self, collector):
"""Unregister a log collector"""
self.log_collectors.remove(collector)
@classmethod
def from_env(cls, env, domain, hostname, role, index):
ip = env.get('BEAKER%s%s_IP_env%s' %
@ -319,3 +329,7 @@ class Host(object):
def put_file(self, localpath, remotepath):
self.log.info('PUT %s', remotepath)
self.sftp.put(localpath, remotepath)
def collect_log(self, filename):
for collector in self.log_collectors:
collector(self, filename)

View File

@ -129,13 +129,12 @@ def enable_replication_debugging(host):
stdin_text=logging_ldif)
def install_master(host, collect_log=None):
if collect_log:
collect_log(host, '/var/log/ipaserver-install.log')
collect_log(host, '/var/log/ipaclient-install.log')
inst = host.domain.realm.replace('.', '-')
collect_log(host, '/var/log/dirsrv/slapd-%s/errors' % inst)
collect_log(host, '/var/log/dirsrv/slapd-%s/access' % inst)
def install_master(host):
host.collect_log('/var/log/ipaserver-install.log')
host.collect_log('/var/log/ipaclient-install.log')
inst = host.domain.realm.replace('.', '-')
host.collect_log('/var/log/dirsrv/slapd-%s/errors' % inst)
host.collect_log('/var/log/dirsrv/slapd-%s/access' % inst)
apply_common_fixes(host)
@ -151,10 +150,9 @@ def install_master(host, collect_log=None):
host.run_command(['kinit', 'admin'],
stdin_text=host.config.admin_password)
def install_replica(master, replica, collect_log=None):
if collect_log:
collect_log(replica, '/var/log/ipareplica-install.log')
collect_log(replica, '/var/log/ipareplica-conncheck.log')
def install_replica(master, replica):
replica.collect_log('/var/log/ipareplica-install.log')
replica.collect_log('/var/log/ipareplica-conncheck.log')
apply_common_fixes(replica)
@ -187,18 +185,16 @@ def connect_replica(master, replica=None):
replica.run_command(['ipa-replica-manage', 'connect'] + args)
def uninstall_master(host, collect_log=None):
if collect_log:
collect_log(host, '/var/log/ipaserver-uninstall.log')
def uninstall_master(host):
host.collect_log('/var/log/ipaserver-uninstall.log')
host.run_command(['ipa-server-install', '--uninstall', '-U'],
raiseonerr=False)
unapply_fixes(host)
def uninstall_client(host, collect_log=None):
if collect_log:
collect_log(host, '/var/log/ipaclient-uninstall.log')
def uninstall_client(host):
host.collect_log('/var/log/ipaclient-uninstall.log')
host.run_command(['ipa-client-install', '--uninstall', '-U'],
raiseonerr=False)