diff --git a/changelogs/fragments/test-ps-utils.yaml b/changelogs/fragments/test-ps-utils.yaml new file mode 100644 index 00000000000..a5f403c3c37 --- /dev/null +++ b/changelogs/fragments/test-ps-utils.yaml @@ -0,0 +1,3 @@ +bugfixes: +- ansible-test - Fix PowerShell module util analysis to properly detect the names of a util when running in a collection +- ansible-test - Do not warn on missing PowerShell or C# util that are in other collections diff --git a/test/lib/ansible_test/_internal/csharp_import_analysis.py b/test/lib/ansible_test/_internal/csharp_import_analysis.py index cc99d761fa2..75fb2fff454 100644 --- a/test/lib/ansible_test/_internal/csharp_import_analysis.py +++ b/test/lib/ansible_test/_internal/csharp_import_analysis.py @@ -92,10 +92,11 @@ def extract_csharp_module_utils_imports(path, module_utils, is_pure_csharp): continue import_name = match.group(1) - if import_name not in module_utils: - display.warning('%s:%d Invalid module_utils import: %s' % (path, line_number, import_name)) - continue - imports.add(import_name) + if import_name in module_utils: + imports.add(import_name) + elif data_context().content.is_ansible or \ + import_name.startswith('ansible_collections.%s' % data_context().content.prefix): + display.warning('%s:%d Invalid module_utils import: %s' % (path, line_number, import_name)) return imports diff --git a/test/lib/ansible_test/_internal/powershell_import_analysis.py b/test/lib/ansible_test/_internal/powershell_import_analysis.py index 4c9d7b8e1a1..4bec5aba989 100644 --- a/test/lib/ansible_test/_internal/powershell_import_analysis.py +++ b/test/lib/ansible_test/_internal/powershell_import_analysis.py @@ -49,7 +49,7 @@ def get_powershell_module_utils_name(path): # type: (str) -> str base_path = data_context().content.module_utils_powershell_path if data_context().content.collection: - prefix = 'ansible_collections.' + data_context().content.collection.prefix + '.plugins.module_utils.' + prefix = 'ansible_collections.' + data_context().content.collection.prefix + 'plugins.module_utils.' else: prefix = '' @@ -77,7 +77,7 @@ def extract_powershell_module_utils_imports(path, module_utils): code = read_text_file(path) - if '# POWERSHELL_COMMON' in code: + if data_context().content.is_ansible and '# POWERSHELL_COMMON' in code: imports.add('Ansible.ModuleUtils.Legacy') lines = code.splitlines() @@ -94,7 +94,8 @@ def extract_powershell_module_utils_imports(path, module_utils): if import_name in module_utils: imports.add(import_name) - else: + elif data_context().content.is_ansible or \ + import_name.startswith('ansible_collections.%s' % data_context().content.prefix): display.warning('%s:%d Invalid module_utils import: %s' % (path, line_number, import_name)) return imports