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 elapsed time status updates for distributed_wait #541

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 19 additions & 5 deletions charmhelpers/contrib/hahelpers/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,25 @@ def distributed_wait(modulo=None, wait=None, operation_name='operation'):
# will still wait
calculated_wait = modulo_distribution(modulo=modulo, wait=wait,
non_zero_wait=True)
msg = "Waiting {} seconds for {} ...".format(calculated_wait,
operation_name)
log(msg, DEBUG)
status_set('maintenance', msg)
time.sleep(calculated_wait)

# update status every 60 seconds with wait time elapsed
remaining_wait = calculated_wait
elapsed = 0
while remaining_wait:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more robust if it said:

while remaining_wait > 0:
    ...

I know that by inspection the code will work, it's just the defensive programmer in me!

if elapsed == 0:
msg = "Waiting {} seconds for {} ...".format(calculated_wait,
operation_name)
else:
msg = ("Waiting {} seconds for {} ..."
"elapsed: {} seconds".format(calculated_wait,
operation_name,
elapsed))
log(msg, DEBUG)
status_set('maintenance', msg)
next_sleep = max(remaining_wait, 60)
time.sleep(next_sleep)
elapsed += next_sleep
remaining_wait = calculated_wait - elapsed


def get_managed_services_and_ports(services, external_ports,
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/hahelpers/test_cluster_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def test_distributed_wait(self, log, modulo_distribution, sleep,
is_leader.return_value = True
cluster_utils.distributed_wait(modulo=9, wait=23)
modulo_distribution.assert_not_called()
sleep.assert_called_with(0)
sleep.assert_not_called(0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be good to check that the looping does actually work here. i.e. verify that it works for an odd number of "not divisible by" 60 seconds wait.


# The rest of the tests are non-leader units
is_leader.return_value = False
Expand Down