Code cleanup for ansible-test coverage support.

pull/70070/head
Matt Clay 4 years ago
parent 8d92df4537
commit 74494a1908

@ -0,0 +1,2 @@
minor_changes:
- ansible-test - Code cleanup in the internal logic for code coverage collection of PowerShell modules.

@ -390,7 +390,7 @@ COVERAGE_REMOTE_OUTPUT:
- {name: _ansible_coverage_remote_output}
type: str
version_added: '2.9'
COVERAGE_REMOTE_WHITELIST:
COVERAGE_REMOTE_PATH_FILTER:
name: Sets the list of paths to run coverage for.
description:
- A list of paths for files on the Ansible controller to run coverage for when executing on the remote host.
@ -400,7 +400,7 @@ COVERAGE_REMOTE_WHITELIST:
- This is for internal use only.
default: '*'
env:
- {name: _ANSIBLE_COVERAGE_REMOTE_WHITELIST}
- {name: _ANSIBLE_COVERAGE_REMOTE_PATH_FILTER}
type: str
version_added: '2.9'
ACTION_WARNINGS:

@ -54,7 +54,7 @@ Function New-CoverageBreakpoint {
$info
}
Function Compare-WhitelistPattern {
Function Compare-PathFilterPattern {
Param (
[String[]]$Patterns,
[String]$Path
@ -85,7 +85,7 @@ $file_encoding = 'UTF8'
try {
$scripts = [System.Collections.Generic.List`1[System.Object]]@($script:common_functions)
$coverage_whitelist = $Payload.coverage.whitelist.Split(":", [StringSplitOptions]::RemoveEmptyEntries)
$coverage_path_filter = $Payload.coverage.path_filter.Split(":", [StringSplitOptions]::RemoveEmptyEntries)
# We need to track what utils have already been added to the script for loading. This is because the load
# order is important and can have module_utils that rely on other utils.
@ -104,7 +104,7 @@ try {
Set-Content -LiteralPath $util_path -Value $util_code -Encoding $file_encoding
$ansible_path = $Payload.coverage.module_util_paths.$util_name
if ((Compare-WhitelistPattern -Patterns $coverage_whitelist -Path $ansible_path)) {
if ((Compare-PathFilterPattern -Patterns $coverage_path_filter -Path $ansible_path)) {
$cov_params = @{
Path = $util_path
Code = $util_sb
@ -133,7 +133,7 @@ try {
$scripts.Add($module_path)
$ansible_path = $Payload.coverage.module_path
if ((Compare-WhitelistPattern -Patterns $coverage_whitelist -Path $ansible_path)) {
if ((Compare-PathFilterPattern -Patterns $coverage_path_filter -Path $ansible_path)) {
$cov_params = @{
Path = $module_path
Code = [ScriptBlock]::Create($module)

@ -340,8 +340,8 @@ def _create_powershell_wrapper(b_module_data, module_path, module_args,
finder.scan_exec_script('coverage_wrapper')
coverage_manifest['output'] = coverage_output
coverage_whitelist = C.config.get_config_value('COVERAGE_REMOTE_WHITELIST', variables=task_vars)
coverage_manifest['whitelist'] = coverage_whitelist
coverage_path_filter = C.config.get_config_value('COVERAGE_REMOTE_PATH_FILTER', variables=task_vars)
coverage_manifest['path_filter'] = coverage_path_filter
# make sure Ansible.ModuleUtils.AddType is added if any C# utils are used
if len(finder.cs_utils_wrapper) > 0 or len(finder.cs_utils_module) > 0:

@ -394,7 +394,7 @@ def get_coverage_environment(args, target_name, version, temp_path, module_cover
# is responsible for adding '={language version}=coverage.{hostname}.{pid}.{id}'
env['_ANSIBLE_COVERAGE_REMOTE_OUTPUT'] = os.path.join(remote_temp_path, '%s=%s=%s' % (
args.command, target_name, args.coverage_label or 'remote'))
env['_ANSIBLE_COVERAGE_REMOTE_WHITELIST'] = os.path.join(data_context().content.root, '*')
env['_ANSIBLE_COVERAGE_REMOTE_PATH_FILTER'] = os.path.join(data_context().content.root, '*')
return env

Loading…
Cancel
Save