From 37e91f9d04e4bb1ace0f742aef969b3fdfae90d7 Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Mon, 20 May 2024 23:27:18 -0400 Subject: [PATCH] Fix up ansible sanity checks --- .../plugins/module_utils/controller_api.py | 6 +++--- awx_collection/plugins/modules/ad_hoc_command.py | 2 +- awx_collection/plugins/modules/export.py | 14 ++++++++++++++ awx_collection/plugins/modules/import.py | 2 -- awx_collection/test/awx/conftest.py | 1 - 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/awx_collection/plugins/module_utils/controller_api.py b/awx_collection/plugins/module_utils/controller_api.py index 0f48fc2dff1c..758fcd198664 100644 --- a/awx_collection/plugins/module_utils/controller_api.py +++ b/awx_collection/plugins/module_utils/controller_api.py @@ -107,7 +107,7 @@ def __init__(self, argument_spec=None, direct_params=None, error_callback=None, # Perform magic depending on whether controller_oauthtoken is a string or a dict if self.params.get('controller_oauthtoken'): token_param = self.params.get('controller_oauthtoken') - if type(token_param) is dict: + if isinstance(token_param, dict): if 'token' in token_param: self.oauth_token = self.params.get('controller_oauthtoken')['token'] else: @@ -215,7 +215,7 @@ def load_config(self, config_path): try: config_data = yaml.load(config_string, Loader=yaml.SafeLoader) # If this is an actual ini file, yaml will return the whole thing as a string instead of a dict - if type(config_data) is not dict: + if not isinstance(config_data, dict): raise AssertionError("The yaml config file is not properly formatted as a dict.") try_config_parsing = False @@ -257,7 +257,7 @@ def load_config(self, config_path): if honorred_setting in config_data: # Veriffy SSL must be a boolean if honorred_setting == 'verify_ssl': - if type(config_data[honorred_setting]) is str: + if isinstance(config_data[honorred_setting], str): setattr(self, honorred_setting, strtobool(config_data[honorred_setting])) else: setattr(self, honorred_setting, bool(config_data[honorred_setting])) diff --git a/awx_collection/plugins/modules/ad_hoc_command.py b/awx_collection/plugins/modules/ad_hoc_command.py index 5864d392a5c7..19e848108986 100644 --- a/awx_collection/plugins/modules/ad_hoc_command.py +++ b/awx_collection/plugins/modules/ad_hoc_command.py @@ -163,7 +163,7 @@ def main(): for arg in ['job_type', 'limit', 'forks', 'verbosity', 'extra_vars', 'become_enabled', 'diff_mode']: if module.params.get(arg): # extra_var can receive a dict or a string, if a dict covert it to a string - if arg == 'extra_vars' and type(module.params.get(arg)) is not str: + if arg == 'extra_vars' and isinstance(module.params.get(arg), str): post_data[arg] = json.dumps(module.params.get(arg)) else: post_data[arg] = module.params.get(arg) diff --git a/awx_collection/plugins/modules/export.py b/awx_collection/plugins/modules/export.py index 1080b4889bda..bb9aea070c67 100644 --- a/awx_collection/plugins/modules/export.py +++ b/awx_collection/plugins/modules/export.py @@ -137,6 +137,20 @@ def main(): argument_spec = dict( all=dict(type='bool', default=False), + organizations=dict(type='list', elements='str'), + users=dict(type='list', elements='str'), + teams=dict(type='list', elements='str'), + credential_types=dict(type='list', elements='str'), + credentials=dict(type='list', elements='str'), + execution_environments=dict(type='list', elements='str'), + notification_templates=dict(type='list', elements='str'), + inventory_sources=dict(type='list', elements='str'), + inventory=dict(type='list', elements='str'), + projects=dict(type='list', elements='str'), + job_templates=dict(type='list', elements='str'), + workflow_job_templates=dict(type='list', elements='str'), + applications=dict(type='list', elements='str'), + schedules=dict(type='list', elements='str'), ) # We are not going to raise an error here because the __init__ method of ControllerAWXKitModule will do that for us diff --git a/awx_collection/plugins/modules/import.py b/awx_collection/plugins/modules/import.py index fe66b2a7a3c4..33d843615bc4 100644 --- a/awx_collection/plugins/modules/import.py +++ b/awx_collection/plugins/modules/import.py @@ -56,8 +56,6 @@ # In this module we don't use EXPORTABLE_RESOURCES, we just want to validate that our installed awxkit has import/export try: - from awxkit.api.pages.api import EXPORTABLE_RESOURCES # noqa - HAS_EXPORTABLE_RESOURCES = True except ImportError: HAS_EXPORTABLE_RESOURCES = False diff --git a/awx_collection/test/awx/conftest.py b/awx_collection/test/awx/conftest.py index b7fb6333dd31..94d6b2562287 100644 --- a/awx_collection/test/awx/conftest.py +++ b/awx_collection/test/awx/conftest.py @@ -19,7 +19,6 @@ from ansible_base.rbac.models import RoleDefinition, DABPermission from awx.main.tests.functional.conftest import _request -from awx.main.tests.functional.conftest import credentialtype_scm, credentialtype_ssh # noqa: F401; pylint: disable=unused-variable from awx.main.models import ( Organization, Project,