def test_report_status_for_cluster_obeys_instance_whitelist( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): service = 'fake_service' planned_deployments = ['cluster.instance1', 'cluster.instance2'] actual_deployments = { 'cluster.instance1': 'sha', 'cluster.instance2': 'sha', } instance_whitelist = ['instance1'] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') status.report_status_for_cluster( service=service, cluster='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 'instance1' in output assert 'instance2' not in output
def test_report_status_for_cluster_displays_deployed_service( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['fake_cluster.fake_instance'] actual_deployments = { 'fake_cluster.fake_instance': 'sha' } instance_whitelist = [] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') fake_status = 'status: SOMETHING FAKE' mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ( "\n" "cluster: fake_cluster\n" " %s\n" % (fake_status) ) status.report_status_for_cluster( service=service, cluster='fake_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 mock_execute_paasta_serviceinit_on_remote_master.assert_called_once_with( 'status', 'fake_cluster', 'fake_service', 'fake_instance', fake_system_paasta_config, stream=True, verbose=0, ignore_ssh_output=True)
def test_report_status_for_cluster_displays_deployed_service( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['cluster.instance'] actual_deployments = {'cluster.instance': 'sha'} instance_whitelist = [] fake_status = 'status: SOMETHING FAKE' mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ("\n" "cluster: cluster\n" " instance: %s\n" " Git sha: sha\n" " %s\n" % ( PaastaColors.blue('instance'), fake_status, )) status.report_status_for_cluster( service=service, cluster='cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert expected_output in output
def test_print_cluster_status_calls_execute_paasta_serviceinit_on_remote_master( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, verbosity_level ): service = "fake_service" planned_deployments = ["a_cluster.a_instance", "a_cluster.b_instance"] actual_deployments = {"a_cluster.a_instance": "this_is_a_sha"} instance_whitelist = [] fake_output = "Marathon: 5 instances" mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_output expected_output = " %s\n" % fake_output status.report_status_for_cluster( service=service, cluster="a_cluster", deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, verbose=verbosity_level, ) assert mock_execute_paasta_serviceinit_on_remote_master.call_count == 1 mock_execute_paasta_serviceinit_on_remote_master.assert_any_call( "status", "a_cluster", service, "a_instance", verbose=verbosity_level ) output = mock_stdout.getvalue() assert expected_output in output
def test_report_status_for_cluster_obeys_instance_whitelist( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): service = 'fake_service' planned_deployments = ['fake_cluster.fake_instance_a', 'fake_cluster.fake_instance_b'] actual_deployments = { 'fake_cluster.fake_instance_a': 'sha', 'fake_cluster.fake_instance_b': 'sha', } instance_whitelist = ['fake_instance_a'] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') status.report_status_for_cluster( service=service, cluster='fake_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=fake_system_paasta_config, ) mock_execute_paasta_serviceinit_on_remote_master.assert_called_once_with( 'status', 'fake_cluster', 'fake_service', 'fake_instance_a', fake_system_paasta_config, stream=True, verbose=0, ignore_ssh_output=True)
def test_report_status_for_cluster_displays_deployed_service( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master ): # paasta_status with no args displays deploy info - vanilla case service = "fake_service" planned_deployments = ["cluster.instance"] actual_deployments = {"cluster.instance": "sha"} instance_whitelist = [] fake_status = "status: SOMETHING FAKE" mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ( "\n" "cluster: cluster\n" " instance: %s\n" " Git sha: sha\n" " %s\n" % (PaastaColors.blue("instance"), fake_status) ) status.report_status_for_cluster( service=service, cluster="cluster", deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert expected_output in output
def test_report_status_for_cluster_displays_multiple_lines_from_execute_paasta_serviceinit_on_remote_master( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['cluster.instance'] actual_deployments = { 'cluster.instance': 'this_is_a_sha' } instance_whitelist = [] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') fake_status = 'status: SOMETHING FAKE\nand then something fake\non another line!\n\n\n' mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ( " status: SOMETHING FAKE\n" " and then something fake\n" " on another line!\n" ) status.report_status_for_cluster( service=service, cluster='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 test_print_cluster_status_calls_execute_paasta_serviceinit_on_remote_master( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': 'this_is_a_sha', } instance_whitelist = [] fake_output = "Marathon: 5 instances" mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_output expected_output = " %s\n" % fake_output status.report_status_for_cluster( service=service, cluster='a_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) assert mock_execute_paasta_serviceinit_on_remote_master.call_count == 1 mock_execute_paasta_serviceinit_on_remote_master.assert_any_call( 'status', 'a_cluster', service, 'a_instance', verbose=False) output = mock_stdout.getvalue() assert expected_output in output
def test_report_status_for_cluster_displays_multiple_lines_from_execute_paasta_serviceinit_on_remote_master( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['cluster.instance'] actual_deployments = {'cluster.instance': 'this_is_a_sha'} instance_whitelist = [] fake_status = 'status: SOMETHING FAKE\nand then something fake\non another line!\n\n\n' mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = (" status: SOMETHING FAKE\n" " and then something fake\n" " on another line!\n") status.report_status_for_cluster( service=service, cluster='cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert expected_output in output
def test_print_cluster_status_calls_execute_paasta_serviceinit_on_remote_master( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, verbosity_level, ): service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': 'this_is_a_sha', } instance_whitelist = [] fake_output = "Marathon: 5 instances" mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_output expected_output = " %s\n" % fake_output status.report_status_for_cluster( service=service, cluster='a_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, verbose=verbosity_level, ) assert mock_execute_paasta_serviceinit_on_remote_master.call_count == 1 mock_execute_paasta_serviceinit_on_remote_master.assert_any_call( 'status', 'a_cluster', service, 'a_instance', verbose=verbosity_level) output = mock_stdout.getvalue() assert expected_output in output
def test_report_status_for_cluster_obeys_instance_whitelist( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): service = 'fake_service' planned_deployments = [ 'fake_cluster.fake_instance_a', 'fake_cluster.fake_instance_b' ] actual_deployments = { 'fake_cluster.fake_instance_a': 'sha', 'fake_cluster.fake_instance_b': 'sha', } instance_whitelist = ['fake_instance_a'] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') status.report_status_for_cluster( service=service, cluster='fake_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=fake_system_paasta_config, ) mock_execute_paasta_serviceinit_on_remote_master.assert_called_once_with( 'status', 'fake_cluster', 'fake_service', 'fake_instance_a', fake_system_paasta_config, stream=True, verbose=0, ignore_ssh_output=True)
def test_report_status_for_cluster_displays_multiple_lines_from_execute_paasta_serviceinit_on_remote_master( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, capfd, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['cluster.instance'] actual_deployments = { 'cluster.instance': 'this_is_a_sha', } instance_whitelist = [] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') fake_status = 'status: SOMETHING FAKE\nand then something fake\non another line!\n\n\n' mock_execute_paasta_serviceinit_on_remote_master.return_value = ( sentinel.return_value, fake_status, ) expected_output = (" status: SOMETHING FAKE\n" " and then something fake\n" " on another line!\n") status.report_status_for_cluster( service=service, cluster='cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=fake_system_paasta_config, ) output, _ = capfd.readouterr() assert expected_output in output
def test_report_status_for_cluster_displays_deployed_service( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['fake_cluster.fake_instance'] actual_deployments = {'fake_cluster.fake_instance': 'sha'} instance_whitelist = [] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') fake_status = 'status: SOMETHING FAKE' mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = ("\n" "cluster: fake_cluster\n" " %s\n" % (fake_status)) status.report_status_for_cluster( service=service, cluster='fake_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 mock_execute_paasta_serviceinit_on_remote_master.assert_called_once_with( 'status', 'fake_cluster', 'fake_service', 'fake_instance', fake_system_paasta_config, stream=True, verbose=0)
def test_report_status_for_cluster_obeys_instance_whitelist( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, system_paasta_config, ): service = 'fake_service' planned_deployments = ['fake_cluster.fake_instance_a', 'fake_cluster.fake_instance_b'] actual_deployments = { 'fake_cluster.fake_instance_a': 'sha', 'fake_cluster.fake_instance_b': 'sha', } instance_whitelist = ['fake_instance_a'] mock_execute_paasta_serviceinit_on_remote_master.return_value = ( sentinel.return_value, 'fake_output', ) status.report_status_for_cluster( service=service, cluster='fake_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=system_paasta_config, ) mock_execute_paasta_serviceinit_on_remote_master.assert_called_once_with( 'status', 'fake_cluster', 'fake_service', 'fake_instance_a', system_paasta_config, stream=False, verbose=0, ignore_ssh_output=True, )
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 test_report_status_for_cluster_instance_sorts_in_deploy_order( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master ): # paasta_status with no args displays deploy info service = "fake_service" planned_deployments = ["a_cluster.a_instance", "a_cluster.b_instance"] actual_deployments = {"a_cluster.a_instance": "533976a9", "a_cluster.b_instance": "533976a9"} 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: 533976a9\n" " %s\n" % (PaastaColors.blue("a_instance"), fake_status, PaastaColors.blue("b_instance"), fake_status) ) 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 test_report_status_for_cluster_displays_multiple_lines_from_execute_paasta_serviceinit_on_remote_master( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, system_paasta_config, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['cluster.instance'] actual_deployments = { 'cluster.instance': 'this_is_a_sha', } instance_whitelist: Dict[str, Any] = {} fake_status = 'status: SOMETHING FAKE\nand then something fake\non another line!\n\n\n' mock_execute_paasta_serviceinit_on_remote_master.return_value = ( 0, fake_status, ) expected_output = (" status: SOMETHING FAKE\n" " and then something fake\n" " on another line!\n") _, output = status.report_status_for_cluster( service=service, cluster='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_calls_execute_paasta_serviceinit_on_remote_master( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, verbosity_level, capfd, system_paasta_config, ): service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': 'this_is_a_sha', } instance_whitelist = [] fake_output = "Marathon: 5 instances" mock_execute_paasta_serviceinit_on_remote_master.return_value = ( sentinel.return_value, fake_output, ) expected_output = " %s\n" % fake_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, verbose=verbosity_level, ) assert mock_execute_paasta_serviceinit_on_remote_master.call_count == 1 mock_execute_paasta_serviceinit_on_remote_master.assert_any_call( 'status', 'a_cluster', service, 'a_instance', system_paasta_config, stream=True, verbose=verbosity_level, ignore_ssh_output=True, ) output, _ = capfd.readouterr() assert expected_output in output
def test_report_status_for_cluster_instance_sorts_in_deploy_order( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, capfd, system_paasta_config, ): # paasta_status with no args displays deploy info service = 'fake_service' planned_deployments = [ 'fake_cluster.fake_instance_a', 'fake_cluster.fake_instance_b', ] actual_deployments = { 'fake_cluster.fake_instance_a': '533976a9', 'fake_cluster.fake_instance_b': '533976a9', } 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: fake_cluster\n" " %s\n" % (fake_status)) status.report_status_for_cluster( service=service, cluster='fake_cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=system_paasta_config, ) output, _ = capfd.readouterr() assert expected_output in output mock_execute_paasta_serviceinit_on_remote_master.assert_called_once_with( 'status', 'fake_cluster', 'fake_service', 'fake_instance_a,fake_instance_b', system_paasta_config, stream=True, verbose=0, ignore_ssh_output=True, )
def test_report_status_for_cluster_instance_sorts_in_deploy_order( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status with no args displays deploy info service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': '533976a9', 'a_cluster.b_instance': '533976a9', } instance_whitelist = [] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') 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: 533976a9\n" " %s\n" % ( PaastaColors.blue('a_instance'), fake_status, PaastaColors.blue('b_instance'), fake_status, ) ) 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 test_report_status_calls_report_invalid_whitelist_values( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master ): service = "fake_service" planned_deployments = ["cluster.instance1", "cluster.instance2"] actual_deployments = {} instance_whitelist = [] status.report_status_for_cluster( service=service, cluster="cluster", deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) mock_report_invalid_whitelist_values.assert_called_once_with( instance_whitelist, ["instance1", "instance2"], "instance" )
def test_report_status_for_cluster_obeys_instance_whitelist( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master ): service = "fake_service" planned_deployments = ["cluster.instance1", "cluster.instance2"] actual_deployments = {"cluster.instance1": "sha", "cluster.instance2": "sha"} instance_whitelist = ["instance1"] status.report_status_for_cluster( service=service, cluster="cluster", deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert "instance1" in output assert "instance2" not in output
def test_report_status_for_cluster_instance_sorts_in_deploy_order( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): # paasta_status with no args displays deploy info service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': '533976a9', 'a_cluster.b_instance': '533976a9', } 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: 533976a9\n" " %s\n" % ( PaastaColors.blue('a_instance'), fake_status, PaastaColors.blue('b_instance'), fake_status, ) ) 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 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 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 = ( 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, ) ) 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 test_report_status_for_cluster_displays_multiple_lines_from_execute_paasta_serviceinit_on_remote_master( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master ): # paasta_status with no args displays deploy info - vanilla case service = "fake_service" planned_deployments = ["cluster.instance"] actual_deployments = {"cluster.instance": "this_is_a_sha"} instance_whitelist = [] fake_status = "status: SOMETHING FAKE\nand then something fake\non another line!\n\n\n" mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status expected_output = " status: SOMETHING FAKE\n" " and then something fake\n" " on another line!\n" status.report_status_for_cluster( service=service, cluster="cluster", deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert expected_output in output
def test_report_status_calls_report_invalid_whitelist_values( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): service = 'fake_service' planned_deployments = ['cluster.instance1', 'cluster.instance2'] actual_deployments = {} instance_whitelist = [] status.report_status_for_cluster( service=service, cluster='cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) mock_report_invalid_whitelist_values.assert_called_once_with( instance_whitelist, ['instance1', 'instance2'], 'instance', )
def test_report_status_for_cluster_obeys_instance_whitelist( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, ): service = 'fake_service' planned_deployments = ['cluster.instance1', 'cluster.instance2'] actual_deployments = { 'cluster.instance1': 'sha', 'cluster.instance2': 'sha', } instance_whitelist = ['instance1'] status.report_status_for_cluster( service=service, cluster='cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, ) output = mock_stdout.getvalue() assert 'instance1' in output assert 'instance2' not in output
def test_report_status_calls_report_invalid_whitelist_values( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, system_paasta_config, ): service = 'fake_service' planned_deployments = ['cluster.instance1', 'cluster.instance2'] actual_deployments: Dict[str, str] = {} instance_whitelist: Dict[str, Any] = {} status.report_status_for_cluster( service=service, cluster='cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=system_paasta_config, ) mock_report_invalid_whitelist_values.assert_called_once_with( {}.keys(), ['instance1', 'instance2'], 'instance', )
def test_print_cluster_status_calls_execute_paasta_serviceinit_on_remote_master( mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, verbosity_level, ): service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': 'this_is_a_sha', } instance_whitelist = [] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') fake_output = "Marathon: 5 instances" mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_output expected_output = " %s\n" % fake_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=fake_system_paasta_config, verbose=verbosity_level, ) assert mock_execute_paasta_serviceinit_on_remote_master.call_count == 1 mock_execute_paasta_serviceinit_on_remote_master.assert_any_call( 'status', 'a_cluster', service, 'a_instance', fake_system_paasta_config, stream=True, verbose=verbosity_level, ignore_ssh_output=True ) output = mock_stdout.getvalue() assert expected_output in output
def test_report_status_calls_report_invalid_whitelist_values( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, capfd, ): service = 'fake_service' planned_deployments = ['cluster.instance1', 'cluster.instance2'] actual_deployments = {} instance_whitelist = [] fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config') status.report_status_for_cluster( service=service, cluster='cluster', deploy_pipeline=planned_deployments, actual_deployments=actual_deployments, instance_whitelist=instance_whitelist, system_paasta_config=fake_system_paasta_config, ) mock_report_invalid_whitelist_values.assert_called_once_with( instance_whitelist, ['instance1', 'instance2'], 'instance', )
def test_report_status_for_cluster_displays_deployed_service( mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master, system_paasta_config, ): # paasta_status with no args displays deploy info - vanilla case service = 'fake_service' planned_deployments = ['fake_cluster.fake_instance'] actual_deployments = { 'fake_cluster.fake_instance': 'sha', } instance_whitelist: Dict[str, Any] = {} fake_status = 'status: SOMETHING FAKE' mock_execute_paasta_serviceinit_on_remote_master.return_value = ( 0, fake_status, ) expected_output = ("\n" "cluster: fake_cluster\n" " %s\n" % (fake_status)) _, output = status.report_status_for_cluster( service=service, cluster='fake_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 mock_execute_paasta_serviceinit_on_remote_master.assert_called_once_with( 'status', 'fake_cluster', 'fake_service', 'fake_instance', system_paasta_config, stream=False, verbose=0, ignore_ssh_output=True, )
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: Dict[str, Any] = {} fake_status = 'status: SOMETHING FAKE' mock_execute_paasta_serviceinit_on_remote_master.return_value = ( 0, 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_cluster_status_serviceinit_and_api_method( mock_report_invalid_whitelist_values, mock_paasta_status_on_api_endpoint, mock_execute_paasta_serviceinit_on_remote_master, system_paasta_config, ): service = 'fake_service' planned_deployments = [ 'a_cluster.a_instance', 'a_cluster.b_instance', ] actual_deployments = { 'a_cluster.a_instance': 'this_is_a_sha', } instance_whitelist: Dict[str, Any] = { 'a_instance': None, 'b_instance': None } fake_output = "Marathon: 5 instances" mock_execute_paasta_serviceinit_on_remote_master.return_value = ( 0, fake_output, ) expected_output = " %s\n" % fake_output _, 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, verbose=False, ) assert mock_execute_paasta_serviceinit_on_remote_master.call_count == 1 assert mock_paasta_status_on_api_endpoint.call_count == 0 mock_execute_paasta_serviceinit_on_remote_master.assert_any_call( 'status', 'a_cluster', service, 'a_instance', system_paasta_config, stream=False, verbose=False, ignore_ssh_output=True, ) output = '\n'.join(str(line) for line in output) assert expected_output in output instance_whitelist: Dict[str, Any] = { 'a_instance': None, 'b_instance': KubernetesDeploymentConfig, 'tron_job.tron_action': TronActionConfig, } actual_deployments = { 'a_cluster.a_instance': 'this_is_a_sha', 'a_cluster.b_instance': 'another_sha', } expected_output = " %s\n" % fake_output _, 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, verbose=False, ) assert mock_execute_paasta_serviceinit_on_remote_master.call_count == 2 assert mock_paasta_status_on_api_endpoint.call_count == 2