~ec0/mojo/bootstack-frankenbranch

« back to all changes in this revision

Viewing changes to mojo/juju/wait.py

  • Committer: Paul Collins
  • Date: 2017-03-22 00:33:10 UTC
  • Revision ID: paul.collins@canonical.com-20170322003310-us16dyeho0k0r4dv
wait.py: update to 2.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import yaml
34
34
 
35
35
 
36
 
__version__ = '2.4.3'
 
36
__version__ = '2.5.0'
37
37
 
38
38
 
39
39
class DescriptionAction(argparse.Action):
80
80
 
81
81
 
82
82
def juju_exe():
83
 
    return 'juju'
 
83
    # Allow override using environment variable(s)
 
84
    if os.environ.get('JUJU_BINARY'):
 
85
        # JUJU_BINARY can be a full path: /path/to/juju
 
86
        juju = os.environ.get('JUJU_BINARY')
 
87
    elif os.environ.get('JUJU_VERSION'):
 
88
        # JUJU_VERSION can specify just the version
 
89
        # and select from juju-$VER in PATH
 
90
        ver = (".".join(os.environ.get('JUJU_VERSION')
 
91
               .split('-')[0].split('.')[:2]))
 
92
        juju = 'juju-{}'.format(ver)
 
93
    else:
 
94
        # Default to juju in PATH
 
95
        juju = 'juju'
 
96
    return juju
84
97
 
85
98
 
86
99
def juju_run(unit, cmd, timeout=None):
94
107
    units = list(units)
95
108
    if not units:
96
109
        return {}
97
 
    args = ['juju', 'run', '--format=yaml', '--unit', ','.join(units)]
 
110
    args = [juju_exe(), 'run', '--format=yaml', '--unit', ','.join(units)]
98
111
    if timeout is not None:
99
112
        args.append('--timeout={}s'.format(timeout))
100
113
    args.extend(['--', cmd])
424
437
        # Run last as it can take quite awhile on environments with a
425
438
        # large number of services.
426
439
        if ready:
427
 
            # Leadership was added in 1.24, so short-circuit to true
428
 
            # anything older.
429
 
            unit_leadership.update(
430
 
                {uname: True
431
 
                 for uname, ver in agent_version.items()
432
 
                 if ver and LooseVersion(ver) < LooseVersion('1.24')})
 
440
            for uname, ver in agent_version.items():
 
441
                if ver and LooseVersion(ver) < LooseVersion('1.24'):
 
442
                    # Leadership was added in 1.24, so short-circuit to true
 
443
                    # anything older.
 
444
                    unit_leadership[uname] = True
 
445
                elif (ver and LooseVersion(ver) >= LooseVersion('2.1') and
 
446
                      unit_leadership[uname] is None):
 
447
                    # Leadership is set in the status output
 
448
                    # only when leader = True
 
449
                    # Avoid the costly juju run when unnecessary
 
450
                    unit_leadership[uname] = False
433
451
 
434
 
            # Ask all the other units in parallel whether they're the leader.
 
452
            # Ask all the other units in parallel whether they're the
 
453
            # leader if leader is not set.
435
454
            unit_leadership.update(leadership_poll(
436
455
                uname for uname, leader in unit_leadership.items()
437
456
                if leader is None))