From 1eb3fba51f38b2a34c2159ad7bbdf5ea3103b165 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Thu, 4 Jul 2019 05:48:28 +0100 Subject: [PATCH] Fix os_quota when volume service not available (#57364) os_quota checks the current quotas for compute, network and volume services and fails when no volume service is found in the catalog. Since openstack test deployments without volume services are common, os_quota shouldn't fail if such service is missing. This was originally fixed in d31a09ceb7d337521fcfa7cecd0d6523749fad41 and later adapted to catch exceptions raised by shade. Since then, this module moved to using openstacksdk, which doesn't catch the exception raised by keystoneauth1. Fixes #41240 --- .../41240-fix-os_quota-without-cinder.yaml | 3 +++ .../modules/cloud/openstack/os_quota.py | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/41240-fix-os_quota-without-cinder.yaml diff --git a/changelogs/fragments/41240-fix-os_quota-without-cinder.yaml b/changelogs/fragments/41240-fix-os_quota-without-cinder.yaml new file mode 100644 index 00000000000..405ef23730b --- /dev/null +++ b/changelogs/fragments/41240-fix-os_quota-without-cinder.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "os_quota - fix failure to set compute or network quota when volume service is not available" diff --git a/lib/ansible/modules/cloud/openstack/os_quota.py b/lib/ansible/modules/cloud/openstack/os_quota.py index 2486ab1de48..13cde37d841 100644 --- a/lib/ansible/modules/cloud/openstack/os_quota.py +++ b/lib/ansible/modules/cloud/openstack/os_quota.py @@ -107,6 +107,7 @@ options: requirements: - "python >= 2.7" - "openstacksdk >= 0.13.0" + - "keystoneauth1 >= 3.4.0" ''' EXAMPLES = ''' @@ -225,7 +226,17 @@ openstack_quotas: ''' -from ansible.module_utils.basic import AnsibleModule +import traceback + +KEYSTONEAUTH1_IMP_ERR = None +try: + from keystoneauth1 import exceptions as ksa_exceptions + HAS_KEYSTONEAUTH1 = True +except ImportError: + KEYSTONEAUTH1_IMP_ERR = traceback.format_exc() + HAS_KEYSTONEAUTH1 = False + +from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module @@ -249,12 +260,12 @@ def _get_quotas(sdk, module, cloud, project): quota = {} try: quota['volume'] = _get_volume_quotas(cloud, project) - except sdk.exceptions.NotFoundException: + except ksa_exceptions.EndpointNotFound: module.warn("No public endpoint for volumev2 service was found. Ignoring volume quotas.") try: quota['network'] = _get_network_quotas(cloud, project) - except sdk.exceptions.NotFoundException: + except ksa_exceptions.EndpointNotFound: module.warn("No public endpoint for network service was found. Ignoring network quotas.") quota['compute'] = _get_compute_quotas(cloud, project) @@ -364,6 +375,9 @@ def main(): supports_check_mode=True ) + if not HAS_KEYSTONEAUTH1: + module.fail_json(msg=missing_required_lib("keystoneauth1"), exception=KEYSTONEAUTH1_IMP_ERR) + sdk, cloud = openstack_cloud_from_module(module) try: cloud_params = dict(module.params)