ansible-test - fix up powershell module_util analysis for collections (#68422)
This commit is contained in:
parent
48bef155fd
commit
e12cea2c7c
3 changed files with 12 additions and 7 deletions
3
changelogs/fragments/test-ps-utils.yaml
Normal file
3
changelogs/fragments/test-ps-utils.yaml
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue