Example #1
0
def do_main(args):
    _handle_logging(args['--log-level'].upper())

    config_path = args['--config-path']
    if args['create']:
        config = launch.config.get_validated_config(config_path)
        info_path = args['--info-path']
        if os.path.exists(info_path):
            raise launch.util.LauncherError(
                'InputConflict', 'Target info path already exists!')
        write_json(info_path, launch.get_launcher(config).create())
        return 0

    try:
        info = load_json(args['--info-path'])
    except FileNotFoundError as ex:
        raise launch.util.LauncherError('MissingInfoJSON', None) from ex

    launcher = launch.get_launcher(info)

    if args['wait']:
        launcher.wait()
        print('Cluster is ready!')
        return 0

    if args['describe']:
        print(json_prettyprint(launcher.describe()))
        return 0

    if args['pytest']:
        var_list = list()
        if args['--env'] is not None:
            if '=' in args['--env']:
                # User is attempting to do an assigment with the option
                raise launch.util.LauncherError(
                    'OptionError',
                    "The '--env' option can only pass through environment variables "
                    "from the current environment. Set variables according to the shell being used."
                )
            var_list = args['--env'].split(',')
            missing = [v for v in var_list if v not in os.environ]
            if len(missing) > 0:
                raise launch.util.LauncherError(
                    'MissingInput',
                    'Environment variable arguments have been indicated '
                    'but not set: {}'.format(repr(missing)))
        env_dict = {e: os.environ[e] for e in var_list}
        return launcher.test(args['<pytest_extras>'], env_dict)

    if args['delete']:
        launcher.delete()
        return 0
Example #2
0
File: cli.py Project: tamarrow/dcos
def do_main(args):
    _handle_logging(args['--log-level'].upper())

    config_path = args['--config-path']
    if args['create']:
        config = launch.config.get_validated_config(config_path)
        info_path = args['--info-path']
        if os.path.exists(info_path):
            raise launch.util.LauncherError('InputConflict', 'Target info path already exists!')
        write_json(info_path, launch.get_launcher(config).create())
        return 0

    try:
        info = load_json(args['--info-path'])
    except FileNotFoundError as ex:
        raise launch.util.LauncherError('MissingInfoJSON', None) from ex

    launcher = launch.get_launcher(info)

    if args['wait']:
        launcher.wait()
        print('Cluster is ready!')
        return 0

    if args['describe']:
        print(json_prettyprint(launcher.describe()))
        return 0

    if args['pytest']:
        var_list = list()
        if args['--env'] is not None:
            if '=' in args['--env']:
                # User is attempting to do an assigment with the option
                raise launch.util.LauncherError(
                    'OptionError', "The '--env' option can only pass through environment variables "
                    "from the current environment. Set variables according to the shell being used.")
            var_list = args['--env'].split(',')
            missing = [v for v in var_list if v not in os.environ]
            if len(missing) > 0:
                raise launch.util.LauncherError(
                    'MissingInput', 'Environment variable arguments have been indicated '
                    'but not set: {}'.format(repr(missing)))
        env_dict = {e: os.environ[e] for e in var_list}
        return launcher.test(args['<pytest_extras>'], env_dict)

    if args['delete']:
        launcher.delete()
        return 0
Example #3
0
def do_main(args):
    _handle_logging(args['--log-level'].upper())

    config_path = args['--config-path']
    if args['create']:
        config = launch.config.get_validated_config(config_path)
        info_path = args['--info-path']
        if os.path.exists(info_path):
            raise launch.util.LauncherError(
                'InputConflict', 'Target info path already exists!')
        write_json(info_path, launch.get_launcher(config).create(config))
        return 0

    info = load_json(args['--info-path'])
    launcher = launch.get_launcher(info)

    if args['wait']:
        launcher.wait(info)
        print('Cluster is ready!')
        return 0

    if args['describe']:
        print(json_prettyprint(launcher.describe(info)))
        return 0

    if args['pytest']:
        test_cmd = 'py.test'
        if args['--env'] is not None:
            if '=' in args['--env']:
                # User is attempting to do an assigment with the option
                raise launch.util.LauncherError(
                    'OptionError',
                    "The '--env' option can only pass through environment variables "
                    "from the current environment. Set variables according to the shell being used."
                )
            var_list = args['--env'].split(',')
            launch.util.check_keys(os.environ, var_list)
            test_cmd = ' '.join(
                ['{}={}'.format(e, os.environ[e])
                 for e in var_list]) + ' ' + test_cmd
        if len(args['<pytest_extras>']) > 0:
            test_cmd += ' ' + ' '.join(args['<pytest_extras>'])
        launcher.test(info, test_cmd)
        return 0

    if args['delete']:
        launcher.delete(info)
        return 0
Example #4
0
def test_key_helper(aws_cf_with_helper_config_path):
    config = launch.config.get_validated_config(aws_cf_with_helper_config_path)
    aws_launcher = launch.get_launcher(config)
    temp_resources = aws_launcher.key_helper()
    assert temp_resources['key_name'] == config['deployment_name']
    assert yaml.load(config['template_parameters'])['KeyName'] == config['deployment_name']
    assert config['ssh_private_key'] == launch.util.MOCK_SSH_KEY_DATA
def test_key_helper(aws_cf_config_path):
    config = launch.config.get_validated_config(aws_cf_config_path)
    aws_launcher = launch.get_launcher(config)
    temp_resources = aws_launcher.key_helper(config)
    assert temp_resources['key_name'] == config['deployment_name']
    assert yaml.load(
        config['template_parameters'])['KeyName'] == config['deployment_name']
    assert config['ssh_private_key'] == launch.util.MOCK_SSH_KEY_DATA
Example #6
0
def test_missing_aws_stack(aws_cf_config_path, monkeypatch):
    """ Tests that clean and appropriate errors will be raised
    """
    monkeypatch.setattr(test_util.aws, 'fetch_stack', mock_stack_not_found)
    config = launch.config.get_validated_config(aws_cf_config_path)
    aws_launcher = launch.get_launcher(config)

    def check_stack_error(cmd, args):
        with pytest.raises(launch.util.LauncherError) as exinfo:
            getattr(aws_launcher, cmd)(*args)
        assert exinfo.value.error == 'StackNotFound'

    info = aws_launcher.create()
    aws_launcher = launch.get_launcher(info)
    check_stack_error('wait', ())
    check_stack_error('describe', ())
    check_stack_error('delete', ())
    check_stack_error('test', ([], {}))
Example #7
0
def test_missing_aws_stack(aws_cf_config_path, monkeypatch):
    """ Tests that clean and appropriate errors will be raised
    """
    monkeypatch.setattr(test_util.aws, 'fetch_stack', mock_stack_not_found)
    config = launch.config.get_validated_config(aws_cf_config_path)
    aws_launcher = launch.get_launcher(config)

    def check_stack_error(cmd, args):
        with pytest.raises(launch.util.LauncherError) as exinfo:
            getattr(aws_launcher, cmd)(*args)
        assert exinfo.value.error == 'StackNotFound'

    info = aws_launcher.create()
    aws_launcher = launch.get_launcher(info)
    check_stack_error('wait', ())
    check_stack_error('describe', ())
    check_stack_error('delete', ())
    check_stack_error('test', ([], {}))
Example #8
0
def check_success(capsys, tmpdir, config_path):
    """
    Runs through the required functions of a launcher and then
    runs through the default usage of the script for a
    given config path and info path, ensuring each step passes
    if all steps finished successfully, this parses and returns the generated
    info JSON and stdout description JSON for more specific checks
    """
    # Test launcher directly first
    config = launch.config.get_validated_config(config_path)
    launcher = launch.get_launcher(config)
    info = launcher.create()
    # Grab the launcher again with the output from create
    launcher = launch.get_launcher(info)
    launcher.wait()
    launcher.describe()
    launcher.test([], {})
    launcher.delete()

    info_path = str(tmpdir.join('my_specific_info.json'))  # test non-default name

    # Now check launcher via CLI
    check_cli(['create', '--config-path={}'.format(config_path), '--info-path={}'.format(info_path)])
    # use the info written to disk to ensure JSON parsable
    info = pkgpanda.util.load_json(info_path)

    check_cli(['wait', '--info-path={}'.format(info_path)])

    # clear stdout capture
    capsys.readouterr()
    check_cli(['describe', '--info-path={}'.format(info_path)])
    # capture stdout from describe and ensure JSON parse-able
    description = json.loads(capsys.readouterr()[0])

    # general assertions about description
    assert 'masters' in description
    assert 'private_agents' in description
    assert 'public_agents' in description

    check_cli(['pytest', '--info-path={}'.format(info_path)])

    check_cli(['delete', '--info-path={}'.format(info_path)])

    return info, description
Example #9
0
File: cli.py Project: malnick/dcos
def do_main(args):
    _handle_logging(args['--log-level'].upper())

    config_path = args['--config-path']
    if args['create']:
        config = launch.config.get_validated_config(config_path)
        info_path = args['--info-path']
        if os.path.exists(info_path):
            raise launch.util.LauncherError('InputConflict', 'Target info path already exists!')
        write_json(info_path, launch.get_launcher(config).create(config))
        return 0

    info = load_json(args['--info-path'])
    launcher = launch.get_launcher(info)

    if args['wait']:
        launcher.wait(info)
        print('Cluster is ready!')
        return 0

    if args['describe']:
        print(json_prettyprint(launcher.describe(info)))
        return 0

    if args['pytest']:
        test_cmd = 'py.test'
        if args['--env'] is not None:
            if '=' in args['--env']:
                # User is attempting to do an assigment with the option
                raise launch.util.LauncherError(
                    'OptionError', "The '--env' option can only pass through environment variables "
                    "from the current environment. Set variables according to the shell being used.")
            var_list = args['--env'].split(',')
            launch.util.check_keys(os.environ, var_list)
            test_cmd = ' '.join(['{}={}'.format(e, os.environ[e]) for e in var_list]) + ' ' + test_cmd
        if len(args['<pytest_extras>']) > 0:
            test_cmd += ' ' + ' '.join(args['<pytest_extras>'])
        launcher.test(info, test_cmd)
        return 0

    if args['delete']:
        launcher.delete(info)
        return 0
Example #10
0
def test_zen_helper(aws_zen_cf_config_path):
    config = launch.config.get_validated_config(aws_zen_cf_config_path)
    aws_launcher = launch.get_launcher(config)
    temp_resources = aws_launcher.zen_helper()
    assert temp_resources['vpc'] == launch.util.MOCK_VPC_ID
    assert temp_resources['gateway'] == launch.util.MOCK_GATEWAY_ID
    assert temp_resources['private_subnet'] == launch.util.MOCK_SUBNET_ID
    assert temp_resources['public_subnet'] == launch.util.MOCK_SUBNET_ID
    template_parameters = yaml.load(config['template_parameters'])
    assert template_parameters['Vpc'] == launch.util.MOCK_VPC_ID
    assert template_parameters['InternetGateway'] == launch.util.MOCK_GATEWAY_ID
    assert template_parameters['PrivateSubnet'] == launch.util.MOCK_SUBNET_ID
    assert template_parameters['PublicSubnet'] == launch.util.MOCK_SUBNET_ID
def test_zen_helper(aws_zen_cf_config_path):
    config = launch.config.get_validated_config(aws_zen_cf_config_path)
    aws_launcher = launch.get_launcher(config)
    temp_resources = aws_launcher.zen_helper(config)
    assert temp_resources['vpc'] == launch.util.MOCK_VPC_ID
    assert temp_resources['gateway'] == launch.util.MOCK_GATEWAY_ID
    assert temp_resources['private_subnet'] == launch.util.MOCK_SUBNET_ID
    assert temp_resources['public_subnet'] == launch.util.MOCK_SUBNET_ID
    template_parameters = yaml.load(config['template_parameters'])
    assert template_parameters['Vpc'] == launch.util.MOCK_VPC_ID
    assert template_parameters[
        'InternetGateway'] == launch.util.MOCK_GATEWAY_ID
    assert template_parameters['PrivateSubnet'] == launch.util.MOCK_SUBNET_ID
    assert template_parameters['PublicSubnet'] == launch.util.MOCK_SUBNET_ID