Skip to content

Commit

Permalink
Fix ansible-test coverage path handling. (ansible#61528)
Browse files Browse the repository at this point in the history
* Fix ansible-test coverage path handling.
* Split CI unit tests into two groups.
  • Loading branch information
mattclay authored Aug 30, 2019
1 parent 951dac7 commit e4e5005
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 20 deletions.
19 changes: 13 additions & 6 deletions shippable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ matrix:
- env: T=sanity/4
- env: T=sanity/5

- env: T=units/2.6
- env: T=units/2.7
- env: T=units/3.5
- env: T=units/3.6
- env: T=units/3.7
- env: T=units/3.8
- env: T=units/2.6/1
- env: T=units/2.7/1
- env: T=units/3.5/1
- env: T=units/3.6/1
- env: T=units/3.7/1
- env: T=units/3.8/1

- env: T=units/2.6/2
- env: T=units/2.7/2
- env: T=units/3.5/2
- env: T=units/3.6/2
- env: T=units/3.7/2
- env: T=units/3.8/2

- env: T=windows/2008/1
- env: T=windows/2008-R2/1
Expand Down
31 changes: 19 additions & 12 deletions test/lib/ansible_test/_internal/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
ApplicationError,
common_environment,
ANSIBLE_TEST_DATA_ROOT,
to_bytes,
to_text,
make_dirs,
)

from .util_common import (
intercept_command,
ResultType,
write_text_test_results,
write_json_test_results,
)

from .config import (
Expand Down Expand Up @@ -68,7 +70,12 @@ def command_coverage_combine(args):
:type args: CoverageConfig
:rtype: list[str]
"""
return _command_coverage_combine_powershell(args) + _command_coverage_combine_python(args)
paths = _command_coverage_combine_powershell(args) + _command_coverage_combine_python(args)

for path in paths:
display.info('Generated combined output: %s' % path, verbosity=1)

return paths


def _command_coverage_combine_python(args):
Expand Down Expand Up @@ -342,6 +349,7 @@ def command_coverage_html(args):
continue

dir_name = os.path.join(ResultType.REPORTS.path, os.path.basename(output_file))
make_dirs(dir_name)
run_coverage(args, output_file, 'html', ['-i', '-d', dir_name])

display.info('HTML report generated: file:///%s' % os.path.join(dir_name, 'index.html'))
Expand All @@ -354,18 +362,19 @@ def command_coverage_xml(args):
output_files = command_coverage_combine(args)

for output_file in output_files:
xml_name = os.path.join(ResultType.REPORTS.path, '%s.xml' % os.path.basename(output_file))
xml_name = '%s.xml' % os.path.basename(output_file)
if output_file.endswith('-powershell'):
report = _generage_powershell_xml(output_file)

rough_string = tostring(report, 'utf-8')
reparsed = minidom.parseString(rough_string)
pretty = reparsed.toprettyxml(indent=' ')

with open(xml_name, 'w') as xml_fd:
xml_fd.write(pretty)
write_text_test_results(ResultType.REPORTS, xml_name, pretty)
else:
run_coverage(args, output_file, 'xml', ['-i', '-o', xml_name])
xml_path = os.path.join(ResultType.REPORTS.path, xml_name)
make_dirs(ResultType.REPORTS.path)
run_coverage(args, output_file, 'xml', ['-i', '-o', xml_path])


def command_coverage_erase(args):
Expand Down Expand Up @@ -504,8 +513,6 @@ def _default_stub_value(lines):
invalid_path_count = 0
invalid_path_chars = 0

coverage_file = os.path.join(ResultType.COVERAGE.path, COVERAGE_OUTPUT_FILE_NAME)

for group in sorted(groups):
coverage_data = groups[group]

Expand All @@ -528,11 +535,11 @@ def _default_stub_value(lines):
coverage_data[source] = _default_stub_value(source_line_count)

if not args.explain:
output_file = coverage_file + group + '-powershell'
with open(output_file, 'wb') as output_file_fd:
output_file_fd.write(to_bytes(json.dumps(coverage_data)))
output_file = COVERAGE_OUTPUT_FILE_NAME + group + '-powershell'

output_files.append(output_file)
write_json_test_results(ResultType.COVERAGE, output_file, coverage_data)

output_files.append(os.path.join(ResultType.COVERAGE.path, output_file))

if invalid_path_count > 0:
display.warning(
Expand Down
45 changes: 43 additions & 2 deletions test/utils/shippable/units.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,55 @@ declare -a args
IFS='/:' read -ra args <<< "$1"

version="${args[1]}"
group="${args[2]}"

if [[ "${COVERAGE:-}" == "--coverage" ]]; then
timeout=99
timeout=60
else
timeout=11
timeout=6
fi

group1=()
group2=()

# create two groups by putting long running network tests into one group
# add or remove more network platforms as needed to balance the two groups

networks=(
f5
fortimanager
fortios
ios
junos
netact
netscaler
netvisor
nos
nso
nuage
nxos
onyx
opx
ovs
radware
routeros
slxos
voss
vyos
)

for network in "${networks[@]}"; do
group1+=(--exclude "test/units/modules/network/${network}/")
group2+=("test/units/modules/network/${network}/")
done

case "${group}" in
1) options=("${group1[@]}") ;;
2) options=("${group2[@]}") ;;
esac

ansible-test env --timeout "${timeout}" --color -v

# shellcheck disable=SC2086
ansible-test units --color -v --docker default --python "${version}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \
"${options[@]}" \

0 comments on commit e4e5005

Please sign in to comment.