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

This commit is contained in:
Jordan Borean 2020-03-25 16:44:50 +10:00 committed by GitHub
parent 48bef155fd
commit e12cea2c7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View 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

View file

@ -92,10 +92,11 @@ def extract_csharp_module_utils_imports(path, module_utils, is_pure_csharp):
continue continue
import_name = match.group(1) 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 return imports

View file

@ -49,7 +49,7 @@ def get_powershell_module_utils_name(path): # type: (str) -> str
base_path = data_context().content.module_utils_powershell_path base_path = data_context().content.module_utils_powershell_path
if data_context().content.collection: 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: else:
prefix = '' prefix = ''
@ -77,7 +77,7 @@ def extract_powershell_module_utils_imports(path, module_utils):
code = read_text_file(path) 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') imports.add('Ansible.ModuleUtils.Legacy')
lines = code.splitlines() lines = code.splitlines()
@ -94,7 +94,8 @@ def extract_powershell_module_utils_imports(path, module_utils):
if import_name in module_utils: if import_name in module_utils:
imports.add(import_name) 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)) display.warning('%s:%d Invalid module_utils import: %s' % (path, line_number, import_name))
return imports return imports