Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state confirmation parameter to wait_for_state method #103

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/cdpy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def expand_file_path(self, file_path):

def wait_for_state(self, describe_func, params: dict, field: Union[str, None, list] = 'status',
state: Union[list, str, None] = None, delay: int = 15, timeout: int = 3600,
ignore_failures: bool = False):
ignore_failures: bool = False, state_confirmation_retries: int = 0):
"""
Proceses a loop waiting for a given function to achieve a given state or known failure states

Expand All @@ -489,6 +489,7 @@ def wait_for_state(self, describe_func, params: dict, field: Union[str, None, li
delay (int): Delay in seconds between each poll of the describe_func. Default is 15
timeout (int): Total wait time in seconds before the function should return a timeout. Default is 3600
ignore_failures (bool): Whether to ignore failed states when waiting for a forced deletion
state_confirmation_retries (int): Number of retry iterations once valid state is reached. Default is 0 (i.e. disabled)

Returns: Output of describe function received during last polling attempt.
"""
Expand All @@ -498,6 +499,7 @@ def wait_for_state(self, describe_func, params: dict, field: Union[str, None, li
if field is not None:
field = field if isinstance(field, list) else [field]
start_time = time()
retry_count = 0 # counter for number of retries
while time() < start_time + timeout:
current = describe_func(**params)
if current is None:
Expand Down Expand Up @@ -530,7 +532,12 @@ def wait_for_state(self, describe_func, params: dict, field: Union[str, None, li
self.logger.info("Waiting to find field {0} in function {1} response"
.format(field, describe_func))
elif current_status in state:
return current
if retry_count >= state_confirmation_retries:
return current
else:
# increment retry counter and loop again to confirm valid state has been reached
self.logger.info("State confirmation retry #{0} in state {1}".format(retry_count, current_status))
retry_count = retry_count + 1
elif current_status in self.FAILED_STATES:
status_reason = 'None provided'
for fail_msg_field in ['statusReason', 'failureMessage']:
Expand Down