diff --git a/changelogs/fragments/ansible-test-coverage-code-cleanup.yml b/changelogs/fragments/ansible-test-coverage-code-cleanup.yml new file mode 100644 index 00000000000..24d14d744dd --- /dev/null +++ b/changelogs/fragments/ansible-test-coverage-code-cleanup.yml @@ -0,0 +1,2 @@ +minor_changes: + - ansible-test - Code cleanup in the internal logic for code coverage collection of PowerShell modules. diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 438f35eaec9..db21ca7c5cc 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -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: diff --git a/lib/ansible/executor/powershell/coverage_wrapper.ps1 b/lib/ansible/executor/powershell/coverage_wrapper.ps1 index 5044ab92244..39bfa05c43a 100644 --- a/lib/ansible/executor/powershell/coverage_wrapper.ps1 +++ b/lib/ansible/executor/powershell/coverage_wrapper.ps1 @@ -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) diff --git a/lib/ansible/executor/powershell/module_manifest.py b/lib/ansible/executor/powershell/module_manifest.py index 83a1c3a7393..9d7987bbb08 100644 --- a/lib/ansible/executor/powershell/module_manifest.py +++ b/lib/ansible/executor/powershell/module_manifest.py @@ -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: diff --git a/test/lib/ansible_test/_internal/util_common.py b/test/lib/ansible_test/_internal/util_common.py index 1ac2e60dd17..0f3ae62767a 100644 --- a/test/lib/ansible_test/_internal/util_common.py +++ b/test/lib/ansible_test/_internal/util_common.py @@ -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