def test_get_default_cluster_for_service_empty_deploy_config(): fake_service = "fake_service" with contextlib.nested( mock.patch("paasta_tools.utils.list_clusters", autospec=True, return_value=[]), mock.patch("paasta_tools.utils.load_system_paasta_config", autospec=True), ) as (mock_list_clusters, mock_load_system_paasta_config): mock_load_system_paasta_config.side_effect = utils.PaastaNotConfiguredError with raises(utils.NoConfigurationForServiceError): utils.get_default_cluster_for_service(fake_service) mock_list_clusters.assert_called_once_with(fake_service)
def test_get_default_cluster_for_service_empty_deploy_config(): fake_service = 'fake_service' with contextlib.nested( mock.patch('paasta_tools.utils.list_clusters', autospec=True, return_value=[]), mock.patch('paasta_tools.utils.load_system_paasta_config', autospec=True), ) as ( mock_list_clusters, mock_load_system_paasta_config, ): mock_load_system_paasta_config.side_effect = utils.PaastaNotConfiguredError with raises(utils.NoConfigurationForServiceError): utils.get_default_cluster_for_service(fake_service) mock_list_clusters.assert_called_once_with(fake_service)
def test_get_default_cluster_for_service(): fake_service = "fake_service" fake_clusters = ["fake_cluster-1", "fake_cluster-2"] with contextlib.nested( mock.patch("paasta_tools.utils.list_clusters", autospec=True, return_value=fake_clusters), mock.patch("paasta_tools.utils.load_system_paasta_config", autospec=True), ) as (mock_list_clusters, mock_load_system_paasta_config): mock_load_system_paasta_config.side_effect = utils.PaastaNotConfiguredError assert utils.get_default_cluster_for_service(fake_service) == "fake_cluster-1" mock_list_clusters.assert_called_once_with(fake_service)
def test_get_default_cluster_for_service(): fake_service = 'fake_service' fake_clusters = ['fake_cluster-1', 'fake_cluster-2'] with contextlib.nested( mock.patch('paasta_tools.utils.list_clusters', autospec=True, return_value=fake_clusters), mock.patch('paasta_tools.utils.load_system_paasta_config', autospec=True), ) as ( mock_list_clusters, mock_load_system_paasta_config, ): mock_load_system_paasta_config.side_effect = utils.PaastaNotConfiguredError assert utils.get_default_cluster_for_service(fake_service) == 'fake_cluster-1' mock_list_clusters.assert_called_once_with(fake_service)
def guess_cluster(service, args): """Returns the cluster from args if available, otherwise uses the "default" one""" if args.cluster: cluster = args.cluster else: try: cluster = get_default_cluster_for_service(service) except NoConfigurationForServiceError: sys.stdout.write(PaastaColors.red( 'Could not automatically detect cluster to emulate. Please specify one with the --cluster option.\n')) sys.exit(2) sys.stdout.write(PaastaColors.yellow( 'Guesing cluster configuration for %s. To override, use the --cluster option.\n' % cluster)) return cluster
def guess_cluster(service, args): """Returns the cluster from args if available, otherwise uses the "default" one""" if args.cluster: cluster = args.cluster else: try: cluster = get_default_cluster_for_service(service) except NoConfigurationForServiceError: sys.stdout.write(PaastaColors.red( 'Could not automatically detect cluster to emulate. Please specify one with the --cluster option.\n')) sys.exit(2) sys.stdout.write(PaastaColors.yellow( 'Guesing cluster configuration for %s. To override, use the --cluster option.\n' % cluster)) return cluster
def configure_and_run_docker_container(docker_client, docker_hash, service, args): """ Run Docker container by image hash with args set in command line. Function prints the output of run command in stdout. """ try: system_paasta_config = load_system_paasta_config() except PaastaNotConfiguredError: sys.stdout.write(PaastaColors.yellow( "Warning: Couldn't load config files from '/etc/paasta'. This indicates\n" "PaaSTA is not configured locally on this host, and local-run may not behave\n" "the same way it would behave on a server configured for PaaSTA.\n" )) system_paasta_config = SystemPaastaConfig({"volumes": []}, '/etc/paasta') volumes = list() if args.cluster: cluster = args.cluster else: try: cluster = get_default_cluster_for_service(service) except NoConfigurationForServiceError: sys.stdout.write(PaastaColors.red( 'Could not automatically detect cluster to emulate. Please specify one with the --cluster option.\n')) sys.exit(2) sys.stdout.write(PaastaColors.yellow( 'Using cluster configuration for %s. To override, use the --cluster option.\n\n' % cluster)) instance_config = get_instance_config( service=service, instance=args.instance, cluster=cluster, soa_dir=args.yelpsoa_config_root, ) # if only one volume specified, extra_volumes should be converted to a list extra_volumes = instance_config.get_extra_volumes() if type(extra_volumes) == dict: extra_volumes = [extra_volumes] for volume in system_paasta_config.get_volumes() + extra_volumes: volumes.append('%s:%s:%s' % (volume['hostPath'], volume['containerPath'], volume['mode'].lower())) if args.cmd: command = shlex.split(args.cmd) else: command_from_config = instance_config.get_cmd() if command_from_config: command = shlex.split(command_from_config) else: command = instance_config.get_args() run_docker_container( docker_client=docker_client, service=service, instance=args.instance, docker_hash=docker_hash, volumes=volumes, interactive=args.interactive, command=command, healthcheck=args.healthcheck, healthcheck_only=args.healthcheck_only, instance_config=instance_config, )
def configure_and_run_docker_container(docker_client, docker_hash, service, args): """ Run Docker container by image hash with args set in command line. Function prints the output of run command in stdout. """ try: system_paasta_config = load_system_paasta_config() except PaastaNotConfiguredError: sys.stdout.write( PaastaColors.yellow( "Warning: Couldn't load config files from '/etc/paasta'. This indicates\n" "PaaSTA is not configured locally on this host, and local-run may not behave\n" "the same way it would behave on a server configured for PaaSTA.\n" )) system_paasta_config = SystemPaastaConfig({"volumes": []}, '/etc/paasta') volumes = list() if args.cluster: cluster = args.cluster else: try: cluster = get_default_cluster_for_service(service) except NoConfigurationForServiceError: sys.stdout.write( PaastaColors.red( 'Could not automatically detect cluster to emulate. Please specify one with the --cluster option.\n' )) sys.exit(2) sys.stdout.write( PaastaColors.yellow( 'Using cluster configuration for %s. To override, use the --cluster option.\n\n' % cluster)) instance_config = get_instance_config( service=service, instance=args.instance, cluster=cluster, soa_dir=args.yelpsoa_config_root, ) # if only one volume specified, extra_volumes should be converted to a list extra_volumes = instance_config.get_extra_volumes() if type(extra_volumes) == dict: extra_volumes = [extra_volumes] for volume in system_paasta_config.get_volumes() + extra_volumes: volumes.append('%s:%s:%s' % (volume['hostPath'], volume['containerPath'], volume['mode'].lower())) if args.cmd: command = shlex.split(args.cmd) else: command_from_config = instance_config.get_cmd() if command_from_config: command = shlex.split(command_from_config) else: command = instance_config.get_args() run_docker_container( docker_client=docker_client, service=service, instance=args.instance, docker_hash=docker_hash, volumes=volumes, interactive=args.interactive, command=command, healthcheck=args.healthcheck, healthcheck_only=args.healthcheck_only, instance_config=instance_config, )