URL: https://github.com/freeipa/freeipa/pull/1423
Author: felipevolpone
 Title: #1423: IntegrationTests now collects logs from all test methods
Action: opened

PR body:
"""
It was missing the configuration and the proper use of the logfile_dir. Also, 
the dict of
logs to be collected should not be cleared. Now, all logs from all test methods 
will
be collected.

It's useful to say that it doesn't mean that all methods are changing the 
environment
or installing/reinstalling freeIPA. So, it's possible that some logs in 
different methods
would be the same.

Fixes: #7310 and #7335
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1423/head:pr1423
git checkout pr1423
From 85e31a315a789575b45316756c0b6fa6f1e0ef36 Mon Sep 17 00:00:00 2001
From: Felipe Barreto <fbarr...@redhat.com>
Date: Wed, 27 Dec 2017 10:02:39 -0200
Subject: [PATCH] IntegrationTests now collects logs from all test methods

It was missing the configuration and the properly use of
the logfile_dir property and the dict of logs to be
collected should not be cleared. Now, all logs from all
test methods will be collected.

It's useful to say that it doesn't mean that all methods
are changing the environment or installing/reinstalling
freeIPA. So, it's possible that some logs in different
methods would be the same.

Fixes: #7310 and #7335
---
 ipatests/pytest_plugins/integration/__init__.py | 18 ++++++++++++------
 ipatests/pytest_plugins/integration/config.py   |  2 ++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/ipatests/pytest_plugins/integration/__init__.py b/ipatests/pytest_plugins/integration/__init__.py
index bee669b0dd..1bc1ba460e 100644
--- a/ipatests/pytest_plugins/integration/__init__.py
+++ b/ipatests/pytest_plugins/integration/__init__.py
@@ -55,7 +55,7 @@ def _get_logname_from_node(node):
     return name
 
 
-def collect_test_logs(node, logs_dict, test_config):
+def collect_test_logs(node, logs_dict, test_config, custom_config):
     """Collect logs from a test
 
     Calls collect_logs
@@ -64,10 +64,14 @@ def collect_test_logs(node, logs_dict, test_config):
     :param logs_dict: Mapping of host to list of log filnames to collect
     :param test_config: Pytest configuration
     """
+    logfile_dir = test_config.getoption('logfile_dir')
+    if not logfile_dir:
+        logfile_dir = custom_config.logfile_dir
+
     collect_logs(
         name=_get_logname_from_node(node),
         logs_dict=logs_dict,
-        logfile_dir=test_config.getoption('logfile_dir'),
+        logfile_dir=logfile_dir,
         beakerlib_plugin=test_config.pluginmanager.getplugin('BeakerLibPlugin'),
     )
 
@@ -179,8 +183,6 @@ def collect_logs(name, logs_dict, logfile_dir=None, beakerlib_plugin=None):
             else:
                 shutil.rmtree(topdirname)
 
-        logs_dict.clear()
-
 
 @pytest.fixture(scope='class')
 def class_integration_logs():
@@ -194,7 +196,8 @@ def integration_logs(class_integration_logs, request):
     """
     yield class_integration_logs
     hosts = class_integration_logs.keys()
-    collect_test_logs(request.node, class_integration_logs, request.config)
+    collect_test_logs(request.node, class_integration_logs,
+                      request.config, request.cls.custom_config)
     collect_systemd_journal(request.node, hosts, request.config)
 
 
@@ -229,6 +232,8 @@ def mh(request, class_integration_logs):
         _config=get_global_config(),
     )
 
+    request.cls.custom_config = mh.config
+
     mh.domain = mh.config.domains[0]
     [mh.master] = mh.domain.hosts_by_role('master')
     mh.replicas = mh.domain.hosts_by_role('replica')
@@ -255,7 +260,8 @@ def collect_log(host, filename):
     for host in cls.get_all_hosts():
         host.remove_log_collector(collect_log)
 
-    collect_test_logs(request.node, class_integration_logs, request.config)
+    collect_test_logs(request.node, class_integration_logs,
+                      request.config, mh.config)
 
 
 def setup_class(cls, mh):
diff --git a/ipatests/pytest_plugins/integration/config.py b/ipatests/pytest_plugins/integration/config.py
index 734a2d92f1..1a2a31dddc 100644
--- a/ipatests/pytest_plugins/integration/config.py
+++ b/ipatests/pytest_plugins/integration/config.py
@@ -42,6 +42,7 @@ class Config(pytest_multihost.config.Config):
         'dns_forwarder',
         'domain_level',
         'log_journal_since',
+        'logfile_dir',
     }
 
     def __init__(self, **kwargs):
@@ -63,6 +64,7 @@ def __init__(self, **kwargs):
         # 8.8.8.8 is probably the best-known public DNS
         self.dns_forwarder = kwargs.get('dns_forwarder') or '8.8.8.8'
         self.debug = False
+        self.logfile_dir = kwargs.get('logfile_dir')
         self.log_journal_since = kwargs.get('log_journal_since') or '-1h'
         if self.domain_level is None:
             self.domain_level = MAX_DOMAIN_LEVEL
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to