1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add retry mechanism support for deactivating storage domain (Updated). (#47551)

This commit is contained in:
Joey 2018-11-02 16:48:46 +08:00 committed by John R Barker
parent 487f2f25ce
commit 899e5645ed
2 changed files with 35 additions and 1 deletions

View file

@ -26,6 +26,7 @@ from abc import ABCMeta, abstractmethod
from datetime import datetime
from distutils.version import LooseVersion
from ansible.module_utils.cloud import CloudRetry
from ansible.module_utils.common._collections_compat import Mapping
try:
@ -802,3 +803,32 @@ class BaseModule(object):
if isinstance(full_version, otypes.Version):
return int(full_version.minor)
return int(full_version.split('.')[1])
def _sdk4_error_maybe():
"""
Allow for ovirtsdk4 not being installed.
"""
if HAS_SDK:
return sdk.Error
return type(None)
class OvirtRetry(CloudRetry):
base_class = _sdk4_error_maybe()
@staticmethod
def status_code_from_exception(error):
return error.code
@staticmethod
def found(response_code, catch_extra_error_codes=None):
# This is a list of error codes to retry.
retry_on = [
# HTTP status: Conflict
409,
]
if catch_extra_error_codes:
retry_on.extend(catch_extra_error_codes)
return response_code in retry_on

View file

@ -311,6 +311,7 @@ from ansible.module_utils.ovirt import (
equal,
get_entity,
get_id_by_name,
OvirtRetry,
ovirt_full_argument_spec,
search_by_name,
search_by_attributes,
@ -676,7 +677,10 @@ def main():
elif state == 'maintenance':
sd_id = storage_domains_module.create()['id']
storage_domains_module.post_create_check(sd_id)
ret = storage_domains_module.action(
ret = OvirtRetry.backoff(tries=5, delay=1, backoff=2)(
storage_domains_module.action
)(
action='deactivate',
action_condition=lambda s: s.status == sdstate.ACTIVE,
wait_condition=lambda s: s.status == sdstate.MAINTENANCE,