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 d31a09ceb7
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
pull/57364/merge
Pierre Riteau 5 years ago committed by ansibot
parent 89be328a29
commit 1eb3fba51f

@ -0,0 +1,3 @@
---
bugfixes:
- "os_quota - fix failure to set compute or network quota when volume service is not available"

@ -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)

Loading…
Cancel
Save