From d31a09ceb7d337521fcfa7cecd0d6523749fad41 Mon Sep 17 00:00:00 2001 From: Alberto Murillo Silva Date: Wed, 3 May 2017 14:43:27 -0500 Subject: [PATCH] Fix os_quota to not break when volumev2 service is not available. 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. Fixes #23085 Signed-off-by: Alberto Murillo Silva --- .../modules/cloud/openstack/os_quota.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_quota.py b/lib/ansible/modules/cloud/openstack/os_quota.py index 1307e5ebd0..502b298b9c 100644 --- a/lib/ansible/modules/cloud/openstack/os_quota.py +++ b/lib/ansible/modules/cloud/openstack/os_quota.py @@ -290,6 +290,7 @@ import sys try: import shade + from keystoneauth1 import exceptions HAS_SHADE = True except ImportError: HAS_SHADE = False @@ -307,11 +308,19 @@ def _get_compute_quotas(cloud, project): return cloud.get_compute_quotas(project) -def _get_quotas(cloud, project): +def _get_quotas(module, cloud, project): quota = {} - quota['volume'] = _get_volume_quotas(cloud, project) - quota['network'] = _get_network_quotas(cloud, project) + try: + quota['volume'] = _get_volume_quotas(cloud, project) + except exceptions.EndpointNotFound: + module.warn("No public endpoint for volumev2 service was found. Ignoring volume quotas.") + + try: + quota['network'] = _get_network_quotas(cloud, project) + except exceptions.EndpointNotFound: + module.warn("No public endpoint for network service was found. Ignoring network quotas.") + quota['compute'] = _get_compute_quotas(cloud, project) for quota_type in quota.keys(): @@ -432,7 +441,7 @@ def main(): module.params[k] = int(v) #Get current quota values - project_quota_output = _get_quotas(cloud, cloud_params['name']) + project_quota_output = _get_quotas(module, cloud, cloud_params['name']) changes_required = False if module.params['state'] == "absent": @@ -461,7 +470,7 @@ def main(): else: module.fail_json(msg=str(e), extra_data=e.extra_data) - project_quota_output = _get_quotas(cloud, cloud_params['name']) + project_quota_output = _get_quotas(module, cloud, cloud_params['name']) changes_required = True @@ -480,7 +489,7 @@ def main(): quota_call(cloud_params['name'], **quota_change_request[quota_type]) #Get quota state post changes for validation - project_quota_update = _get_quotas(cloud, cloud_params['name']) + project_quota_update = _get_quotas(module, cloud, cloud_params['name']) if project_quota_output == project_quota_update: module.fail_json(msg='Could not apply quota update')