~hatch/juju-quickstart/no-more-sudo

« back to all changes in this revision

Viewing changes to quickstart/utils.py

  • Committer: Jeff Pihach
  • Date: 2014-01-30 20:29:48 UTC
  • Revision ID: jeff.pihach@canonical.com-20140130202948-a30qx06nb8r12rnt
Refactored the local_requires_sudo check outside of the bootstrap method

Show diffs side-by-side

added added

removed removed

Lines of Context:
328
328
 
329
329
 
330
330
def get_juju_version():
331
 
    """Get the current version of the Juju client.
332
 
 
333
 
    Return a string of the numeric portion of the Juju version.
 
331
    """Return the current juju-core version.
 
332
 
 
333
    Return a (major:int, minor:int, patch:bytes) tuple, including
 
334
    major, minor and patch version numbers.
 
335
 
 
336
    Raise a ValueError if the "juju version" call exits with an error
 
337
    or the returned version is not well formed.
334
338
    """
335
 
    retcode, version, error = call('juju', 'version')
 
339
    retcode, output, error = call('juju', 'version')
336
340
    if retcode:
337
 
        raise OSError(error)
338
 
    return version.split('-')[0]
339
 
 
340
 
 
341
 
def bootstrap_requires_sudo(is_local, version):
342
 
    """After Juju version 1.17.0 sudo is no longer required for
343
 
    bootstrapping local deployments.
 
341
        raise ValueError(error)
 
342
    version_string = output.split('-')[0]
 
343
    try:
 
344
        major, minor, patch = version_string.split('.', 2)
 
345
        return int(major), int(minor), int(patch)
 
346
    except ValueError:
 
347
        msg = 'invalid version string: {}'.format(version_string)
 
348
        raise ValueError(msg.encode('utf-8'))
 
349
 
 
350
 
 
351
def local_bootstrap_requires_sudo(major, minor, patch):
 
352
    """Parse Juju version to check if sudo is required for local deployment.
 
353
 
 
354
    Before Juju version 1.17.2 sudo is required for bootstrapping
 
355
    local environments.
344
356
    """
345
 
    major, minor, _ = version.split('.')
346
 
    return is_local and int(major) >= 1 and int(minor) < 17
 
357
    patch_ok = True
 
358
    if minor < 18:
 
359
        patch_ok = patch <= 1
 
360
    return major >= 1 and minor >= 17 and patch_ok
347
361
 
348
362
 
349
363
def run_once(function):