sanity tests

This commit is contained in:
Seth Foster
2021-06-03 16:28:12 -04:00
parent cd100fd770
commit 4bd910493a
11 changed files with 36 additions and 50 deletions

View File

@@ -89,7 +89,7 @@ class InventoryModule(BaseInventoryPlugin):
if path.endswith('@controller_inventory') or path.endswith('@tower_inventory'): if path.endswith('@controller_inventory') or path.endswith('@tower_inventory'):
self.no_config_file_supplied = True self.no_config_file_supplied = True
return True return True
elif super(InventoryModule, self).verify_file(path): elif super().verify_file(path):
return path.endswith( return path.endswith(
( (
'controller_inventory.yml', 'controller_inventory.yml',
@@ -109,7 +109,7 @@ class InventoryModule(BaseInventoryPlugin):
self.display.warning(warning) self.display.warning(warning)
def parse(self, inventory, loader, path, cache=True): def parse(self, inventory, loader, path, cache=True):
super(InventoryModule, self).parse(inventory, loader, path) super().parse(inventory, loader, path)
if not self.no_config_file_supplied and os.path.isfile(path): if not self.no_config_file_supplied and os.path.isfile(path):
self._read_config_data(path) self._read_config_data(path)
@@ -132,7 +132,7 @@ class InventoryModule(BaseInventoryPlugin):
except ValueError as e: except ValueError as e:
raise AnsibleOptionsError( raise AnsibleOptionsError(
'Invalid type for configuration option inventory_id, ' 'not integer, and cannot convert to string: {err}'.format(err=to_native(e)) 'Invalid type for configuration option inventory_id, ' 'not integer, and cannot convert to string: {err}'.format(err=to_native(e))
) ) from e
inventory_id = inventory_id.replace('/', '') inventory_id = inventory_id.replace('/', '')
inventory_url = '/api/v2/inventories/{inv_id}/script/'.format(inv_id=inventory_id) inventory_url = '/api/v2/inventories/{inv_id}/script/'.format(inv_id=inventory_id)

View File

@@ -137,7 +137,7 @@ class LookupModule(LookupBase):
AnsibleError('{0}'.format(LIBRARY_IMPORT_ERROR)), AnsibleError('{0}'.format(LIBRARY_IMPORT_ERROR)),
LIBRARY_IMPORT_ERROR LIBRARY_IMPORT_ERROR
) )
super(LookupModule, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@staticmethod @staticmethod
def parse_date_time(date_string): def parse_date_time(date_string):
@@ -169,8 +169,8 @@ class LookupModule(LookupBase):
if 'start_date' in kwargs: if 'start_date' in kwargs:
try: try:
rrule_kwargs['dtstart'] = LookupModule.parse_date_time(kwargs['start_date']) rrule_kwargs['dtstart'] = LookupModule.parse_date_time(kwargs['start_date'])
except Exception: except Exception as e:
raise AnsibleError('Parameter start_date must be in the format YYYY-MM-DD [HH:MM:SS]') raise AnsibleError('Parameter start_date must be in the format YYYY-MM-DD [HH:MM:SS]') from e
# If we are a none frequency we don't need anything else # If we are a none frequency we don't need anything else
if frequency == 'none': if frequency == 'none':

View File

@@ -22,7 +22,7 @@ class ControllerAWXKitModule(ControllerModule):
def __init__(self, argument_spec, **kwargs): def __init__(self, argument_spec, **kwargs):
kwargs['supports_check_mode'] = False kwargs['supports_check_mode'] = False
super(ControllerAWXKitModule, self).__init__(argument_spec=argument_spec, **kwargs) super().__init__(argument_spec=argument_spec, **kwargs)
# Die if we don't have AWX_KIT installed # Die if we don't have AWX_KIT installed
if not HAS_AWX_KIT: if not HAS_AWX_KIT:

View File

@@ -30,7 +30,7 @@ class ControllerAPIModule(ControllerModule):
def __init__(self, argument_spec, direct_params=None, error_callback=None, warn_callback=None, **kwargs): def __init__(self, argument_spec, direct_params=None, error_callback=None, warn_callback=None, **kwargs):
kwargs['supports_check_mode'] = True kwargs['supports_check_mode'] = True
super(ControllerAPIModule, self).__init__( super().__init__(
argument_spec=argument_spec, direct_params=direct_params, error_callback=error_callback, warn_callback=warn_callback, **kwargs argument_spec=argument_spec, direct_params=direct_params, error_callback=error_callback, warn_callback=warn_callback, **kwargs
) )
self.session = Request(cookies=CookieJar(), validate_certs=self.verify_ssl) self.session = Request(cookies=CookieJar(), validate_certs=self.verify_ssl)

View File

@@ -95,7 +95,7 @@ class ControllerModule(AnsibleModule):
if direct_params is not None: if direct_params is not None:
self.params = direct_params self.params = direct_params
else: else:
super(ControllerModule, self).__init__(argument_spec=full_argspec, **kwargs) super().__init__(argument_spec=full_argspec, **kwargs)
self.load_config_files() self.load_config_files()
@@ -238,10 +238,10 @@ class ControllerModule(AnsibleModule):
pass pass
except Exception as e: except Exception as e:
raise ConfigFileException("An unknown exception occured trying to ini load config file: {0}".format(e)) raise ConfigFileException("An unknown exception occured trying to ini load config file: {0}".format(e)) from e
except Exception as e: except Exception as e:
raise ConfigFileException("An unknown exception occured trying to load config file: {0}".format(e)) raise ConfigFileException("An unknown exception occured trying to load config file: {0}".format(e)) from e
# If we made it here, we have a dict which has values in it from our config, any final settings logic can be performed here # If we made it here, we have a dict which has values in it from our config, any final settings logic can be performed here
for honorred_setting in self.short_params: for honorred_setting in self.short_params:
@@ -265,15 +265,15 @@ class ControllerModule(AnsibleModule):
if self.error_callback: if self.error_callback:
self.error_callback(**kwargs) self.error_callback(**kwargs)
else: else:
super(ControllerModule, self).fail_json(**kwargs) super().fail_json(**kwargs)
def exit_json(self, **kwargs): def exit_json(self, **kwargs):
# Try to log out if we are authenticated # Try to log out if we are authenticated
self.logout() self.logout()
super(ControllerModule, self).exit_json(**kwargs) super().exit_json(**kwargs)
def warn(self, warning): def warn(self, warning):
if self.warn_callback is not None: if self.warn_callback is not None:
self.warn_callback(warning) self.warn_callback(warning)
else: else:
super(ControllerModule, self).warn(warning) super().warn(warning)

View File

@@ -113,7 +113,7 @@ class TowerLegacyModule(AnsibleModule):
) )
) )
super(TowerLegacyModule, self).__init__(argument_spec=args, **kwargs) super().__init__(argument_spec=args, **kwargs)
if not HAS_TOWER_CLI: if not HAS_TOWER_CLI:
self.fail_json(msg=missing_required_lib('ansible-tower-cli'), exception=TOWER_CLI_IMP_ERR) self.fail_json(msg=missing_required_lib('ansible-tower-cli'), exception=TOWER_CLI_IMP_ERR)

View File

@@ -362,7 +362,7 @@ def main():
authorize=dict(type='bool'), authorize=dict(type='bool'),
authorize_password=dict(no_log=True), authorize_password=dict(no_log=True),
client=dict(), client=dict(),
security_token=dict(no_log=True), security_token=dict(no_log=False),
secret=dict(no_log=True), secret=dict(no_log=True),
subscription=dict(), subscription=dict(),
tenant=dict(), tenant=dict(),

View File

@@ -41,6 +41,7 @@ options:
- Signifies that this InstanceGroup should act as a ContainerGroup. If no credential is specified, the underlying Pod's ServiceAccount will be used. - Signifies that this InstanceGroup should act as a ContainerGroup. If no credential is specified, the underlying Pod's ServiceAccount will be used.
required: False required: False
type: bool type: bool
default: False
policy_instance_percentage: policy_instance_percentage:
description: description:
- Minimum percentage of all instances that will be automatically assigned to this group when new instances come online. - Minimum percentage of all instances that will be automatically assigned to this group when new instances come online.
@@ -91,7 +92,7 @@ def main():
name=dict(required=True), name=dict(required=True),
new_name=dict(), new_name=dict(),
credential=dict(), credential=dict(),
is_container_group=dict(type='bool', default=None), is_container_group=dict(type='bool', default=False),
policy_instance_percentage=dict(type='int', default='0'), policy_instance_percentage=dict(type='int', default='0'),
policy_instance_minimum=dict(type='int', default='0'), policy_instance_minimum=dict(type='int', default='0'),
policy_instance_list=dict(type='list', elements='str'), policy_instance_list=dict(type='list', elements='str'),

View File

@@ -164,7 +164,7 @@ def main():
skip_tags=dict(type='list', elements='str'), skip_tags=dict(type='list', elements='str'),
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4, 5]), verbosity=dict(type='int', choices=[0, 1, 2, 3, 4, 5]),
diff_mode=dict(type='bool'), diff_mode=dict(type='bool'),
credential_passwords=dict(type='dict', no_log=True), credential_passwords=dict(type='dict', no_log=False),
wait=dict(default=False, type='bool'), wait=dict(default=False, type='bool'),
interval=dict(default=1.0, type='float'), interval=dict(default=1.0, type='float'),
timeout=dict(default=None, type='int'), timeout=dict(default=None, type='int'),

View File

@@ -140,12 +140,10 @@ options:
type: bool type: bool
aliases: aliases:
- diff_mode_enabled - diff_mode_enabled
default: 'no'
use_fact_cache: use_fact_cache:
description: description:
- Enable use of fact caching for the job template. - Enable use of fact caching for the job template.
type: bool type: bool
default: 'no'
aliases: aliases:
- fact_caching_enabled - fact_caching_enabled
host_config_key: host_config_key:
@@ -156,75 +154,64 @@ options:
description: description:
- Prompt user for (scm branch) on launch. - Prompt user for (scm branch) on launch.
type: bool type: bool
default: 'False'
ask_diff_mode_on_launch: ask_diff_mode_on_launch:
description: description:
- Prompt user to enable diff mode (show changes) to files when supported by modules. - Prompt user to enable diff mode (show changes) to files when supported by modules.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_diff_mode - ask_diff_mode
ask_variables_on_launch: ask_variables_on_launch:
description: description:
- Prompt user for (extra_vars) on launch. - Prompt user for (extra_vars) on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_extra_vars - ask_extra_vars
ask_limit_on_launch: ask_limit_on_launch:
description: description:
- Prompt user for a limit on launch. - Prompt user for a limit on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_limit - ask_limit
ask_tags_on_launch: ask_tags_on_launch:
description: description:
- Prompt user for job tags on launch. - Prompt user for job tags on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_tags - ask_tags
ask_skip_tags_on_launch: ask_skip_tags_on_launch:
description: description:
- Prompt user for job tags to skip on launch. - Prompt user for job tags to skip on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_skip_tags - ask_skip_tags
ask_job_type_on_launch: ask_job_type_on_launch:
description: description:
- Prompt user for job type on launch. - Prompt user for job type on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_job_type - ask_job_type
ask_verbosity_on_launch: ask_verbosity_on_launch:
description: description:
- Prompt user to choose a verbosity level on launch. - Prompt user to choose a verbosity level on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_verbosity - ask_verbosity
ask_inventory_on_launch: ask_inventory_on_launch:
description: description:
- Prompt user for inventory on launch. - Prompt user for inventory on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_inventory - ask_inventory
ask_credential_on_launch: ask_credential_on_launch:
description: description:
- Prompt user for credential on launch. - Prompt user for credential on launch.
type: bool type: bool
default: 'False'
aliases: aliases:
- ask_credential - ask_credential
survey_enabled: survey_enabled:
description: description:
- Enable a survey on the job template. - Enable a survey on the job template.
type: bool type: bool
default: 'no'
survey_spec: survey_spec:
description: description:
- JSON/YAML dict formatted survey definition. - JSON/YAML dict formatted survey definition.
@@ -233,12 +220,10 @@ options:
description: description:
- Activate privilege escalation. - Activate privilege escalation.
type: bool type: bool
default: 'no'
allow_simultaneous: allow_simultaneous:
description: description:
- Allow simultaneous runs of the job template. - Allow simultaneous runs of the job template.
type: bool type: bool
default: 'no'
aliases: aliases:
- concurrent_jobs_enabled - concurrent_jobs_enabled
timeout: timeout:
@@ -388,24 +373,24 @@ def main():
skip_tags=dict(), skip_tags=dict(),
start_at_task=dict(), start_at_task=dict(),
timeout=dict(type='int', default=0), timeout=dict(type='int', default=0),
use_fact_cache=dict(type='bool', aliases=['fact_caching_enabled'], default=False), use_fact_cache=dict(type='bool', aliases=['fact_caching_enabled']),
host_config_key=dict(no_log=True), host_config_key=dict(no_log=False),
ask_diff_mode_on_launch=dict(type='bool', aliases=['ask_diff_mode'], default=False), ask_diff_mode_on_launch=dict(type='bool', aliases=['ask_diff_mode']),
ask_variables_on_launch=dict(type='bool', aliases=['ask_extra_vars'], default=False), ask_variables_on_launch=dict(type='bool', aliases=['ask_extra_vars']),
ask_limit_on_launch=dict(type='bool', aliases=['ask_limit'], default=False), ask_limit_on_launch=dict(type='bool', aliases=['ask_limit']),
ask_tags_on_launch=dict(type='bool', aliases=['ask_tags'], default=False), ask_tags_on_launch=dict(type='bool', aliases=['ask_tags']),
ask_skip_tags_on_launch=dict(type='bool', aliases=['ask_skip_tags'], default=False), ask_skip_tags_on_launch=dict(type='bool', aliases=['ask_skip_tags']),
ask_job_type_on_launch=dict(type='bool', aliases=['ask_job_type'], default=False), ask_job_type_on_launch=dict(type='bool', aliases=['ask_job_type']),
ask_verbosity_on_launch=dict(type='bool', aliases=['ask_verbosity'], default=False), ask_verbosity_on_launch=dict(type='bool', aliases=['ask_verbosity']),
ask_inventory_on_launch=dict(type='bool', aliases=['ask_inventory'], default=False), ask_inventory_on_launch=dict(type='bool', aliases=['ask_inventory']),
ask_credential_on_launch=dict(type='bool', aliases=['ask_credential'], default=False), ask_credential_on_launch=dict(type='bool', aliases=['ask_credential']),
survey_enabled=dict(type='bool', default=False), survey_enabled=dict(type='bool'),
survey_spec=dict(type="dict"), survey_spec=dict(type="dict"),
become_enabled=dict(type='bool', default=False), become_enabled=dict(type='bool'),
diff_mode=dict(type='bool', aliases=['diff_mode_enabled'], default=False), diff_mode=dict(type='bool', aliases=['diff_mode_enabled']),
allow_simultaneous=dict(type='bool', aliases=['concurrent_jobs_enabled'], default=False), allow_simultaneous=dict(type='bool', aliases=['concurrent_jobs_enabled']),
scm_branch=dict(), scm_branch=dict(),
ask_scm_branch_on_launch=dict(type='bool', default=False), ask_scm_branch_on_launch=dict(type='bool'),
job_slice_count=dict(type='int', default='1'), job_slice_count=dict(type='int', default='1'),
webhook_service=dict(choices=['github', 'gitlab', '']), webhook_service=dict(choices=['github', 'gitlab', '']),
webhook_credential=dict(), webhook_credential=dict(),

View File

@@ -184,7 +184,7 @@ def run_module(request, collection_import):
try: try:
result = json.loads(module_stdout) result = json.loads(module_stdout)
except Exception as e: except Exception as e:
raise Exception('Module did not write valid JSON, error: {0}, stdout:\n{1}'.format(str(e), module_stdout)) raise Exception('Module did not write valid JSON, error: {0}, stdout:\n{1}'.format(str(e), module_stdout)) from e
# A module exception should never be a test expectation # A module exception should never be a test expectation
if 'exception' in result: if 'exception' in result:
if "ModuleNotFoundError: No module named 'tower_cli'" in result['exception']: if "ModuleNotFoundError: No module named 'tower_cli'" in result['exception']: