Clean up ansible-test results path handling.
This brings us closer to being able to use `tests/` instead of `test/` in collections.
This commit is contained in:
parent
f0d32a2de0
commit
ba1b4565d3
10 changed files with 42 additions and 21 deletions
|
@ -81,7 +81,7 @@ def ansible_environment(args, color=True, ansible_config=None):
|
|||
if args.debug:
|
||||
env.update(dict(
|
||||
ANSIBLE_DEBUG='true',
|
||||
ANSIBLE_LOG_PATH=os.path.abspath('test/results/logs/debug.log'),
|
||||
ANSIBLE_LOG_PATH=os.path.join(data_context().results, 'logs', 'debug.log'),
|
||||
))
|
||||
|
||||
if data_context().content.collection:
|
||||
|
|
|
@ -158,7 +158,8 @@ def cloud_init(args, targets):
|
|||
)
|
||||
|
||||
if not args.explain and results:
|
||||
results_path = 'test/results/data/%s-%s.json' % (args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.utcnow().replace(microsecond=0))))
|
||||
results_path = os.path.join(data_context().results, 'data', '%s-%s.json' % (
|
||||
args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.utcnow().replace(microsecond=0)))))
|
||||
|
||||
data = dict(
|
||||
clouds=results,
|
||||
|
|
|
@ -35,8 +35,6 @@ from .data import (
|
|||
data_context,
|
||||
)
|
||||
|
||||
COVERAGE_DIR = 'test/results/coverage'
|
||||
COVERAGE_FILE = os.path.join(COVERAGE_DIR, 'coverage')
|
||||
COVERAGE_GROUPS = ('command', 'target', 'environment', 'version')
|
||||
COVERAGE_CONFIG_PATH = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'coveragerc')
|
||||
|
||||
|
@ -50,7 +48,8 @@ def command_coverage_combine(args):
|
|||
|
||||
modules = dict((t.module, t.path) for t in list(walk_module_targets()) if t.path.endswith('.py'))
|
||||
|
||||
coverage_files = [os.path.join(COVERAGE_DIR, f) for f in os.listdir(COVERAGE_DIR) if '=coverage.' in f]
|
||||
coverage_dir = os.path.join(data_context().results, 'coverage')
|
||||
coverage_files = [os.path.join(coverage_dir, f) for f in os.listdir(coverage_dir) if '=coverage.' in f]
|
||||
|
||||
ansible_path = os.path.abspath('lib/ansible/') + '/'
|
||||
root_path = data_context().content.root + '/'
|
||||
|
@ -183,6 +182,8 @@ def command_coverage_combine(args):
|
|||
invalid_path_count = 0
|
||||
invalid_path_chars = 0
|
||||
|
||||
coverage_file = os.path.join(data_context().results, 'coverage', 'coverage')
|
||||
|
||||
for group in sorted(groups):
|
||||
arc_data = groups[group]
|
||||
|
||||
|
@ -208,7 +209,7 @@ def command_coverage_combine(args):
|
|||
updated.add_arcs(dict((source, []) for source in sources))
|
||||
|
||||
if not args.explain:
|
||||
output_file = COVERAGE_FILE + group
|
||||
output_file = coverage_file + group
|
||||
updated.write_file(output_file)
|
||||
output_files.append(output_file)
|
||||
|
||||
|
@ -251,7 +252,7 @@ def command_coverage_html(args):
|
|||
output_files = command_coverage_combine(args)
|
||||
|
||||
for output_file in output_files:
|
||||
dir_name = 'test/results/reports/%s' % os.path.basename(output_file)
|
||||
dir_name = os.path.join(data_context().results, 'reports', os.path.basename(output_file))
|
||||
env = common_environment()
|
||||
env.update(dict(COVERAGE_FILE=output_file))
|
||||
run_command(args, env=env, cmd=['coverage', 'html', '--rcfile', COVERAGE_CONFIG_PATH, '-i', '-d', dir_name])
|
||||
|
@ -264,7 +265,7 @@ def command_coverage_xml(args):
|
|||
output_files = command_coverage_combine(args)
|
||||
|
||||
for output_file in output_files:
|
||||
xml_name = 'test/results/reports/%s.xml' % os.path.basename(output_file)
|
||||
xml_name = os.path.join(data_context().results, 'reports', '%s.xml' % os.path.basename(output_file))
|
||||
env = common_environment()
|
||||
env.update(dict(COVERAGE_FILE=output_file))
|
||||
run_command(args, env=env, cmd=['coverage', 'xml', '--rcfile', COVERAGE_CONFIG_PATH, '-i', '-o', xml_name])
|
||||
|
@ -276,11 +277,13 @@ def command_coverage_erase(args):
|
|||
"""
|
||||
initialize_coverage(args)
|
||||
|
||||
for name in os.listdir(COVERAGE_DIR):
|
||||
coverage_dir = os.path.join(data_context().results, 'coverage')
|
||||
|
||||
for name in os.listdir(coverage_dir):
|
||||
if not name.startswith('coverage') and '=coverage.' not in name:
|
||||
continue
|
||||
|
||||
path = os.path.join(COVERAGE_DIR, name)
|
||||
path = os.path.join(coverage_dir, name)
|
||||
|
||||
if not args.explain:
|
||||
os.remove(path)
|
||||
|
|
|
@ -70,6 +70,7 @@ class DataContext:
|
|||
content = self.__create_content_layout(layout_providers, source_providers, current_path, True)
|
||||
|
||||
self.content = content # type: ContentLayout
|
||||
self.results = os.path.join(self.content.root, 'test', 'results')
|
||||
|
||||
@staticmethod
|
||||
def __create_content_layout(layout_providers, # type: t.List[t.Type[LayoutProvider]]
|
||||
|
|
|
@ -47,6 +47,10 @@ from .test import (
|
|||
TestTimeout,
|
||||
)
|
||||
|
||||
from .data import (
|
||||
data_context,
|
||||
)
|
||||
|
||||
|
||||
class EnvConfig(CommonConfig):
|
||||
"""Configuration for the tools command."""
|
||||
|
@ -105,7 +109,7 @@ def show_dump_env(args):
|
|||
show_dict(data, verbose)
|
||||
|
||||
if args.dump and not args.explain:
|
||||
with open('test/results/bot/data-environment.json', 'w') as results_fd:
|
||||
with open(os.path.join(data_context().results, 'bot', 'data-environment.json'), 'w') as results_fd:
|
||||
results_fd.write(json.dumps(data, sort_keys=True))
|
||||
|
||||
|
||||
|
|
|
@ -194,8 +194,8 @@ def install_command_requirements(args, python_version=None):
|
|||
:type python_version: str | None
|
||||
"""
|
||||
if not args.explain:
|
||||
make_dirs('test/results/coverage')
|
||||
make_dirs('test/results/data')
|
||||
make_dirs(os.path.join(data_context().results, 'coverage'))
|
||||
make_dirs(os.path.join(data_context().results, 'data'))
|
||||
|
||||
if isinstance(args, ShellConfig):
|
||||
if args.raw:
|
||||
|
@ -1001,14 +1001,15 @@ def command_integration_filtered(args, targets, all_targets, inventory_path, pre
|
|||
if not args.explain:
|
||||
if args.coverage:
|
||||
coverage_temp_path = os.path.join(common_temp_path, COVERAGE_OUTPUT_NAME)
|
||||
coverage_save_path = 'test/results/coverage'
|
||||
coverage_save_path = os.path.join(data_context().results, 'coverage')
|
||||
|
||||
for filename in os.listdir(coverage_temp_path):
|
||||
shutil.copy(os.path.join(coverage_temp_path, filename), os.path.join(coverage_save_path, filename))
|
||||
|
||||
remove_tree(common_temp_path)
|
||||
|
||||
results_path = 'test/results/data/%s-%s.json' % (args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.utcnow().replace(microsecond=0))))
|
||||
results_path = os.path.join(data_context().results, 'data', '%s-%s.json' % (
|
||||
args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.utcnow().replace(microsecond=0)))))
|
||||
|
||||
data = dict(
|
||||
targets=results,
|
||||
|
@ -1199,7 +1200,7 @@ def integration_environment(args, target, test_dir, inventory_path, ansible_conf
|
|||
callback_plugins = ['junit'] + (env_config.callback_plugins or [] if env_config else [])
|
||||
|
||||
integration = dict(
|
||||
JUNIT_OUTPUT_DIR=os.path.abspath('test/results/junit'),
|
||||
JUNIT_OUTPUT_DIR=os.path.join(data_context().results, 'junit'),
|
||||
ANSIBLE_CALLBACK_WHITELIST=','.join(sorted(set(callback_plugins))),
|
||||
ANSIBLE_TEST_CI=args.metadata.ci_provider,
|
||||
ANSIBLE_TEST_COVERAGE='check' if args.coverage_check else ('yes' if args.coverage else ''),
|
||||
|
|
|
@ -37,6 +37,10 @@ from ..util import (
|
|||
display,
|
||||
)
|
||||
|
||||
from ..data import (
|
||||
data_context,
|
||||
)
|
||||
|
||||
|
||||
class IntegrationAliasesTest(SanityVersionNeutral):
|
||||
"""Sanity test to evaluate integration test aliases."""
|
||||
|
@ -176,7 +180,7 @@ class IntegrationAliasesTest(SanityVersionNeutral):
|
|||
|
||||
self.check_changes(args, results)
|
||||
|
||||
with open('test/results/bot/data-sanity-ci.json', 'w') as results_fd:
|
||||
with open(os.path.join(data_context().results, 'bot', 'data-sanity-ci.json'), 'w') as results_fd:
|
||||
json.dump(results, results_fd, sort_keys=True, indent=4)
|
||||
|
||||
messages = []
|
||||
|
|
|
@ -18,6 +18,10 @@ from .config import (
|
|||
TestConfig,
|
||||
)
|
||||
|
||||
from .data import (
|
||||
data_context,
|
||||
)
|
||||
|
||||
|
||||
def calculate_best_confidence(choices, metadata):
|
||||
"""
|
||||
|
@ -120,7 +124,7 @@ class TestResult:
|
|||
:type extension: str
|
||||
:rtype: str
|
||||
"""
|
||||
path = 'test/results/%s/ansible-test-%s' % (directory, self.command)
|
||||
path = os.path.join(data_context().results, directory, 'ansible-test-%s' % self.command)
|
||||
|
||||
if self.test:
|
||||
path += '-%s' % self.test
|
||||
|
|
|
@ -98,8 +98,7 @@ def command_units(args):
|
|||
'yes' if args.color else 'no',
|
||||
'-p', 'no:cacheprovider',
|
||||
'-c', os.path.join(ANSIBLE_TEST_DATA_ROOT, 'pytest.ini'),
|
||||
'--junit-xml',
|
||||
'test/results/junit/python%s-units.xml' % version,
|
||||
'--junit-xml', os.path.join(data_context().results, 'junit', 'python%s-units.xml' % version),
|
||||
]
|
||||
|
||||
if version != '2.6':
|
||||
|
|
|
@ -24,6 +24,10 @@ from .util import (
|
|||
ANSIBLE_TEST_DATA_ROOT,
|
||||
)
|
||||
|
||||
from .data import (
|
||||
data_context,
|
||||
)
|
||||
|
||||
|
||||
class CommonConfig:
|
||||
"""Configuration common to all commands."""
|
||||
|
@ -159,7 +163,7 @@ def get_coverage_environment(args, target_name, version, temp_path, module_cover
|
|||
# config is in a temporary directory
|
||||
# results are in the source tree
|
||||
coverage_config_base_path = args.coverage_config_base_path
|
||||
coverage_output_base_path = os.path.abspath(os.path.join('test/results'))
|
||||
coverage_output_base_path = data_context().results
|
||||
else:
|
||||
raise Exception('No temp path and no coverage config base path. Check for missing coverage_context usage.')
|
||||
|
||||
|
|
Loading…
Reference in a new issue