def test_start_or_stop_bad_refs(mock_list_clusters, mock_list_all_instances, mock_list_remote_refs, mock_get_instance_config, mock_figure_out_service_name, mock_stdout): args = mock.Mock() # To suppress any messages due to Mock making everything truthy args.clusters = 'fake_cluster1,fake_cluster2' args.soa_dir = '/fake/soa/dir' args.instances = 'fake_instance' mock_list_clusters.return_value = ['fake_cluster1', 'fake_cluster2'] mock_figure_out_service_name.return_value = 'fake_service' mock_get_instance_config.return_value = MarathonServiceConfig( cluster='fake_cluster1', instance='fake_instance', service='fake_service', config_dict={}, branch_dict={}, ) mock_list_remote_refs.return_value = { "refs/tags/paasta-deliberatelyinvalidref-20160304T053919-deploy": "70f7245ccf039d778c7e527af04eac00d261d783"} mock_list_all_instances.return_value = {args.instances} assert start_stop_restart.paasta_start_or_stop(args, 'restart') == 1 assert "No branches found for" in mock_stdout.getvalue().decode('utf-8')
def test_start_or_stop_bad_refs(mock_list_clusters, mock_list_all_instances, mock_list_remote_refs, mock_get_instance_config, mock_figure_out_service_name, mock_stdout): args = mock.Mock() # To suppress any messages due to Mock making everything truthy args.clusters = 'fake_cluster1,fake_cluster2' args.soa_dir = '/fake/soa/dir' args.instances = 'fake_instance' mock_list_clusters.return_value = ['fake_cluster1', 'fake_cluster2'] mock_figure_out_service_name.return_value = 'fake_service' mock_get_instance_config.return_value = MarathonServiceConfig( cluster='fake_cluster1', instance='fake_instance', service='fake_service', config_dict={}, branch_dict={}, ) mock_list_remote_refs.return_value = { "refs/tags/paasta-deliberatelyinvalidref-20160304T053919-deploy": "70f7245ccf039d778c7e527af04eac00d261d783" } mock_list_all_instances.return_value = {args.instances} assert start_stop_restart.paasta_start_or_stop(args, 'restart') == 1 assert "No branches found for" in mock_stdout.getvalue()
def test_paasta_start_or_stop( mock_list_clusters, mock_list_all_instances, mock_get_git_url, mock_get_instance_config, mock_instance_config, mock_figure_out_service_name, mock_list_remote_refs, mock_get_latest_deployment_tag, mock_format_timestamp, mock_issue_state_change_for_service, ): args = mock.Mock() args.clusters = 'cluster1,cluster2' args.instances = 'main1,canary' mock_list_clusters.return_value = ['cluster1', 'cluster2'] mock_list_all_instances.return_value = set(args.instances.split(",")) args.soa_dir = '/soa/dir' mock_get_git_url.return_value = 'fake_git_url' mock_figure_out_service_name.return_value = 'fake_service' mock_get_instance_config.return_value = mock_instance_config mock_instance_config.get_deploy_group.return_value = 'some_group' mock_list_remote_refs.return_value = ['not_a_real_tag', 'fake_tag'] mock_get_latest_deployment_tag.return_value = ('not_a_real_tag', None) mock_format_timestamp.return_value = 'not_a_real_timestamp' ret = start_stop_restart.paasta_start_or_stop(args, 'start') c1_get_instance_config_call = mock.call(service='fake_service', cluster='cluster1', instance='main1', soa_dir='/soa/dir', load_deployments=False) c2_get_instance_config_call = mock.call(service='fake_service', cluster='cluster1', instance='canary', soa_dir='/soa/dir', load_deployments=False) c3_get_instance_config_call = mock.call(service='fake_service', cluster='cluster2', instance='main1', soa_dir='/soa/dir', load_deployments=False) c4_get_instance_config_call = mock.call(service='fake_service', cluster='cluster2', instance='canary', soa_dir='/soa/dir', load_deployments=False) mock_get_instance_config.assert_has_calls([ c1_get_instance_config_call, c2_get_instance_config_call, c3_get_instance_config_call, c4_get_instance_config_call ], any_order=True) mock_get_latest_deployment_tag.assert_called_with( ['not_a_real_tag', 'fake_tag'], 'some_group') mock_issue_state_change_for_service.assert_called_with( service_config=mock_instance_config, force_bounce='not_a_real_timestamp', desired_state='start') assert mock_issue_state_change_for_service.call_count == 4 assert (ret == 0)
def test_paasta_start_or_stop( mock_list_clusters, mock_list_all_instances, mock_get_git_url, mock_get_instance_config, mock_instance_config, mock_figure_out_service_name, mock_list_remote_refs, mock_get_latest_deployment_tag, mock_format_timestamp, mock_issue_state_change_for_service, ): args = mock.Mock() args.clusters = 'cluster1,cluster2' args.instances = 'main1,canary' mock_list_clusters.return_value = ['cluster1', 'cluster2'] mock_list_all_instances.return_value = set(args.instances.split(",")) args.soa_dir = '/soa/dir' mock_get_git_url.return_value = 'fake_git_url' mock_figure_out_service_name.return_value = 'fake_service' mock_get_instance_config.return_value = mock_instance_config mock_instance_config.get_deploy_group.return_value = 'some_group' mock_list_remote_refs.return_value = ['not_a_real_tag', 'fake_tag'] mock_get_latest_deployment_tag.return_value = ('not_a_real_tag', None) mock_format_timestamp.return_value = 'not_a_real_timestamp' ret = start_stop_restart.paasta_start_or_stop(args, 'start') c1_get_instance_config_call = mock.call(service='fake_service', cluster='cluster1', instance='main1', soa_dir='/soa/dir', load_deployments=False) c2_get_instance_config_call = mock.call(service='fake_service', cluster='cluster1', instance='canary', soa_dir='/soa/dir', load_deployments=False) c3_get_instance_config_call = mock.call(service='fake_service', cluster='cluster2', instance='main1', soa_dir='/soa/dir', load_deployments=False) c4_get_instance_config_call = mock.call(service='fake_service', cluster='cluster2', instance='canary', soa_dir='/soa/dir', load_deployments=False) mock_get_instance_config.assert_has_calls([c1_get_instance_config_call, c2_get_instance_config_call, c3_get_instance_config_call, c4_get_instance_config_call], any_order=True) mock_get_latest_deployment_tag.assert_called_with(['not_a_real_tag', 'fake_tag'], 'some_group') mock_issue_state_change_for_service.assert_called_with(service_config=mock_instance_config, force_bounce='not_a_real_timestamp', desired_state='start') assert mock_issue_state_change_for_service.call_count == 4 assert(ret == 0)
def test_cluster_throws_exception_for_invalid_cluster_no_instances( mock_list_clusters, mock_stdout, mock_figure_out_service_name): mock_args = mock.Mock() mock_args.soa_dir = '/foo' mock_args.instances = None mock_args.clusters = "fake_cluster_1,fake_cluster_2" mock_list_clusters.return_value = ['fake_cluster_2'] mock_figure_out_service_name.return_value = 'fake_service' assert start_stop_restart.paasta_start_or_stop(mock_args, 'restart') == 1 assert "Invalid cluster name(s) specified: fake_cluster_1" in mock_stdout.getvalue( ) assert "Valid options: fake_cluster_2" in mock_stdout.getvalue()
def test_cluster_throws_exception_for_invalid_cluster_no_instances( mock_list_clusters, mock_stdout, mock_figure_out_service_name): mock_args = mock.Mock() mock_args.soa_dir = '/foo' mock_args.instances = None mock_args.clusters = "fake_cluster_1,fake_cluster_2" mock_list_clusters.return_value = ['fake_cluster_2'] mock_figure_out_service_name.return_value = 'fake_service' assert start_stop_restart.paasta_start_or_stop(mock_args, 'restart') == 1 assert "Invalid cluster name(s) specified: fake_cluster_1" in mock_stdout.getvalue().decode('utf-8') assert "Valid options: fake_cluster_2" in mock_stdout.getvalue().decode('utf-8')
def test_stop_or_start_handls_ls_remote_failures( mock_get_git_url, mock_get_instance_config, mock_figure_out_service_name, mock_list_remote_refs, mock_stdout, ): args = mock.Mock() mock_get_git_url.return_value = 'fake_git_url' mock_figure_out_service_name.return_value = 'fake_service' mock_get_instance_config.return_value = None mock_list_remote_refs.side_effect = remote_git.LSRemoteException assert start_stop_restart.paasta_start_or_stop(args, 'restart') == 1 assert "may be down" in mock_stdout.getvalue()
def test_stop_or_start_handle_ls_remote_failures( mock_get_git_url, mock_get_instance_config, mock_figure_out_service_name, mock_list_remote_refs, mock_stdout, ): args = mock.Mock() args.clusters = 'cluster1' mock_get_git_url.return_value = 'fake_git_url' mock_figure_out_service_name.return_value = 'fake_service' mock_get_instance_config.return_value = None mock_list_remote_refs.side_effect = remote_git.LSRemoteException assert start_stop_restart.paasta_start_or_stop(args, 'restart') == 1 assert "may be down" in mock_stdout.getvalue()
def test_cluster_throws_exception_no_matching_instance_clusters( mock_list_clusters, mock_stdout, mock_figure_out_service_name): mock_args = mock.Mock() mock_args.soa_dir = '/foo' mock_args.clusters = "fake_cluster_1,fake_cluster_2,fake_cluster_3" mock_args.instances = "instance_one,instance_two" # this is called twice: once for each of the instances. # the code should flatten these out to be one list. mock_list_clusters.return_value = ['fake_cluster_1', 'fake_cluster_2'] mock_figure_out_service_name.return_value = 'fake_service' assert start_stop_restart.paasta_start_or_stop(mock_args, 'restart') == 1 assert "Invalid cluster name(s) specified: fake_cluster_3" in mock_stdout.getvalue().decode('utf-8') assert "Valid options: fake_cluster_1 fake_cluster_2" in mock_stdout.getvalue().decode('utf-8')
def test_cluster_throws_exception_no_matching_instance_clusters( mock_list_clusters, mock_stdout, mock_figure_out_service_name): mock_args = mock.Mock() mock_args.soa_dir = '/foo' mock_args.clusters = "fake_cluster_1,fake_cluster_2,fake_cluster_3" mock_args.instances = "instance_one,instance_two" # this is called twice: once for each of the instances. # the code should flatten these out to be one list. mock_list_clusters.return_value = ['fake_cluster_1', 'fake_cluster_2'] mock_figure_out_service_name.return_value = 'fake_service' assert start_stop_restart.paasta_start_or_stop(mock_args, 'restart') == 1 assert "Invalid cluster name(s) specified: fake_cluster_3" in mock_stdout.getvalue( ) assert "Valid options: fake_cluster_1 fake_cluster_2" in mock_stdout.getvalue( )
def test_start_or_stop_bad_refs(mock_list_remote_refs, mock_get_instance_config, mock_figure_out_service_name, mock_stdout): args = mock.Mock() # To suppress any messages due to Mock making everything truthy args.clusters = 'fake_cluster1,fake_cluster2' mock_figure_out_service_name.return_value = 'fake_service' mock_get_instance_config.return_value = MarathonServiceConfig( cluster='fake_cluster1', instance='fake_instance', service='fake_service', config_dict={}, branch_dict={}, ) mock_list_remote_refs.return_value = { "refs/heads/paasta-deliberatelyinvalidref": "70f7245ccf039d778c7e527af04eac00d261d783"} assert start_stop_restart.paasta_start_or_stop(args, 'restart') == 1 assert "No branches found for" in mock_stdout.getvalue()