diff options
author | Petr Viktorin <pviktori@redhat.com> | 2013-06-27 10:40:39 +0200 |
---|---|---|
committer | Petr Viktorin <pviktori@redhat.com> | 2013-07-25 12:32:33 +0200 |
commit | 4b439356b735d55c7da664bdf8d9f40468fb9c4d (patch) | |
tree | 7bd8d6868737791ee4435d58b8c6a67b53e9aced | |
parent | 65dfcb7cec7b641a87f9c59657eb7acbbecf911e (diff) | |
download | freeipa-4b439356b735d55c7da664bdf8d9f40468fb9c4d.tar.gz freeipa-4b439356b735d55c7da664bdf8d9f40468fb9c4d.tar.xz freeipa-4b439356b735d55c7da664bdf8d9f40468fb9c4d.zip |
test_integration: Add log collection to Host
This allows collecting logs when a test context is not available.
-rw-r--r-- | ipatests/test_integration/base.py | 15 | ||||
-rw-r--r-- | ipatests/test_integration/host.py | 14 | ||||
-rw-r--r-- | ipatests/test_integration/tasks.py | 30 |
3 files changed, 36 insertions, 23 deletions
diff --git a/ipatests/test_integration/base.py b/ipatests/test_integration/base.py index 8b243f937..4e8521dd9 100644 --- a/ipatests/test_integration/base.py +++ b/ipatests/test_integration/base.py @@ -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): diff --git a/ipatests/test_integration/host.py b/ipatests/test_integration/host.py index 0d363f93a..5647e0dc2 100644 --- a/ipatests/test_integration/host.py +++ b/ipatests/test_integration/host.py @@ -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) diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py index ecefdab70..3285838c6 100644 --- a/ipatests/test_integration/tasks.py +++ b/ipatests/test_integration/tasks.py @@ -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) |