Exemplo n.º 1
0
def test_run_list(mazer_args_for_test):
    cli = galaxy.GalaxyCLI(args=mazer_args_for_test + ['list'])
    cli.parse()
    res = cli.run()

    log.debug('mat: %s', mazer_args_for_test)
    log.debug('res: %s', res)
Exemplo n.º 2
0
def main(args=None):
    setup_default()

    args = args or sys.argv[:]

    # import logging_tree
    # logging_tree.printout()

    log.debug('args: %s', args)
    cli = galaxy.GalaxyCLI(args)
    try:
        cli.parse()
    except cli_exceptions.CliOptionsError as e:
        cli.parser.print_help()
        log.error(e)
        return os.EX_USAGE

    try:
        exit_code = cli.run()
    except exceptions.GalaxyError as e:
        log.exception(e)
        print(e)
        # exit with EX_SOFTWARE on generic error
        exit_code = os.EX_SOFTWARE

    # do any return code setup we need here
    return exit_code
Exemplo n.º 3
0
def test_build_run_tmp_collection_path(tmpdir, mazer_args_for_test):
    temp_dir = tmpdir.mkdir('mazer_cli_built_run_tmp_output_path_unit_test')
    log.debug('temp_dir: %s', temp_dir.strpath)

    collection_path = tmpdir.mkdir('collection').strpath
    output_path = tmpdir.mkdir('output').strpath

    info_path = os.path.join(collection_path, 'galaxy.yml')
    info_fd = open(info_path, 'w')
    info_fd.write(COLLECTION_INFO1)
    info_fd.close()

    cli = galaxy.GalaxyCLI(args=mazer_args_for_test + [
        'build', '--collection-path', collection_path, '--output-path',
        output_path
    ])
    cli.parse()

    log.debug('cli.options: %s', cli.options)

    res = cli.run()
    log.debug('res: %s', res)

    assert os.path.isdir(output_path)

    expected_artifact_path = os.path.join(
        output_path, 'some_namespace-some_namespace-3.1.4.tar.gz')

    assert os.path.isfile(expected_artifact_path)
    assert tarfile.is_tarfile(expected_artifact_path)
Exemplo n.º 4
0
def test_build_run_no_args():
    cli = galaxy.GalaxyCLI(args=['build'])
    cli.parse()
    log.debug('cli.options: %s', cli.options)

    rc = cli.run()

    assert rc == os.EX_SOFTWARE
Exemplo n.º 5
0
def test_build_no_args():
    cli = galaxy.GalaxyCLI(args=['build'])
    cli.parse()

    log.debug('cli.options: %s', cli.options)
    assert cli.options.output_path is None
    assert cli.options.collection_path is None
    assert cli.args == []
Exemplo n.º 6
0
def test_version_invalid_config(mazer_args_for_test, mocker):

    mocker.patch('ansible_galaxy_cli.cli.galaxy.config.config_file.load',
                 return_value=None)
    cli = galaxy.GalaxyCLI(args=mazer_args_for_test + ['version'])
    cli.parse()
    res = cli.run()

    log.debug('mat: %s', mazer_args_for_test)
    log.debug('res: %s', res)
    assert res == 0
Exemplo n.º 7
0
def main(args=None):
    setup_default()
    setup_custom()

    args = args or sys.argv[:]

    # import logging_tree
    # logging_tree.printout()

    log.debug('args: %s', args)

    cli = galaxy.GalaxyCLI(args)

    try:
        cli.parse()
    except cli_exceptions.CliOptionsError as e:
        cli.parser.print_help()
        log.error(e)
        return os.EX_USAGE

    # TODO: some level of exception mapper to set exit code based on exception
    try:
        exit_code = cli.run()
    except exceptions.GalaxyConfigFileError as e:
        log.exception(e)

        # The str(e)/error here maybe a multiline yaml error that looks
        # best on a fresh line
        stderr_log.error('Error loading configuration file %s:', e.config_file_path)
        stderr_log.error(e)

        return os.EX_CONFIG
    except exceptions.GalaxyError as e:
        log.exception(e)
        stderr_log.error(e)

        # exit with EX_SOFTWARE on generic error
        exit_code = os.EX_SOFTWARE
    except Exception as e:
        log.exception(e)
        stderr_log.error(e)
        exit_code = os.EX_SOFTWARE

        # let non-Galaxy exceptions bubble up and traceback
        log.debug('Uncaught exception for invocation: %s', cli._orig_args_copy)
        log.error('Uncaught exception, existing with exit code: %s', exit_code)
        raise

    log.debug('exit code: %s', exit_code)
    # do any return code setup we need here
    return exit_code
Exemplo n.º 8
0
def test_build_run_tmp_collection_path(tmpdir):
    temp_dir = tmpdir.mkdir('mazer_cli_built_run_tmp_output_path_unit_test')
    log.debug('temp_dir: %s', temp_dir.strpath)

    collection_path = tmpdir.mkdir('collection').strpath
    output_path = tmpdir.mkdir('output').strpath

    info_path = os.path.join(collection_path, 'collection_info.yml')
    info_fd = open(info_path, 'w')
    info_fd.write(COLLECTION_INFO1)
    info_fd.close()

    cli = galaxy.GalaxyCLI(args=[
        'mazer', 'build', '--collection-path', collection_path,
        '--output-path', output_path
    ])
    cli.parse()

    log.debug('cli.options: %s', cli.options)

    res = cli.run()
    log.debug('res: %s', res)
Exemplo n.º 9
0
def test_run_info():
    cli = galaxy.GalaxyCLI(args=['info'])
    cli.parse()
    with pytest.raises(cli_exceptions.CliOptionsError,
                       match="you must specify a user/role name"):
        cli.run()
Exemplo n.º 10
0
def test_info():
    cli = galaxy.GalaxyCLI(args=['info'])
    cli.parse()

    log.debug('cli.options: %s', cli.options)
Exemplo n.º 11
0
def test_publish_no_args(mazer_args_for_test):
    cli = galaxy.GalaxyCLI(args=mazer_args_for_test + ['publish'])
    cli.parse()
    with pytest.raises(cli_exceptions.CliOptionsError,
                       match="you must specify a path"):
        cli.run()
Exemplo n.º 12
0
def test_run_info(mazer_args_for_test):
    cli = galaxy.GalaxyCLI(args=mazer_args_for_test + ['info'])
    cli.parse()
    with pytest.raises(cli_exceptions.CliOptionsError,
                       match="you must specify a collection name"):
        cli.run()
Exemplo n.º 13
0
def test_info(mazer_args_for_test):
    cli = galaxy.GalaxyCLI(args=mazer_args_for_test + ['info'])
    cli.parse()

    log.debug('cli.options: %s', cli.options)