コード例 #1
0
def test_guess_instance_fails(mock_list_all_instances_for_service, ):
    mock_list_all_instances_for_service.side_effect = NoConfigurationForServiceError(
    )
    fake_service = 'fake_service'
    args = mock.MagicMock()
    args.service = fake_service
    args.cluster = None
    with raises(SystemExit) as excinfo:
        utils.guess_cluster(
            service=fake_service,
            args=args,
        )
    assert excinfo.value.code == 2
コード例 #2
0
ファイル: test_utils.py プロジェクト: timopek/paasta
def test_guess_cluster_when_missing_cluster_exception(
    mock_get_default_cluster_for_service,
):
    mock_get_default_cluster_for_service.side_effect = NoConfigurationForServiceError()
    fake_service = 'fake_service'
    args = mock.MagicMock()
    args.service = fake_service
    args.instance = 'fake_instance'
    args.cluster = None
    with raises(SystemExit) as excinfo:
        utils.guess_cluster(
            service=fake_service,
            args=args,
        )
    assert excinfo.value.code == 2
コード例 #3
0
ファイル: test_utils.py プロジェクト: michaelnkang/paasta
def test_guess_cluster_when_missing_cluster_exception(
    mock_get_default_cluster_for_service, ):
    mock_get_default_cluster_for_service.side_effect = NoConfigurationForServiceError(
    )
    fake_service = 'fake_service'
    args = mock.MagicMock()
    args.service = fake_service
    args.instance = 'fake_instance'
    args.cluster = None
    with raises(SystemExit) as excinfo:
        utils.guess_cluster(
            service=fake_service,
            args=args,
        )
    assert excinfo.value.code == 2
コード例 #4
0
def paasta_local_run(args):
    if args.action == 'build' and not makefile_responds_to('cook-image'):
        sys.stderr.write(
            "A local Makefile with a 'cook-image' target is required for --build\n"
        )
        sys.stderr.write(
            "If you meant to pull the docker image from the registry, explicitly pass --pull\n"
        )
        return 1

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)
    cluster = guess_cluster(service=service, args=args)
    instance = guess_instance(service=service, cluster=cluster, args=args)
    docker_client = get_docker_client()

    if args.action == 'build':
        default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
        tag = os.environ.get('DOCKER_TAG', default_tag)
        os.environ['DOCKER_TAG'] = tag
        pull_image = False
        cook_return = paasta_cook_image(args=None,
                                        service=service,
                                        soa_dir=args.yelpsoa_config_root)
        if cook_return != 0:
            return cook_return
    elif args.action == 'dry_run':
        pull_image = False
        tag = None
    else:
        pull_image = True
        tag = None

    try:
        configure_and_run_docker_container(
            docker_client=docker_client,
            docker_hash=tag,
            service=service,
            instance=instance,
            cluster=cluster,
            args=args,
            pull_image=pull_image,
            dry_run=args.action == 'dry_run',
        )
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        return 1
コード例 #5
0
def paasta_local_run(args):
    if args.pull or args.dry_run:
        build = False
    elif args.build:
        build = True
    else:
        build = local_makefile_present()

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)
    cluster = guess_cluster(service=service, args=args)
    instance = guess_instance(service=service, cluster=cluster, args=args)
    docker_client = get_docker_client()

    if build:
        default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
        tag = os.environ.get('DOCKER_TAG', default_tag)
        os.environ['DOCKER_TAG'] = tag
        pull_image = False
        cook_return = paasta_cook_image(args=None,
                                        service=service,
                                        soa_dir=args.yelpsoa_config_root)
        if cook_return != 0:
            return cook_return
    elif args.dry_run:
        pull_image = False
        tag = None
    else:
        pull_image = True
        tag = None

    try:
        configure_and_run_docker_container(
            docker_client=docker_client,
            docker_hash=tag,
            service=service,
            instance=instance,
            cluster=cluster,
            args=args,
            pull_image=pull_image,
            dry_run=args.dry_run,
        )
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        return 1
コード例 #6
0
ファイル: local_run.py プロジェクト: EvanKrall/paasta
def paasta_local_run(args):
    if args.pull or args.dry_run:
        build = False
    elif args.build:
        build = True
    else:
        build = local_makefile_present()

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)
    cluster = guess_cluster(service=service, args=args)
    instance = guess_instance(service=service, cluster=cluster, args=args)
    docker_client = get_docker_client()

    if build:
        default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
        tag = os.environ.get('DOCKER_TAG', default_tag)
        os.environ['DOCKER_TAG'] = tag
        pull_image = False
        cook_return = paasta_cook_image(args=None, service=service, soa_dir=args.yelpsoa_config_root)
        if cook_return != 0:
            return cook_return
    elif args.dry_run:
        pull_image = False
        tag = None
    else:
        pull_image = True
        tag = None

    try:
        configure_and_run_docker_container(
            docker_client=docker_client,
            docker_hash=tag,
            service=service,
            instance=instance,
            cluster=cluster,
            args=args,
            pull_image=pull_image,
            dry_run=args.dry_run,
        )
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        return 1
コード例 #7
0
ファイル: local_run.py プロジェクト: gstarnberger/paasta
def paasta_local_run(args):
    if args.action == 'build' and not makefile_responds_to('cook-image'):
        sys.stderr.write("A local Makefile with a 'cook-image' target is required for --build\n")
        sys.stderr.write("If you meant to pull the docker image from the registry, explicitly pass --pull\n")
        return 1

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)
    cluster = guess_cluster(service=service, args=args)
    instance = guess_instance(service=service, cluster=cluster, args=args)
    docker_client = get_docker_client()

    if args.action == 'build':
        default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
        tag = os.environ.get('DOCKER_TAG', default_tag)
        os.environ['DOCKER_TAG'] = tag
        pull_image = False
        cook_return = paasta_cook_image(args=None, service=service, soa_dir=args.yelpsoa_config_root)
        if cook_return != 0:
            return cook_return
    elif args.action == 'dry_run':
        pull_image = False
        tag = None
    else:
        pull_image = True
        tag = None

    try:
        configure_and_run_docker_container(
            docker_client=docker_client,
            docker_hash=tag,
            service=service,
            instance=instance,
            cluster=cluster,
            args=args,
            pull_image=pull_image,
            dry_run=args.action == 'dry_run',
        )
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        return 1
コード例 #8
0
ファイル: local_run.py プロジェクト: yanyanqin/paasta
def paasta_local_run(args):
    if args.pull:
        build = False
    elif args.build:
        build = True
    else:
        build = local_makefile_present()

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)
    cluster = guess_cluster(service=service, args=args)
    instance = guess_instance(service=service, cluster=cluster, args=args)
    base_docker_url = get_docker_host()
    docker_client = Client(base_url=base_docker_url)

    if build:
        default_tag = "paasta-local-run-%s-%s" % (service, get_username())
        tag = os.environ.get("DOCKER_TAG", default_tag)
        os.environ["DOCKER_TAG"] = tag
        pull_image = False
        paasta_cook_image(args=None, service=service, soa_dir=args.yelpsoa_config_root)
    else:
        pull_image = True
        tag = None

    try:
        configure_and_run_docker_container(
            docker_client=docker_client,
            docker_hash=tag,
            service=service,
            instance=instance,
            cluster=cluster,
            args=args,
            pull_image=pull_image,
        )
    except errors.APIError as e:
        sys.stderr.write("Can't run Docker container. Error: %s\n" % str(e))
        sys.exit(1)
コード例 #9
0
ファイル: test_utils.py プロジェクト: timopek/paasta
def test_guess_cluster_uses_provided_cluster():
    args = mock.MagicMock()
    args.cluster = 'fake_cluster'
    actual = utils.guess_cluster(service='fake_service', args=args)
    assert actual == 'fake_cluster'
コード例 #10
0
ファイル: test_utils.py プロジェクト: michaelnkang/paasta
def test_guess_cluster_uses_provided_cluster():
    args = mock.MagicMock()
    args.cluster = 'fake_cluster'
    actual = utils.guess_cluster(service='fake_service', args=args)
    assert actual == 'fake_cluster'