Retain logs for functional test cases

This helps greatly the debugging process in face of race conditions.

Change-Id: I74235307183cbb15a7179b18b417b38ffb1d2cc9
This commit is contained in:
armando-migliaccio 2015-09-02 17:23:56 -07:00 committed by Assaf Muller
parent 43710925db
commit a97fd4dabb
6 changed files with 35 additions and 13 deletions

View File

@ -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):
"""

View File

@ -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
}

View File

@ -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):

View File

@ -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',

View File

@ -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')

View File

@ -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))