コード例 #1
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.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, planned_deployments, actual_deployments, None, False)
コード例 #2
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
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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,
    )