From a97fd4dabb31019ac7926b4445cd8d8f319b1b6a Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Wed, 2 Sep 2015 17:23:56 -0700 Subject: [PATCH] Retain logs for functional test cases This helps greatly the debugging process in face of race conditions. Change-Id: I74235307183cbb15a7179b18b417b38ffb1d2cc9 --- neutron/tests/base.py | 5 ++++ neutron/tests/contrib/post_test_hook.sh | 23 +++++++++++++------ neutron/tests/fullstack/resources/process.py | 4 ++-- .../functional/agent/linux/test_ip_lib.py | 1 - .../tests/functional/agent/test_l3_agent.py | 2 -- neutron/tests/functional/base.py | 13 ++++++++++- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/neutron/tests/base.py b/neutron/tests/base.py index cb5fb3ee6..86f08544f 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -103,6 +103,11 @@ def get_test_timeout(default=0): return int(os.environ.get('OS_TEST_TIMEOUT', 0)) +def sanitize_log_path(path): + # Sanitize the string so that it's log path is shell friendly + return path.replace(' ', '-').replace('(', '_').replace(')', '_') + + class AttributeDict(dict): """ diff --git a/neutron/tests/contrib/post_test_hook.sh b/neutron/tests/contrib/post_test_hook.sh index efac0d624..c42649b70 100644 --- a/neutron/tests/contrib/post_test_hook.sh +++ b/neutron/tests/contrib/post_test_hook.sh @@ -8,6 +8,19 @@ SCRIPTS_DIR="/usr/os-testr-env/bin/" venv=${1:-"dsvm-functional"} +function generate_test_logs { + local path="$1" + # Compress all $path/*.txt files and move the directories holding those + # files to /opt/stack/logs. Files with .log suffix have their + # suffix changed to .txt (so browsers will know to open the compressed + # files and not download them). + if [ -d "$path" ] + then + sudo find $path -iname "*.log" -type f -exec mv {} {}.txt \; -exec gzip -9 {}.txt \; + sudo mv $path/* /opt/stack/logs/ + fi +} + function generate_testr_results { # Give job user rights to access tox logs sudo -H -u $owner chmod o+rw . @@ -20,13 +33,9 @@ function generate_testr_results { sudo mv ./*.gz /opt/stack/logs/ fi - # Compress all /tmp/fullstack-*/*.txt files and move the directories - # holding those files to /opt/stack/logs. Files with .log suffix have their - # suffix changed to .txt (so browsers will know to open the compressed - # files and not download them). - if [ "$venv" == "dsvm-fullstack" ] && [ -d /tmp/fullstack-logs/ ]; then - sudo find /tmp/fullstack-logs -iname "*.log" -type f -exec mv {} {}.txt \; -exec gzip -9 {}.txt \; - sudo mv /tmp/fullstack-logs/* /opt/stack/logs/ + if [ "$venv" == "dsvm-functional" ] || [ "$venv" == "dsvm-fullstack" ] + then + generate_test_logs "/tmp/${venv}-logs" fi } diff --git a/neutron/tests/fullstack/resources/process.py b/neutron/tests/fullstack/resources/process.py index 4414102e2..0d6a8bd73 100644 --- a/neutron/tests/fullstack/resources/process.py +++ b/neutron/tests/fullstack/resources/process.py @@ -29,8 +29,8 @@ from neutron.tests.common import net_helpers LOG = logging.getLogger(__name__) -# This should correspond the directory from which infra retrieves log files -DEFAULT_LOG_DIR = '/tmp/fullstack-logs/' +# This is the directory from which infra fetches log files for fullstack tests +DEFAULT_LOG_DIR = '/tmp/dsvm-fullstack-logs/' class ProcessFixture(fixtures.Fixture): diff --git a/neutron/tests/functional/agent/linux/test_ip_lib.py b/neutron/tests/functional/agent/linux/test_ip_lib.py index b166b0ec5..27e00ef29 100644 --- a/neutron/tests/functional/agent/linux/test_ip_lib.py +++ b/neutron/tests/functional/agent/linux/test_ip_lib.py @@ -42,7 +42,6 @@ class IpLibTestFramework(functional_base.BaseSudoTestCase): self._configure() def _configure(self): - config.setup_logging() config.register_interface_driver_opts_helper(cfg.CONF) cfg.CONF.set_override( 'interface_driver', diff --git a/neutron/tests/functional/agent/test_l3_agent.py b/neutron/tests/functional/agent/test_l3_agent.py index 8c86a22ac..17b0ee00e 100644 --- a/neutron/tests/functional/agent/test_l3_agent.py +++ b/neutron/tests/functional/agent/test_l3_agent.py @@ -81,8 +81,6 @@ class L3AgentTestFramework(base.BaseSudoTestCase): def _configure_agent(self, host): conf = self._get_config_opts() l3_agent_main.register_opts(conf) - cfg.CONF.set_override('debug', False) - agent_config.setup_logging() conf.set_override( 'interface_driver', 'neutron.agent.linux.interface.OVSInterfaceDriver') diff --git a/neutron/tests/functional/base.py b/neutron/tests/functional/base.py index ea4997f6f..2a489a397 100644 --- a/neutron/tests/functional/base.py +++ b/neutron/tests/functional/base.py @@ -19,11 +19,15 @@ from oslo_config import cfg from neutron.agent.common import config from neutron.agent.linux import utils +from neutron.common import utils as common_utils from neutron.tests import base from neutron.tests.common import base as common_base SUDO_CMD = 'sudo -n' +# This is the directory from which infra fetches log files for functional tests +DEFAULT_LOG_DIR = '/tmp/dsvm-functional-logs/' + class BaseSudoTestCase(base.BaseTestCase): """ @@ -48,10 +52,17 @@ class BaseSudoTestCase(base.BaseTestCase): def setUp(self): super(BaseSudoTestCase, self).setUp() - if not base.bool_from_env('OS_SUDO_TESTING'): self.skipTest('Testing with sudo is not enabled') + # Have each test log into its own log file + cfg.CONF.set_override('debug', True) + common_utils.ensure_dir(DEFAULT_LOG_DIR) + log_file = base.sanitize_log_path( + os.path.join(DEFAULT_LOG_DIR, "%s.log" % self.id())) + cfg.CONF.set_override('log_file', log_file) + config.setup_logging() + config.register_root_helper(cfg.CONF) self.config(group='AGENT', root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD)) -- 2.45.2