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:
parent
487f2f25ce
commit
899e5645ed
2 changed files with 35 additions and 1 deletions
|
@ -26,6 +26,7 @@ from abc import ABCMeta, abstractmethod
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
|
from ansible.module_utils.cloud import CloudRetry
|
||||||
from ansible.module_utils.common._collections_compat import Mapping
|
from ansible.module_utils.common._collections_compat import Mapping
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -802,3 +803,32 @@ class BaseModule(object):
|
||||||
if isinstance(full_version, otypes.Version):
|
if isinstance(full_version, otypes.Version):
|
||||||
return int(full_version.minor)
|
return int(full_version.minor)
|
||||||
return int(full_version.split('.')[1])
|
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,
|
equal,
|
||||||
get_entity,
|
get_entity,
|
||||||
get_id_by_name,
|
get_id_by_name,
|
||||||
|
OvirtRetry,
|
||||||
ovirt_full_argument_spec,
|
ovirt_full_argument_spec,
|
||||||
search_by_name,
|
search_by_name,
|
||||||
search_by_attributes,
|
search_by_attributes,
|
||||||
|
@ -676,7 +677,10 @@ def main():
|
||||||
elif state == 'maintenance':
|
elif state == 'maintenance':
|
||||||
sd_id = storage_domains_module.create()['id']
|
sd_id = storage_domains_module.create()['id']
|
||||||
storage_domains_module.post_create_check(sd_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='deactivate',
|
||||||
action_condition=lambda s: s.status == sdstate.ACTIVE,
|
action_condition=lambda s: s.status == sdstate.ACTIVE,
|
||||||
wait_condition=lambda s: s.status == sdstate.MAINTENANCE,
|
wait_condition=lambda s: s.status == sdstate.MAINTENANCE,
|
||||||
|
|
Loading…
Reference in a new issue