def test_guess_instance_uses_provided_cluster(): args = mock.MagicMock() args.instance = 'fake_instance1' actual = utils.guess_instance(service='fake_service', cluster=None, args=args) assert actual == 'fake_instance1'
def test_guess_instance_fails_when_instance_is_not_provided( 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 args.instance = None with raises(SystemExit) as excinfo: utils.guess_instance( service=fake_service, cluster=None, args=args, ) assert excinfo.value.code == 2
def test_guess_instance_fails_when_instance_is_not_provided( 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 args.instance = None with raises(SystemExit) as excinfo: utils.guess_instance( service=fake_service, cluster=None, args=args, ) assert excinfo.value.code == 2
def test_guess_instances_picks_something( mock_list_all_instances_for_service, ): mock_list_all_instances_for_service.return_value = ['a', 'b', 'c'] args = mock.MagicMock() args.instance = None actual = utils.guess_instance(service='fake_service', cluster=None, args=args) assert actual in ['a', 'b', 'c']
def test_guess_instances_uses_main_if_available( mock_list_all_instances_for_service, ): mock_list_all_instances_for_service.return_value = ['a', 'b', 'main', 'c'] args = mock.MagicMock() args.instance = None actual = utils.guess_instance(service='fake_service', cluster=None, args=args) assert actual == 'main'
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
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
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
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)