Esempio n. 1
0
def add_plugin(path):
    path = common.normalize_path(path)
    if not os.path.isdir(path):
        message = ("invalid plug-in directory: '{}'").format(path)
        raise RuntimeError(message)

    common.execute('ir plugin add "{}"', path)
    LOG.info("plug-in added from path '%s'", path)
Esempio n. 2
0
def remove_plugin(name):
    try:
        common.execute('ir plugin remove "{}"', name)
    except subprocess.CalledProcessError as ex:
        LOG.debug("plug-in '%s' not removed: %s", name, ex)
        return False
    else:
        LOG.info("plug-in '%s' removed", name)
        return True
Esempio n. 3
0
def has_plugin(name):
    try:
        common.execute("ir plugin list | awk '( $4 == \"{}\" )'", name,
                       capture_stdout=False)
    except subprocess.CalledProcessError as ex:
        LOG.debug("tobiko plugin not found ({})", ex)
        return False
    else:
        LOG.info("tobiko plugin found")
        return True
Esempio n. 4
0
def ensure_workspace(filename=None):
    filename = (filename or
                os.environ.get('IR_WORKSPACE_FILE') or
                'workspace.tgz')
    filename = common.normalize_path(filename)
    workspace = common.name_from_path(filename)
    if os.path.isfile(filename):
        try:
            common.execute('ir workspace delete "{}"', workspace)
        except subprocess.CalledProcessError as ex:
            LOG.debug("workspace '%s' not deleted: %s", workspace, ex)
        common.execute('ir workspace import "{}"', filename)
        LOG.info("workspace imported from file '%s'", filename)
        return
    else:
        LOG.debug("workspace file not found: '%s'", filename)

    try:
        common.execute('ir workspace checkout "{}"', workspace)
    except subprocess.CalledProcessError as ex:
        LOG.debug("workspace '%s' not checked out: %s", workspace, ex)
    else:
        LOG.info("workspace '%s' checked out", workspace)
        return

    common.execute('infrared workspace checkout --create "{}"', workspace)
    LOG.info("workspace '%s' created", workspace)
Esempio n. 5
0
def copy_inventory(filename=None):
    filename = (filename or
                os.environ.get('ANSIBLE_INVENTORY') or
                'ansible_hosts')
    if not os.path.isfile(filename):
        LOG.debug('inventary file not found: %r', filename)
        return False

    dest_file = common.execute('ir workspace inventory')
    LOG.debug("got workspace inventory file: '%s'", dest_file)

    dest_dir = os.path.basename(dest_file)
    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)
        LOG.info("directory created: '%s'", dest_dir)

    common.execute('cp {} {}', filename, dest_file)
    LOG.info("inventary file '%s' copied to '%s'", filename, dest_file)
    return True
Esempio n. 6
0
def run_test_cases():
    xdist_options = ''
    if NUM_PROCESSES != '1':
        xdist_options = f"--numprocesses '{NUM_PROCESSES}' --dist loadscope"
    rerun_options = ''
    if RERUNS:
        rerun_options = f"--reruns '{RERUNS}' --reruns-delay '{RERUNS_DELAY}'"
    cover_options = ''
    if COVER:
        cover_options = f"--cov=tobiko"

    # Pass environment variables to pytest command
    environ = dict(os.environ, TOBIKO_REPORT_NAME=REPORT_NAME)
    common.execute(
        "pytest -v "
        f"{xdist_options} "
        f"{rerun_options} "
        f"{cover_options} "
        f"--log-file={REPORT_LOG} "
        f"--junitxml={REPORT_XML} "
        f"--html={REPORT_HTML} --self-contained-html "
        f"{common.get_posargs()}",
        environ=environ,
        capture_stdout=False)
Esempio n. 7
0
def install_bindeps():
    LOG.info(f"Installing Tobiko binary dependencies...")
    common.execute(os.path.join(TOP_DIR, 'tools', 'install-bindeps.sh'),
                   capture_stdout=False)
Esempio n. 8
0
def log_environ():
    common.execute('env | sort >> "{log_file}"',
                   log_file=REPORT_LOG,
                   capture_stdout=False)
Esempio n. 9
0
def get_version():
    version = CACHE.get('version')
    if not version:
        CACHE['version'] = version = common.execute(
            f"git -C '{TOP_DIR}' describe --always").splitlines()[0]
    return version
Esempio n. 10
0
def show_infrared_workspaces():
    return common.execute('ir workspace list', capture_stdout=False)
Esempio n. 11
0
def show_infrared_plugins():
    return common.execute('ir plugin list', capture_stdout=False)
Esempio n. 12
0
def show_infrared_version():
    return common.execute('ir --version || ir --version', capture_stdout=False)