Refactor test execution scripts
- Acreate a new tools/run_tests.py script to
execute test cases
- Move report generation to such script and
remove 'report' tox environment
- Running test cases generates report files
(.log, .html, .xml) into 'report/{envname}'
directory
- Test cases failures will returns exit code 1
Other script test runner failures returns
exit code 2
Big refactory to tox.ini file to try semplifying it:
- create the new 'py3' tox environment for running unit
tests as default platform python 3 interpreter
- use same as py3 '{envdir}' for scenario, functional,
neutron and faults tox environments
Change-Id: Id09425245cc86b84b41e6b3b1c1db759cc686f3a
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright 2018 Red Hat
|
||||
# Copyright 2020 Red Hat
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@@ -13,29 +13,26 @@
|
||||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
TOP_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
if TOP_DIR not in sys.path:
|
||||
sys.path.insert(0, TOP_DIR)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
from tools import common # noqa
|
||||
|
||||
LOG = common.get_logger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
setup_logging()
|
||||
common.setup_logging()
|
||||
add_tobiko_plugin()
|
||||
ensure_workspace()
|
||||
copy_inventory()
|
||||
|
||||
|
||||
def setup_logging(level=logging.DEBUG):
|
||||
logging.basicConfig(
|
||||
level=level,
|
||||
stream=sys.stderr,
|
||||
format='%(name)-s: %(levelname)-7s %(asctime)-15s | %(message)s')
|
||||
|
||||
|
||||
def add_tobiko_plugin(path=None):
|
||||
path = path or os.environ.get('IR_TOBIKO_PLUGIN')
|
||||
if path:
|
||||
@@ -43,19 +40,19 @@ def add_tobiko_plugin(path=None):
|
||||
|
||||
|
||||
def add_plugin(name, path):
|
||||
path = normalize_path(path)
|
||||
path = common.normalize_path(path)
|
||||
if not os.path.isdir(path):
|
||||
message = ("invalid plug-in '{}' directory: '{}'").format(name, path)
|
||||
raise RuntimeError(message)
|
||||
|
||||
remove_plugin(name)
|
||||
execute('ir plugin add "{}"', path)
|
||||
common.execute('ir plugin add "{}"', path)
|
||||
LOG.info("plug-in '%s' added from path '%s'", name, path)
|
||||
|
||||
|
||||
def remove_plugin(name):
|
||||
try:
|
||||
execute('ir plugin remove "{}"', name)
|
||||
common.execute('ir plugin remove "{}"', name)
|
||||
except subprocess.CalledProcessError as ex:
|
||||
LOG.debug("plug-in '%s' not removed: %s", name, ex)
|
||||
return False
|
||||
@@ -68,11 +65,11 @@ def ensure_workspace(filename=None):
|
||||
filename = (filename or
|
||||
os.environ.get('IR_WORKSPACE_FILE') or
|
||||
'workspace.tgz')
|
||||
filename = normalize_path(filename)
|
||||
workspace = name_from_path(filename)
|
||||
filename = common.normalize_path(filename)
|
||||
workspace = common.name_from_path(filename)
|
||||
if os.path.isfile(filename):
|
||||
try:
|
||||
execute('ir workspace import "{}"', filename)
|
||||
common.execute('ir workspace import "{}"', filename)
|
||||
except subprocess.CalledProcessError as ex:
|
||||
LOG.debug("workspace file '%s' not imported: %s", filename, ex)
|
||||
else:
|
||||
@@ -82,14 +79,14 @@ def ensure_workspace(filename=None):
|
||||
LOG.debug("workspace file not found: '%s'", filename)
|
||||
|
||||
try:
|
||||
execute('ir workspace checkout "{}"', workspace)
|
||||
common.execute('ir workspace checkout "{}"', workspace)
|
||||
except subprocess.CalledProcessError as ex:
|
||||
LOG.debug("workspace '%s' not checked out: %s", workspace, ex)
|
||||
else:
|
||||
LOG.info("workspace '%s' checked out", workspace)
|
||||
return
|
||||
|
||||
execute('infrared workspace checkout --create "{}"', workspace)
|
||||
common.execute('infrared workspace checkout --create "{}"', workspace)
|
||||
LOG.info("workspace '%s' created", workspace)
|
||||
|
||||
|
||||
@@ -101,7 +98,7 @@ def copy_inventory(filename=None):
|
||||
LOG.debug('inventary file not found: %r', filename)
|
||||
return False
|
||||
|
||||
dest_file = execute('ir workspace inventory')
|
||||
dest_file = common.execute('ir workspace inventory')
|
||||
LOG.debug("got workspace inventory file: '%s'", dest_file)
|
||||
|
||||
dest_dir = os.path.basename(dest_file)
|
||||
@@ -109,27 +106,10 @@ def copy_inventory(filename=None):
|
||||
os.makedirs(dest_dir)
|
||||
LOG.info("directory created: '%s'", dest_dir)
|
||||
|
||||
execute('cp {} {}', filename, dest_file)
|
||||
common.execute('cp {} {}', filename, dest_file)
|
||||
LOG.info("inventary file '%s' copied to '%s'", filename, dest_file)
|
||||
return True
|
||||
|
||||
|
||||
def normalize_path(path):
|
||||
return os.path.realpath(os.path.expanduser(path))
|
||||
|
||||
|
||||
def execute(command, *args, **kwargs):
|
||||
if args or kwargs:
|
||||
command = command.format(*args, **kwargs)
|
||||
LOG.debug("execute command: '%s'", command)
|
||||
return subprocess.check_output(command, shell=True,
|
||||
universal_newlines=True)
|
||||
|
||||
|
||||
def name_from_path(path):
|
||||
return os.path.splitext(os.path.basename(path))[0]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
LOG = logging.getLogger(name_from_path(__file__))
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user