# 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
    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)
        except Exception as e:
            log.debug(e)
        if output['status'] == 'running' or output['status'] == 'pending':
            time.sleep(5)
            continue
        if output['status'] == 'failed':
            fail("The test failed, "
                 "please have a look at `juju show-action-status`")
        if output['status'] == 'completed':
            completed_msg = "{} test passed".format(unit)
            results = output.get('results', None)
            if not results:
                is_complete = True
                success(completed_msg)
            if results.get('outcome', None):
                is_complete = True
                completed_msg = "{}: (result) {}".format(
                    completed_msg,
                    results.get('outcome'))

# 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

    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)
        except Exception as e:
            log.debug(e)
        if output['status'] == 'running' or output['status'] == 'pending':
            time.sleep(5)
            continue
        if output['status'] == 'failed':
            fail("The test failed, "
                 "please have a look at `juju show-action-status`")
        if output['status'] == 'completed':
            completed_msg = "{} test passed".format(unit)
            results = output.get('results', None)
            if not results:
                is_complete = True
                success(completed_msg)
            if results.get('outcome', None):
                is_complete = True
                completed_msg = "{}: (result) {}".format(
                    completed_msg,
                    results.get('outcome'))

                success(completed_msg)