Fix os_quota when volume service 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.

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

(cherry picked from commit 1aca1f21f9)
This commit is contained in:
Pierre Riteau 2019-06-05 10:50:50 +01:00 committed by Toshio Kuratomi
parent afb91e5140
commit 299fff1d5e
2 changed files with 20 additions and 3 deletions

View file

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

View file

@ -107,6 +107,7 @@ options:
requirements: requirements:
- "python >= 2.7" - "python >= 2.7"
- "openstacksdk >= 0.13.0" - "openstacksdk >= 0.13.0"
- "keystoneauth1 >= 3.4.0"
''' '''
EXAMPLES = ''' 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 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 = {} quota = {}
try: try:
quota['volume'] = _get_volume_quotas(cloud, project) 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.") module.warn("No public endpoint for volumev2 service was found. Ignoring volume quotas.")
try: try:
quota['network'] = _get_network_quotas(cloud, project) 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.") module.warn("No public endpoint for network service was found. Ignoring network quotas.")
quota['compute'] = _get_compute_quotas(cloud, project) quota['compute'] = _get_compute_quotas(cloud, project)
@ -364,6 +375,9 @@ def main():
supports_check_mode=True 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) sdk, cloud = openstack_cloud_from_module(module)
try: try:
cloud_params = dict(module.params) cloud_params = dict(module.params)