Merge lp:~fo0bar/juju-wait/juju-wait-quicker into lp:~stub/juju-wait/trunk-migrated-to-git

Proposed by Ryan Finnie
Status: Merged
Merged at revision: 41
Proposed branch: lp:~fo0bar/juju-wait/juju-wait-quicker
Merge into: lp:~stub/juju-wait/trunk-migrated-to-git
Diff against target: 79 lines (+33/-15)
1 file modified
juju_wait/__init__.py (+33/-15)
To merge this branch: bzr merge lp:~fo0bar/juju-wait/juju-wait-quicker
Reviewer Review Type Date Requested Status
Stuart Bishop Approve
Review via email: mp+305537@code.launchpad.net

Description of the change

Ignore update-status hook, check leaders after IDLE_CONFIRMATION loop

These two changes are intended to reduce wait time on large
environments.

~Recent juju (1.24+?) regularly runs housekeeping hooks, the most common
of which is update-status. On a large environment, there is almost
always an update-status run in the last 15 seconds, but juju-wait should
not block on this.

Run the leaders block after the IDLE_CONFIRMATION block, as checking
leadership on an environment with many services takes a significant
amount of time, and is the least likely to set ready = False and begin
the whole process again. Running this last will make it so it's
(usually) only ever run once, at the very end.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Yup.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju_wait/__init__.py'
2--- juju_wait/__init__.py 2016-06-22 17:38:20 +0000
3+++ juju_wait/__init__.py 2016-09-12 22:07:04 +0000
4@@ -295,9 +295,17 @@
5 for uname, astatus in sorted(agent_status.items()):
6 current = astatus['current']
7 since = parse_ts(astatus['since'])
8+ if 'message' in astatus:
9+ message = astatus['message']
10+ else:
11+ message = ''
12
13 # Check agent status
14- if current != 'idle':
15+ if (current == 'executing'
16+ and message == 'running update-status hook'):
17+ # update-status is an idle hook event
18+ pass
19+ elif current != 'idle':
20 logging.debug('{} juju agent status is {} since '
21 '{}Z'.format(uname, current, since))
22 ready = False
23@@ -339,8 +347,29 @@
24 ''.format(uname, logs[uname].strip()))
25 ready = False
26
27+ if ready:
28+ # We are never ready until this check has been running until
29+ # IDLE_CONFIRMATION time has passed. This ensures that if we
30+ # run 'juju wait' immediately after an operation such as
31+ # 'juju upgrade-charm', then the scheduled operation has had
32+ # a chance to fire any hooks it is going to.
33+ if ready_since is None:
34+ ready_since = datetime.utcnow()
35+ ready = False
36+ elif ready_since + IDLE_CONFIRMATION < datetime.utcnow():
37+ logging.info('All units idle since {}Z ({})'
38+ ''.format(ready_since,
39+ ', '.join(sorted(all_units))))
40+ else:
41+ ready = False
42+ else:
43+ ready_since = None
44+ ready = False
45+
46 # Ensure every service has a leader. If there is no leader, then
47 # one will be appointed soon and hooks should kick off.
48+ # Run last as it can take quite awhile on environments with a
49+ # large number of services.
50 if ready:
51 services = set()
52 services_with_leader = set()
53@@ -355,23 +384,12 @@
54 for sname in services:
55 if sname not in services_with_leader:
56 logging.info('{} does not have a leader'.format(sname))
57+ ready_since = None
58 ready = False
59
60+ # If everything looks good, return.
61 if ready:
62- # We are never ready until this check has been running until
63- # IDLE_CONFIRMATION time has passed. This ensures that if we
64- # run 'juju wait' immediately after an operation such as
65- # 'juju upgrade-charm', then the scheduled operation has had
66- # a chance to fire any hooks it is going to.
67- if ready_since is None:
68- ready_since = datetime.utcnow()
69- elif ready_since + IDLE_CONFIRMATION < datetime.utcnow():
70- logging.info('All units idle since {}Z ({})'
71- ''.format(ready_since,
72- ', '.join(sorted(all_units))))
73- return
74- else:
75- ready_since = None
76+ return
77
78 prev_logs = logs
79 time.sleep(4)

Subscribers

People subscribed via source and target branches