Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible-test - fix up powershell module_util analysis for collections #68422

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/test-ps-utils.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions test/lib/ansible_test/_internal/csharp_import_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions test/lib/ansible_test/_internal/powershell_import_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''

Expand Down Expand Up @@ -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()
Expand All @@ -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