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
=== modified file 'helper/tests/check_juju.py'
--- helper/tests/check_juju.py 2015-01-13 13:12:47 +0000
+++ helper/tests/check_juju.py 2015-10-14 13:11:05 +0000
@@ -1,5 +1,4 @@
1#!/usr/bin/python1#!/usr/bin/python
2import utils.mojo_utils as mojo_utils2import utils.mojo_utils as mojo_utils
33
4mojo_utils.juju_check_hooks_complete()4mojo_utils.juju_wait_finished()
5mojo_utils.juju_status_check_and_wait()
65
=== modified file 'helper/utils/mojo_utils.py'
--- helper/utils/mojo_utils.py 2015-10-09 13:47:36 +0000
+++ helper/utils/mojo_utils.py 2015-10-14 13:11:05 +0000
@@ -9,11 +9,13 @@
9import yaml9import yaml
10from collections import Counter10from collections import Counter
1111
12# XXX 'blocked' can be a transitional or bad state depending on whether the
13# deployment has finished
12JUJU_STATUSES = {14JUJU_STATUSES = {
13 'good': ['ACTIVE', 'started'],15 'good': ['ACTIVE', 'started', 'active'],
14 'bad': ['error'],16 'bad': ['error'],
15 'transitional': ['pending', 'pending', 'down', 'installed', 'stopped',17 'transitional': ['pending', 'pending', 'down', 'installed', 'stopped',
16 'allocating'],18 'allocating', 'maintenance', 'blocked'],
17}19}
1820
1921
@@ -83,6 +85,10 @@
8385
84def remote_shell_check(unit, timeout=None):86def remote_shell_check(unit, timeout=None):
85 cmd = ['juju', 'run']87 cmd = ['juju', 'run']
88 env_timeout = os.environ.get('JUJU_RUN_TIMEOUT')
89 # Environment specified timeout overrides internally set timeout
90 if env_timeout:
91 timeout = env_timeout
86 if timeout:92 if timeout:
87 cmd.extend(['--timeout', str(timeout)])93 cmd.extend(['--timeout', str(timeout)])
88 cmd.extend(['--unit', unit, 'uname -a'])94 cmd.extend(['--unit', unit, 'uname -a'])
@@ -94,6 +100,10 @@
94 if fatal is None:100 if fatal is None:
95 fatal = True101 fatal = True
96 cmd = ['juju', 'run', '--unit', unit]102 cmd = ['juju', 'run', '--unit', unit]
103 env_timeout = os.environ.get('JUJU_RUN_TIMEOUT')
104 # Environment specified timeout overrides internally set timeout
105 if env_timeout:
106 timeout = env_timeout
97 if timeout:107 if timeout:
98 cmd.extend(['--timeout', str(timeout)])108 cmd.extend(['--timeout', str(timeout)])
99 if remote_cmd:109 if remote_cmd:
@@ -379,6 +389,22 @@
379 return get_machine_state(juju_status, 'instance-state')389 return get_machine_state(juju_status, 'instance-state')
380390
381391
392def get_workload_states(juju_status):
393 service_state = Counter()
394 for service in juju_status['services']:
395 if 'units' in juju_status['services'][service]:
396 for unit in juju_status['services'][service]['units']:
397 unit_info = juju_status['services'][service]['units'][unit]
398 service_state[unit_info['workload-status']['current']] += 1
399 if 'subordinates' in unit_info:
400 subs = unit_info['subordinates']
401 for sub_unit in subs:
402 sub_sstate = \
403 subs[sub_unit]['workload-status']['current']
404 service_state[sub_sstate] += 1
405 return service_state
406
407
382def get_service_agent_states(juju_status):408def get_service_agent_states(juju_status):
383 service_state = Counter()409 service_state = Counter()
384 for service in juju_status['services']:410 for service in juju_status['services']:
@@ -419,7 +445,7 @@
419 return True445 return True
420446
421447
422def juju_status_check_and_wait():448def juju_status_check_and_wait(use_workload_status=True):
423 checks = {449 checks = {
424 'Machines': [450 'Machines': [
425 {451 {
@@ -438,6 +464,11 @@
438 }464 }
439 ]465 ]
440 }466 }
467 if use_workload_status:
468 checks['Services'].append({
469 'Heading': 'Workload State',
470 'check_func': get_workload_states
471 })
441 stable_state = [False]472 stable_state = [False]
442 while False in stable_state:473 while False in stable_state:
443 juju_status = get_juju_status()474 juju_status = get_juju_status()
@@ -470,12 +501,19 @@
470501
471502
472def juju_wait_finished():503def juju_wait_finished():
473 # Wait till all statuses are green504 use_wls = os.environ.get('USE_WORKLOAD_STATUS')
474 juju_status_check_and_wait()505 print use_wls
475 # juju status may report all has finished but hooks are still firing.506 if use_wls and use_wls.lower() == 'false':
476 juju_check_hooks_complete()507 logging.debug("Ignoring workload status, falling back to juju run")
477 # Check nothing has subsequently gone bad508 # Wait till all statuses are green
478 juju_status_check_and_wait()509 juju_status_check_and_wait(use_workload_status=False)
510 # juju status may report all has finished but hooks are still firing.
511 juju_check_hooks_complete()
512 # Check nothing has subsequently gone bad
513 juju_status_check_and_wait(use_workload_status=False)
514 else:
515 logging.debug("Using workload status to check deployment complete")
516 juju_status_check_and_wait()
479517
480518
481def dict_to_yaml(dict_data):519def dict_to_yaml(dict_data):

Subscribers

People subscribed via source and target branches