def paasta_get_latest_deployment(args): service = args.service deploy_group = args.deploy_group soa_dir = args.soa_dir validate_service_name(service, soa_dir) git_sha = get_currently_deployed_sha(service=service, deploy_group=deploy_group, soa_dir=soa_dir) if not git_sha: print PaastaColors.red("A deployment could not be found for %s in %s" % (deploy_group, service)) return 1 else: print git_sha return 0
def test_print_cluster_status_missing_deploys_in_red( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master ): # paasta_status displays missing deploys in red service = "fake_service" planned_deployments = ["a_cluster.a_instance", "a_cluster.b_instance"] actual_deployments = {"a_cluster.a_instance": "533976a981679d586bed1cfb534fdba4b4e2c815"} instance_whitelist = [] fake_status = "status: SOMETHING FAKE" mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ( "\n" "cluster: a_cluster\n" " instance: %s\n" " Git sha: 533976a9\n" " %s\n" " instance: %s\n" " Git sha: None\n" % (PaastaColors.blue("a_instance"), fake_status, PaastaColors.red("b_instance")) ) status.report_status_for_cluster( service=service, cluster="a_cluster", deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert expected_output in output
def paasta_get_latest_deployment(args): service = args.service deploy_group = args.deploy_group soa_dir = args.soa_dir validate_service_name(service, soa_dir) git_url = get_git_url( service=service, soa_dir=soa_dir, ) remote_refs = list_remote_refs(git_url) _, git_sha = get_latest_deployment_tag(remote_refs, deploy_group) if not git_sha: print PaastaColors.red("A deployment could not be found for %s in %s" % (deploy_group, service)) return 1 else: print git_sha return 0
def test_print_cluster_status_missing_deploys_in_red( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, system_paasta_config, ): # paasta_status displays missing deploys in red service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': '533976a981679d586bed1cfb534fdba4b4e2c815', } instance_whitelist = [] fake_status = 'status: SOMETHING FAKE' mock_execute_paasta_serviceinit_on_remote_master.return_value = ( sentinel.return_value, fake_status, ) expected_output = ( "\n" "cluster: a_cluster\n" " instance: %s\n" " Git sha: None (not deployed yet)\n" " %s\n" % ( PaastaColors.red('b_instance'), fake_status, ) ) _, output = status.report_status_for_cluster( service=service, cluster='a_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=system_paasta_config, ) output = '\n'.join(str(line) for line in output) assert expected_output in output
def test_print_cluster_status_missing_deploys_in_red( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status displays missing deploys in red service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': '533976a981679d586bed1cfb534fdba4b4e2c815', } instance_whitelist = [] fake_status = 'status: SOMETHING FAKE' fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ( "\n" "cluster: a_cluster\n" " instance: %s\n" " Git sha: 533976a9\n" " %s\n" " instance: %s\n" " Git sha: None\n" % ( PaastaColors.blue('a_instance'), fake_status, PaastaColors.red('b_instance'), ) ) status.report_status_for_cluster( service=service, cluster='a_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=fake_system_paasta_config, ) output = mock_stdout.getvalue() assert expected_output in output
def paasta_get_latest_deployment(args): service = args.service deploy_group = args.deploy_group soa_dir = args.soa_dir validate_service_name(service, soa_dir) git_sha = get_currently_deployed_sha(service=service, deploy_group=deploy_group, soa_dir=soa_dir) if not git_sha: paasta_print( PaastaColors.red( f"A deployment could not be found for {deploy_group} in {service}" ), file=sys.stderr, ) return 1 else: paasta_print(git_sha) return 0
def test_print_cluster_status_missing_deploys_in_red( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status displays missing deploys in red service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': '533976a981679d586bed1cfb534fdba4b4e2c815', } instance_whitelist = [] fake_status = 'status: SOMETHING FAKE' mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ( "\n" "cluster: a_cluster\n" " instance: %s\n" " Git sha: 533976a9\n" " %s\n" " instance: %s\n" " Git sha: None\n" % ( PaastaColors.blue('a_instance'), fake_status, PaastaColors.red('b_instance'), ) ) status.report_status_for_cluster( service=service, cluster='a_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert expected_output in output
def paasta_get_docker_image(args): service = args.service deploy_group = args.deploy_group soa_dir = args.soa_dir validate_service_name(service, soa_dir) deployments = load_v2_deployments_json(service=service, soa_dir=soa_dir) docker_image = deployments.get_docker_image_for_deploy_group(deploy_group) if not docker_image: print( PaastaColors.red( f"There is no {service} docker_image for {deploy_group}. Has it been deployed yet?" ), file=sys.stderr, ) return 1 else: registry_uri = get_service_docker_registry(service=service, soa_dir=soa_dir) docker_url = f"{registry_uri}/{docker_image}" print(docker_url) return 0