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

pull/47974/head
Joey 6 years ago committed by John R Barker
parent 487f2f25ce
commit 899e5645ed

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

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

Loading…
Cancel
Save