Ejemplo n.º 1
0
def test_status_pending_pipeline_build_message(
    mock_get_actual_deployments,
    mock_get_deploy_info,
    mock_figure_out_service_name,
    mock_load_system_paasta_config,
    capfd,
):
    # If deployments.json is missing SERVICE, output the appropriate message
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service
    pipeline = [{'instancename': 'cluster.instance'}]
    mock_get_deploy_info.return_value = {'pipeline': pipeline}
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    mock_load_system_paasta_config.return_value = fake_system_paasta_config

    actual_deployments = {}
    mock_get_actual_deployments.return_value = actual_deployments
    expected_output = missing_deployments_message(service)

    args = MagicMock()
    args.service = service
    args.deploy_group = None

    paasta_status(args)
    output, _ = capfd.readouterr()
    assert expected_output in output
Ejemplo n.º 2
0
def test_status_arg_service_not_found(
    mock_guess_service_name,
    mock_validate_service_name,
    mock_load_system_paasta_config,
    mock_list_clusters,
    capfd,
    system_paasta_config,
):
    # paasta_status with no args and non-service directory results in error
    mock_guess_service_name.return_value = 'not_a_service'
    error = NoSuchService('fake_service')
    mock_validate_service_name.side_effect = error
    mock_list_clusters.return_value = ['cluster1']
    mock_load_system_paasta_config.return_value = system_paasta_config
    expected_output = str(error) + "\n"

    args = MagicMock()
    args.service = None
    args.owner = None
    args.clusters = None
    args.instances = None
    args.deploy_group = None
    args.registration = None

    # Fail if exit(1) does not get called
    with raises(SystemExit) as sys_exit:
        paasta_status(args)

    output, _ = capfd.readouterr()
    assert sys_exit.value.code == 1
    assert output == expected_output
Ejemplo n.º 3
0
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_figure_out_service_name,
):
    service = "fake_service"
    mock_figure_out_service_name.return_value = service

    planned_deployments = ["cluster1.instance1", "cluster1.instance2", "cluster2.instance1"]
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {"fake_service:paasta-cluster.instance": "this_is_a_sha"}
    mock_get_actual_deployments.return_value = actual_deployments

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args)
    mock_get_actual_deployments.assert_called_once_with(service)
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster_whitelist=[],
        instance_whitelist=[],
        verbose=0,
    )
Ejemplo n.º 4
0
def test_status_pending_pipeline_build_message(
        mock_get_actual_deployments, mock_get_deploy_info,
        mock_figure_out_service_name, mock_load_system_paasta_config,
        mock_list_services, mock_get_instance_configs_for_service, capfd,
        system_paasta_config,
):
    # If deployments.json is missing SERVICE, output the appropriate message
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service
    mock_list_services.return_value = [service]
    pipeline = [{'instancename': 'cluster.instance'}]
    mock_get_deploy_info.return_value = {'pipeline': pipeline}
    mock_load_system_paasta_config.return_value = system_paasta_config
    mock_instance_config = make_fake_instance_conf('cluster', service, 'instancename')
    mock_get_instance_configs_for_service.return_value = [mock_instance_config]

    actual_deployments = {}
    mock_get_actual_deployments.return_value = actual_deployments
    expected_output = missing_deployments_message(service)

    args = MagicMock()
    args.service = service
    args.deploy_group = None
    args.clusters = None
    args.instances = None
    args.owner = None
    args.soa_dir = utils.DEFAULT_SOA_DIR
    args.registration = None

    paasta_status(args)
    output, _ = capfd.readouterr()
    assert expected_output in output
Ejemplo n.º 5
0
def test_status_calls_sergeants(
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_figure_out_service_name,
    mock_load_system_paasta_config,
    mock_list_services,
    mock_get_instance_configs_for_service,
    system_paasta_config,
):
    service = 'fake_service'
    cluster = 'fake_cluster'
    mock_figure_out_service_name.return_value = service
    mock_list_services.return_value = [service]

    mock_instance_config = make_fake_instance_conf(cluster, service, 'fi')
    mock_instance_config.get_service.return_value = service
    mock_instance_config.get_cluster.return_value = cluster
    mock_get_instance_configs_for_service.return_value = [mock_instance_config]

    planned_deployments = [
        'cluster1.instance1',
        'cluster1.instance2',
        'cluster2.instance1',
    ]
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {
        'fake_service:paasta-cluster.instance': 'this_is_a_sha',
    }
    mock_get_actual_deployments.return_value = actual_deployments
    mock_load_system_paasta_config.return_value = system_paasta_config
    mock_report_status.return_value = 1776, ['dummy', 'output']

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    args.owner = None
    args.deploy_group = None
    args.soa_dir = '/fake/soa/dir'
    args.registration = None
    return_value = paasta_status(args)

    assert return_value == 1776

    mock_get_actual_deployments.assert_called_once_with(
        service, '/fake/soa/dir')
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster=cluster,
        instance_whitelist={'fi': mock_instance_config.__class__},
        system_paasta_config=system_paasta_config,
        verbose=False,
        use_api_endpoint=False,
    )
Ejemplo n.º 6
0
def test_status_arg_service_not_found(mock_stdout, mock_guess_service_name, mock_validate_service_name):
    # paasta_status with no args and non-service directory results in error
    mock_guess_service_name.return_value = "not_a_service"
    error = NoSuchService("fake_service")
    mock_validate_service_name.side_effect = error
    expected_output = str(error) + "\n"

    args = MagicMock()
    args.service = False

    # Fail if exit(1) does not get called
    with raises(SystemExit) as sys_exit:
        paasta_status(args)

    output = mock_stdout.getvalue()
    assert sys_exit.value.code == 1
    assert output == expected_output
Ejemplo n.º 7
0
def test_status_arg_service_not_found(mock_stdout, mock_guess_service_name,
                                      mock_validate_service_name):
    # paasta_status with no args and non-service directory results in error
    mock_guess_service_name.return_value = 'not_a_service'
    error = NoSuchService('fake_service')
    mock_validate_service_name.side_effect = error
    expected_output = str(error) + "\n"

    args = MagicMock()
    args.service = False

    # Fail if exit(1) does not get called
    with raises(SystemExit) as sys_exit:
        paasta_status(args)

    output = mock_stdout.getvalue()
    assert sys_exit.value.code == 1
    assert output == expected_output
Ejemplo n.º 8
0
def test_status_with_registration(
        mock_report_status, mock_load_system_paasta_config, mock_get_actual_deployments,
        mock_figure_out_service_name, mock_list_services,
        mock_get_instance_configs_for_service,
        system_paasta_config,
):
    mock_load_system_paasta_config.return_value = system_paasta_config
    mock_list_services.return_value = ['fakeservice', 'otherservice']
    cluster = 'fake_cluster'
    mock_inst_1 = make_fake_instance_conf(cluster, 'fakeservice', 'instance1', registrations=['fakeservice.main'])
    mock_inst_2 = make_fake_instance_conf(cluster, 'fakeservice', 'instance2', registrations=['fakeservice.not_main'])
    mock_inst_3 = make_fake_instance_conf(
        cluster, 'fakeservice', 'instance3',
        registrations=['fakeservice.also_not_main'],
    )
    mock_inst_4 = make_fake_instance_conf(
        cluster, 'fakeservice', 'instance4',
        registrations=None,
    )
    mock_get_instance_configs_for_service.return_value = [
        mock_inst_1,
        mock_inst_2,
        mock_inst_3,
        mock_inst_4,
    ]

    mock_get_actual_deployments.return_value = {
        'fakeservice.instance1': 'sha1',
        'fakeservice.instance2': 'sha2',
        'fakeservice.instance3': 'sha3',
    }
    mock_report_status.return_value = 0, ['dummy', 'output']

    args = StatusArgs(
        service='fakeservice',
        instances=None,
        clusters=None,
        deploy_group=None,
        owner=None,
        registration='main,not_main',
        soa_dir='/fake/soa/dir',
        verbose=False,
    )
    return_value = paasta_status(args)

    assert return_value == 0
    assert mock_report_status.call_count == 1
    mock_report_status.assert_called_once_with(
        service='fakeservice',
        cluster=cluster,
        deploy_pipeline=ANY,
        actual_deployments=ANY,
        instance_whitelist={'instance1', 'instance2'},
        system_paasta_config=system_paasta_config,
        verbose=args.verbose,
        use_api_endpoint=ANY,
    )
Ejemplo n.º 9
0
def test_status_pending_pipeline_build_message(
    mock_stdout, mock_get_actual_deployments, mock_get_deploy_info, mock_figure_out_service_name
):
    # If deployments.json is missing SERVICE, output the appropriate message
    service = "fake_service"
    mock_figure_out_service_name.return_value = service
    pipeline = [{"instancename": "cluster.instance"}]
    mock_get_deploy_info.return_value = {"pipeline": pipeline}

    actual_deployments = {}
    mock_get_actual_deployments.return_value = actual_deployments
    expected_output = missing_deployments_message(service)

    args = MagicMock()
    args.service = service

    paasta_status(args)
    output = mock_stdout.getvalue()
    assert expected_output in output
Ejemplo n.º 10
0
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_figure_out_service_name,
    mock_load_system_paasta_config,
):
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service

    planned_deployments = [
        'cluster1.instance1', 'cluster1.instance2', 'cluster2.instance1'
    ]
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {
        'fake_service:paasta-cluster.instance': 'this_is_a_sha'
    }
    mock_get_actual_deployments.return_value = actual_deployments
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    mock_load_system_paasta_config.return_value = fake_system_paasta_config

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    args.soa_dir = '/fake/soa/dir'
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args, '/fake/soa/dir')
    mock_get_actual_deployments.assert_called_once_with(
        service, '/fake/soa/dir')
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster_whitelist=[],
        instance_whitelist=[],
        system_paasta_config=fake_system_paasta_config,
        verbose=0,
    )
Ejemplo n.º 11
0
def test_status_pending_pipeline_build_message(
        mock_stdout, mock_get_actual_deployments, mock_get_deploy_info,
        mock_figure_out_service_name):
    # If deployments.json is missing SERVICE, output the appropriate message
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service
    pipeline = [{'instancename': 'cluster.instance'}]
    mock_get_deploy_info.return_value = {'pipeline': pipeline}

    actual_deployments = {}
    mock_get_actual_deployments.return_value = actual_deployments
    expected_output = missing_deployments_message(service)

    args = MagicMock()
    args.service = service

    paasta_status(args)
    output = mock_stdout.getvalue()
    assert expected_output in output
Ejemplo n.º 12
0
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_get_deploy_info,
    mock_figure_out_service_name,
):
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service

    pipeline = [{'instancename': 'cluster.instance'}]
    deploy_info = {'pipeline': pipeline}
    planned_deployments = [
        'cluster1.instance1', 'cluster1.instance2', 'cluster2.instance1'
    ]
    mock_get_deploy_info.return_value = deploy_info
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {
        'fake_service:paasta-cluster.instance': 'this_is_a_sha'
    }
    mock_get_actual_deployments.return_value = actual_deployments

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args)
    mock_get_actual_deployments.assert_called_once_with(service)
    mock_get_deploy_info.assert_called_once_with(service)
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster_whitelist=[],
        instance_whitelist=[],
        verbose=False,
    )
Ejemplo n.º 13
0
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_figure_out_service_name,
    mock_load_system_paasta_config,
):
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service

    planned_deployments = [
        'cluster1.instance1', 'cluster1.instance2', 'cluster2.instance1']
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {
        'fake_service:paasta-cluster.instance': 'this_is_a_sha'
    }
    mock_get_actual_deployments.return_value = actual_deployments
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    mock_load_system_paasta_config.return_value = fake_system_paasta_config

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    args.soa_dir = '/fake/soa/dir'
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args, '/fake/soa/dir')
    mock_get_actual_deployments.assert_called_once_with(service, '/fake/soa/dir')
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster_whitelist=[],
        instance_whitelist=[],
        system_paasta_config=fake_system_paasta_config,
        verbose=0,
    )
Ejemplo n.º 14
0
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_get_deploy_info,
    mock_figure_out_service_name,
):
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service

    pipeline = [{'instancename': 'cluster.instance'}]
    deploy_info = {'pipeline': pipeline}
    planned_deployments = [
        'cluster1.instance1', 'cluster1.instance2', 'cluster2.instance1']
    mock_get_deploy_info.return_value = deploy_info
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {
        'fake_service:paasta-cluster.instance': 'this_is_a_sha'
    }
    mock_get_actual_deployments.return_value = actual_deployments

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args)
    mock_get_actual_deployments.assert_called_once_with(service)
    mock_get_deploy_info.assert_called_once_with(service)
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster_whitelist=[],
        instance_whitelist=[],
        verbose=False,
    )
Ejemplo n.º 15
0
def test_status_pending_pipeline_build_message(
        mock_stdout, mock_get_actual_deployments, mock_get_deploy_info,
        mock_figure_out_service_name, mock_load_system_paasta_config):
    # If deployments.json is missing SERVICE, output the appropriate message
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service
    pipeline = [{'instancename': 'cluster.instance'}]
    mock_get_deploy_info.return_value = {'pipeline': pipeline}
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    mock_load_system_paasta_config.return_value = fake_system_paasta_config

    actual_deployments = {}
    mock_get_actual_deployments.return_value = actual_deployments
    expected_output = missing_deployments_message(service)

    args = MagicMock()
    args.service = service

    paasta_status(args)
    output = mock_stdout.getvalue()
    assert expected_output in output
Ejemplo n.º 16
0
def test_status_with_owner(
    mock_report_status,
    mock_load_system_paasta_config,
    mock_get_actual_deployments,
    mock_figure_out_service_name,
    mock_list_services,
    mock_get_instance_configs_for_service,
    system_paasta_config,
):
    mock_load_system_paasta_config.return_value = system_paasta_config
    mock_list_services.return_value = ['fakeservice', 'otherservice']
    cluster = 'fake_cluster'
    mock_inst_1 = make_fake_instance_conf(cluster,
                                          'fakeservice',
                                          'instance1',
                                          team='faketeam')
    mock_inst_2 = make_fake_instance_conf(cluster,
                                          'otherservice',
                                          'instance3',
                                          team='faketeam')
    mock_get_instance_configs_for_service.return_value = [
        mock_inst_1,
        mock_inst_2,
    ]

    mock_get_actual_deployments.return_value = {
        'fakeservice.instance1': 'sha1',
        'fakeservice.instance2': 'sha2',
        'otherservice.instance3': 'sha3',
        'otherservice.instance1': 'sha4',
    }
    mock_report_status.return_value = 0, ['dummy', 'output']

    args = MagicMock()
    args.service = None
    args.instances = None
    args.clusters = None
    args.deploy_group = None
    args.owner = 'faketeam'
    args.soa_dir = '/fake/soa/dir'
    args.registration = None
    return_value = paasta_status(args)

    assert return_value == 0
    assert mock_report_status.call_count == 2