diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py index 40ca8bc233..19653bbbee 100644 --- a/lib/ansible/module_utils/ovirt.py +++ b/lib/ansible/module_utils/ovirt.py @@ -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 diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_storage_domain.py b/lib/ansible/modules/cloud/ovirt/ovirt_storage_domain.py index d4ae30bbf2..3b87423725 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_storage_domain.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_storage_domain.py @@ -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,