Merge lp:~gnuoy/openstack-mojo-specs/juju-when-are-you-done into lp:openstack-mojo-specs

Proposed by Liam Young
Status: Needs review
Proposed branch: lp:~gnuoy/openstack-mojo-specs/juju-when-are-you-done
Merge into: lp:openstack-mojo-specs
Diff against target: 122 lines (+48/-11)
2 files modified
helper/tests/check_juju.py (+1/-2)
helper/utils/mojo_utils.py (+47/-9)
To merge this branch: bzr merge lp:~gnuoy/openstack-mojo-specs/juju-when-are-you-done
Reviewer Review Type Date Requested Status
OpenStack Charm Testing Maintainers Pending
Review via email: mp+274390@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

How mojo detects when juju has finished can now be influenced by two environment variables.

1) JUJU_RUN_TIMEOUT When the system being deployed on is busy sometimes the default 5mins is not enough so this can be set to a higher value to make juju run wait longer for the queued run action to complete
2) USE_WORKLOAD_STATUS By default this is true and will use the charms workload status to decide when the charms are finished. Setting this to 'false' will cause mojo to flip back to the old behaviour of relying on juju run.

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #11894 mojo-openstack-specs for gnuoy mp274390
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/11894/

Unmerged revisions

229. By Liam Young

Allow JUJU_RUN_TIMEOUT to be set to specify juju run timeout

228. By Liam Young

Use workload status to check deploy has finished unless disabled by USE_WORKLOAD_STATUS

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'helper/tests/check_juju.py'
2--- helper/tests/check_juju.py 2015-01-13 13:12:47 +0000
3+++ helper/tests/check_juju.py 2015-10-14 13:11:05 +0000
4@@ -1,5 +1,4 @@
5 #!/usr/bin/python
6 import utils.mojo_utils as mojo_utils
7
8-mojo_utils.juju_check_hooks_complete()
9-mojo_utils.juju_status_check_and_wait()
10+mojo_utils.juju_wait_finished()
11
12=== modified file 'helper/utils/mojo_utils.py'
13--- helper/utils/mojo_utils.py 2015-10-09 13:47:36 +0000
14+++ helper/utils/mojo_utils.py 2015-10-14 13:11:05 +0000
15@@ -9,11 +9,13 @@
16 import yaml
17 from collections import Counter
18
19+# XXX 'blocked' can be a transitional or bad state depending on whether the
20+# deployment has finished
21 JUJU_STATUSES = {
22- 'good': ['ACTIVE', 'started'],
23+ 'good': ['ACTIVE', 'started', 'active'],
24 'bad': ['error'],
25 'transitional': ['pending', 'pending', 'down', 'installed', 'stopped',
26- 'allocating'],
27+ 'allocating', 'maintenance', 'blocked'],
28 }
29
30
31@@ -83,6 +85,10 @@
32
33 def remote_shell_check(unit, timeout=None):
34 cmd = ['juju', 'run']
35+ env_timeout = os.environ.get('JUJU_RUN_TIMEOUT')
36+ # Environment specified timeout overrides internally set timeout
37+ if env_timeout:
38+ timeout = env_timeout
39 if timeout:
40 cmd.extend(['--timeout', str(timeout)])
41 cmd.extend(['--unit', unit, 'uname -a'])
42@@ -94,6 +100,10 @@
43 if fatal is None:
44 fatal = True
45 cmd = ['juju', 'run', '--unit', unit]
46+ env_timeout = os.environ.get('JUJU_RUN_TIMEOUT')
47+ # Environment specified timeout overrides internally set timeout
48+ if env_timeout:
49+ timeout = env_timeout
50 if timeout:
51 cmd.extend(['--timeout', str(timeout)])
52 if remote_cmd:
53@@ -379,6 +389,22 @@
54 return get_machine_state(juju_status, 'instance-state')
55
56
57+def get_workload_states(juju_status):
58+ service_state = Counter()
59+ for service in juju_status['services']:
60+ if 'units' in juju_status['services'][service]:
61+ for unit in juju_status['services'][service]['units']:
62+ unit_info = juju_status['services'][service]['units'][unit]
63+ service_state[unit_info['workload-status']['current']] += 1
64+ if 'subordinates' in unit_info:
65+ subs = unit_info['subordinates']
66+ for sub_unit in subs:
67+ sub_sstate = \
68+ subs[sub_unit]['workload-status']['current']
69+ service_state[sub_sstate] += 1
70+ return service_state
71+
72+
73 def get_service_agent_states(juju_status):
74 service_state = Counter()
75 for service in juju_status['services']:
76@@ -419,7 +445,7 @@
77 return True
78
79
80-def juju_status_check_and_wait():
81+def juju_status_check_and_wait(use_workload_status=True):
82 checks = {
83 'Machines': [
84 {
85@@ -438,6 +464,11 @@
86 }
87 ]
88 }
89+ if use_workload_status:
90+ checks['Services'].append({
91+ 'Heading': 'Workload State',
92+ 'check_func': get_workload_states
93+ })
94 stable_state = [False]
95 while False in stable_state:
96 juju_status = get_juju_status()
97@@ -470,12 +501,19 @@
98
99
100 def juju_wait_finished():
101- # Wait till all statuses are green
102- juju_status_check_and_wait()
103- # juju status may report all has finished but hooks are still firing.
104- juju_check_hooks_complete()
105- # Check nothing has subsequently gone bad
106- juju_status_check_and_wait()
107+ use_wls = os.environ.get('USE_WORKLOAD_STATUS')
108+ print use_wls
109+ if use_wls and use_wls.lower() == 'false':
110+ logging.debug("Ignoring workload status, falling back to juju run")
111+ # Wait till all statuses are green
112+ juju_status_check_and_wait(use_workload_status=False)
113+ # juju status may report all has finished but hooks are still firing.
114+ juju_check_hooks_complete()
115+ # Check nothing has subsequently gone bad
116+ juju_status_check_and_wait(use_workload_status=False)
117+ else:
118+ logging.debug("Using workload status to check deployment complete")
119+ juju_status_check_and_wait()
120
121
122 def dict_to_yaml(dict_data):

Subscribers

People subscribed via source and target branches