~frankban/juju-quickstart/env-creation-proto2

« back to all changes in this revision

Viewing changes to quickstart/utils.py

  • Committer: Francesco Banconi
  • Date: 2013-11-20 14:51:14 UTC
  • mfrom: (17.1.5 local-provider)
  • Revision ID: francesco.banconi@canonical.com-20131120145114-hghyg5b8ca0kq8ed
Add support for local providers.

Bootstrap the environment with "sudo" if
the environment is configured to use the 
local provider.

Also improved debugging documentation.

Tests: make check

To QA this, just run `.venv/bin/python juju-quickstart` 
as you are used to, but with the local provider: 
try to deploy a bundle, try to re-run quickstart again 
with the environment already bootstrapped. 
In general the application should ask for sudo password 
and then proceed as usual.

R=rharding
CC=
https://codereview.appspot.com/29540044

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
_juju_switch_expression = re.compile(r'Current environment: "([\w-]+)"\n')
36
36
 
37
37
 
38
 
def call(*args):
 
38
def call(command, *args):
39
39
    """Call a subprocess passing the given arguments.
40
40
 
41
41
    Take the subcommand and its parameters as args.
43
43
    Return a tuple containing the subprocess return code, output and error.
44
44
    """
45
45
    pipe = subprocess.PIPE
46
 
    cmdline = ' '.join(map(pipes.quote, args))
 
46
    cmd = (command,) + args
 
47
    cmdline = ' '.join(map(pipes.quote, cmd))
47
48
    logging.debug('running the following: {}'.format(cmdline))
48
49
    try:
49
 
        process = subprocess.Popen(args, stdout=pipe, stderr=pipe)
 
50
        process = subprocess.Popen(cmd, stdout=pipe, stderr=pipe)
50
51
    except OSError as err:
51
52
        # A return code 127 is returned by the shell when the command is not
52
53
        # found in the PATH.
53
 
        return 127, '', '{}: {}'.format(args[0], err)
 
54
        return 127, '', '{}: {}'.format(command, err)
54
55
    output, error = process.communicate()
55
56
    retcode = process.poll()
56
57
    logging.debug('retcode: {} | output: {!r} | error: {!r}'.format(