diff options
author | beeankha <beeankha@gmail.com> | 2021-07-29 22:36:29 +0200 |
---|---|---|
committer | beeankha <beeankha@gmail.com> | 2021-07-30 16:53:44 +0200 |
commit | e88e81928c51b4de38fb226818a76b8ccdcb92c3 (patch) | |
tree | a53add497f629019217bd0eeb0ea0a73693e1ada /awx_collection | |
parent | Merge pull request #10757 from rebeccahhh/instance_node_type (diff) | |
download | awx-e88e81928c51b4de38fb226818a76b8ccdcb92c3.tar.xz awx-e88e81928c51b4de38fb226818a76b8ccdcb92c3.zip |
Fix sanity errors for collections
Diffstat (limited to 'awx_collection')
-rw-r--r-- | awx_collection/plugins/inventory/controller.py | 5 | ||||
-rw-r--r-- | awx_collection/plugins/lookup/schedule_rrule.py | 8 | ||||
-rw-r--r-- | awx_collection/plugins/module_utils/controller_module.py | 6 | ||||
-rw-r--r-- | awx_collection/test/awx/conftest.py | 4 | ||||
-rw-r--r-- | awx_collection/test/awx/test_project.py | 2 |
5 files changed, 14 insertions, 11 deletions
diff --git a/awx_collection/plugins/inventory/controller.py b/awx_collection/plugins/inventory/controller.py index 6709ec232b..78aa903233 100644 --- a/awx_collection/plugins/inventory/controller.py +++ b/awx_collection/plugins/inventory/controller.py @@ -72,6 +72,7 @@ from ansible.errors import AnsibleParserError, AnsibleOptionsError from ansible.plugins.inventory import BaseInventoryPlugin from ansible.config.manager import ensure_type +from ansible.module_utils.six import raise_from from ..module_utils.controller_api import ControllerAPIModule @@ -130,9 +131,9 @@ class InventoryModule(BaseInventoryPlugin): try: inventory_id = ensure_type(inventory_id, 'str') except ValueError as e: - raise AnsibleOptionsError( + raise_from(AnsibleOptionsError( 'Invalid type for configuration option inventory_id, ' 'not integer, and cannot convert to string: {err}'.format(err=to_native(e)) - ) from e + ), e) inventory_id = inventory_id.replace('/', '') inventory_url = '/api/v2/inventories/{inv_id}/script/'.format(inv_id=inventory_id) diff --git a/awx_collection/plugins/lookup/schedule_rrule.py b/awx_collection/plugins/lookup/schedule_rrule.py index cae7266de5..e1079e44ac 100644 --- a/awx_collection/plugins/lookup/schedule_rrule.py +++ b/awx_collection/plugins/lookup/schedule_rrule.py @@ -169,7 +169,7 @@ class LookupModule(LookupBase): try: rrule_kwargs['dtstart'] = LookupModule.parse_date_time(kwargs['start_date']) except Exception as e: - raise AnsibleError('Parameter start_date must be in the format YYYY-MM-DD [HH:MM:SS]') from e + raise_from(AnsibleError('Parameter start_date must be in the format YYYY-MM-DD [HH:MM:SS]'), e) # If we are a none frequency we don't need anything else if frequency == 'none': @@ -184,7 +184,7 @@ class LookupModule(LookupBase): try: rrule_kwargs['until'] = LookupModule.parse_date_time(end_on) except Exception as e: - raise AnsibleError('Parameter end_on must either be an integer or in the format YYYY-MM-DD [HH:MM:SS]') from e + raise_from(AnsibleError('Parameter end_on must either be an integer or in the format YYYY-MM-DD [HH:MM:SS]'), e) # A week-based frequency can also take the on_days parameter if frequency == 'week' and 'on_days' in kwargs: @@ -208,7 +208,7 @@ class LookupModule(LookupBase): if my_month_day < 1 or my_month_day > 31: raise Exception() except Exception as e: - raise AnsibleError('month_day_number must be between 1 and 31') from e + raise_from(AnsibleError('month_day_number must be between 1 and 31'), e) rrule_kwargs['bymonthday'] = my_month_day @@ -216,7 +216,7 @@ class LookupModule(LookupBase): try: (occurance, weekday) = kwargs['on_the'].split(' ') except Exception as e: - raise AnsibleError('on_the parameter must be two words separated by a space') from e + raise_from(AnsibleError('on_the parameter must be two words separated by a space'), e) if weekday not in LookupModule.weekdays: raise AnsibleError('Weekday portion of on_the parameter is not valid') diff --git a/awx_collection/plugins/module_utils/controller_module.py b/awx_collection/plugins/module_utils/controller_module.py index 6b8ced4818..a37111f4e1 100644 --- a/awx_collection/plugins/module_utils/controller_module.py +++ b/awx_collection/plugins/module_utils/controller_module.py @@ -3,7 +3,7 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from ansible.module_utils.basic import AnsibleModule, env_fallback -from ansible.module_utils.six import string_types +from ansible.module_utils.six import raise_from, string_types from ansible.module_utils.six.moves import StringIO from ansible.module_utils.six.moves.urllib.parse import urlparse, urlencode from ansible.module_utils.six.moves.configparser import ConfigParser, NoOptionError @@ -238,10 +238,10 @@ class ControllerModule(AnsibleModule): pass except Exception as e: - raise ConfigFileException("An unknown exception occured trying to ini load config file: {0}".format(e)) from e + raise_from(ConfigFileException("An unknown exception occured trying to ini load config file: {0}".format(e)), e) except Exception as e: - raise ConfigFileException("An unknown exception occured trying to load config file: {0}".format(e)) from e + raise_from(ConfigFileException("An unknown exception occured trying to load config file: {0}".format(e)), 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 for honorred_setting in self.short_params: diff --git a/awx_collection/test/awx/conftest.py b/awx_collection/test/awx/conftest.py index 77cf8d6e07..42325da6fb 100644 --- a/awx_collection/test/awx/conftest.py +++ b/awx_collection/test/awx/conftest.py @@ -15,6 +15,8 @@ from requests.models import Response, PreparedRequest import pytest +from ansible.module_utils.six import raise_from + from awx.main.tests.functional.conftest import _request from awx.main.models import Organization, Project, Inventory, JobTemplate, Credential, CredentialType, ExecutionEnvironment, UnifiedJob @@ -184,7 +186,7 @@ def run_module(request, collection_import): try: result = json.loads(module_stdout) except Exception as e: - raise Exception('Module did not write valid JSON, error: {0}, stdout:\n{1}'.format(str(e), module_stdout)) from e + raise_from(Exception('Module did not write valid JSON, error: {0}, stdout:\n{1}'.format(str(e), module_stdout)), e) # A module exception should never be a test expectation if 'exception' in result: if "ModuleNotFoundError: No module named 'tower_cli'" in result['exception']: diff --git a/awx_collection/test/awx/test_project.py b/awx_collection/test/awx/test_project.py index 0485748b35..9f6da405db 100644 --- a/awx_collection/test/awx/test_project.py +++ b/awx_collection/test/awx/test_project.py @@ -47,4 +47,4 @@ def test_create_project_copy_from(run_module, admin_user, organization, silence_ dict(name=proj_name, copy_from='foo', scm_type='git', wait=False), admin_user, ) - silence_warning.assert_called_with(f"A project with the name {proj_name} already exists.") + silence_warning.assert_called_with("A project with the name {0} already exists.".format(proj_name)) |