# Path: conjureup/utils.py
# def run(cmd, **kwargs):
#     """ Compatibility function to support python 3.4
#     """
#     try:
#         from subprocess import run as _run
#         return _run(cmd, **kwargs)
#     except ImportError:
#         if 'check' in kwargs:
#             del kwargs['check']
#             return check_call(cmd, **kwargs)
#         else:
#             return check_output(cmd, **kwargs)
# 
# Path: conjureup/hooklib/writer.py
# CACHEDIR = os.getenv('CONJURE_UP_CACHEDIR',
#                      os.path.expanduser('~/.cache/conjure-up'))
# SPELL_NAME = os.getenv('CONJURE_UP_SPELL', '_unspecified_spell')
# LOGFILE = os.path.join(CACHEDIR, '{spell}.log'.format(spell=SPELL_NAME))
# def success(msg):
# def fail(msg):
# def error(msg):
# def info(msg):


import os
import time
import yaml
from subprocess import PIPE, CalledProcessError
from conjureup.utils import run
from .writer import fail, log, success
             md['juju-status'].get('message', ''))
            for name, md in status().get('machines', {}).items()]


def run_action(unit, action):
    """ runs an action on a unit, waits for result
    """
    is_complete = False
    sh = run(
        'juju run-action -m {} {} {}'.format(
            JUJU_CM_STR, unit, action),
        shell=True,
        stdout=PIPE)
    run_action_output = yaml.load(sh.stdout.decode())
    log.debug("{}: {}".format(sh.args, run_action_output))
    action_id = run_action_output.get('Action queued with id', None)
    log.debug("Found action: {}".format(action_id))
    if not action_id:
        fail("Could not determine action id for test")

    while not is_complete:
        sh = run(
            'juju show-action-output -m {} {}'.format(
                JUJU_CM_STR, action_id),
            shell=True,
            stderr=PIPE,
            stdout=PIPE)
        log.debug(sh)
        try:
            output = yaml.load(sh.stdout.decode())

# Path: conjureup/utils.py
# def run(cmd, **kwargs):
#     """ Compatibility function to support python 3.4
#     """
#     try:
#         from subprocess import run as _run
#         return _run(cmd, **kwargs)
#     except ImportError:
#         if 'check' in kwargs:
#             del kwargs['check']
#             return check_call(cmd, **kwargs)
#         else:
#             return check_output(cmd, **kwargs)
# 
# Path: conjureup/hooklib/writer.py
# CACHEDIR = os.getenv('CONJURE_UP_CACHEDIR',
#                      os.path.expanduser('~/.cache/conjure-up'))
# SPELL_NAME = os.getenv('CONJURE_UP_SPELL', '_unspecified_spell')
# LOGFILE = os.path.join(CACHEDIR, '{spell}.log'.format(spell=SPELL_NAME))
# def success(msg):
# def fail(msg):
# def error(msg):
# def info(msg):


# Path: conjureup/hooklib/juju.py
import os
import time
import yaml
from subprocess import PIPE, CalledProcessError
from conjureup.utils import run
from .writer import fail, log, success

             md['juju-status'].get('message', ''))
            for name, md in status().get('machines', {}).items()]


def run_action(unit, action):
    """ runs an action on a unit, waits for result
    """
    is_complete = False
    sh = run(
        'juju run-action -m {} {} {}'.format(
            JUJU_CM_STR, unit, action),
        shell=True,
        stdout=PIPE)
    run_action_output = yaml.load(sh.stdout.decode())
    log.debug("{}: {}".format(sh.args, run_action_output))
    action_id = run_action_output.get('Action queued with id', None)
    log.debug("Found action: {}".format(action_id))
    if not action_id:
        fail("Could not determine action id for test")

    while not is_complete:
        sh = run(
            'juju show-action-output -m {} {}'.format(
                JUJU_CM_STR, action_id),
            shell=True,
            stderr=PIPE,
            stdout=PIPE)
        log.debug(sh)
        try:
            output = yaml.load(sh.stdout.decode())

            log.debug(output)