예제 #1
0
def test_get_http_utilization_for_all_tasks_no_data():
    fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
        service='fake-service',
        instance='fake-instance',
        cluster='fake-cluster',
        config_dict={},
        branch_dict={},
    )
    fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])]
    mock_json_mapper = mock.Mock(side_effect=KeyError('Detailed message'))  # KeyError simulates an invalid response

    with contextlib.nested(
        mock.patch('paasta_tools.autoscaling.autoscaling_service_lib.log.debug', autospec=True),
        mock.patch('paasta_tools.autoscaling.autoscaling_service_lib.get_json_body_from_service', autospec=True),
    ) as (
        mock_log_debug,
        _,
    ):
        with raises(autoscaling_service_lib.MetricsProviderNoDataError):
            autoscaling_service_lib.get_http_utilization_for_all_tasks(
                fake_marathon_service_config,
                fake_marathon_tasks,
                endpoint='fake-endpoint',
                json_mapper=mock_json_mapper,
            )
        mock_log_debug.assert_called_once_with(
            "Caught excpetion when querying fake-service on fake_host:30101 : 'Detailed message'")
예제 #2
0
def test_get_http_utilization_for_all_tasks_no_data():
    fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
        service='fake-service',
        instance='fake-instance',
        cluster='fake-cluster',
        config_dict={},
        branch_dict={},
    )
    fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])]
    mock_json_mapper = mock.Mock(side_effect=KeyError('Detailed message'))  # KeyError simulates an invalid response

    with contextlib.nested(
        mock.patch('paasta_tools.autoscaling.autoscaling_service_lib.log.debug', autospec=True),
        mock.patch('paasta_tools.autoscaling.autoscaling_service_lib.get_json_body_from_service', autospec=True),
    ) as (
        mock_log_debug,
        _,
    ):
        with raises(autoscaling_service_lib.MetricsProviderNoDataError):
            autoscaling_service_lib.get_http_utilization_for_all_tasks(
                fake_marathon_service_config,
                fake_marathon_tasks,
                endpoint='fake-endpoint',
                json_mapper=mock_json_mapper,
            )
        mock_log_debug.assert_called_once_with(
            "Caught excpetion when querying fake-service on fake_host:30101 : 'Detailed message'")
예제 #3
0
def test_get_http_utilization_for_all_tasks_timeout():
    fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])]
    mock_json_mapper = mock.Mock(side_effect=Timeout)

    with mock.patch('paasta_tools.autoscaling.autoscaling_service_lib.get_json_body_from_service', autospec=True):
        assert autoscaling_service_lib.get_http_utilization_for_all_tasks(
            marathon_service_config=mock.Mock(),
            marathon_tasks=fake_marathon_tasks,
            endpoint='fake-endpoint',
            json_mapper=mock_json_mapper,
        ) == 1.0
예제 #4
0
def test_get_http_utilization_for_all_tasks_timeout():
    fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])]
    mock_json_mapper = mock.Mock(side_effect=Timeout)

    with mock.patch('paasta_tools.autoscaling.autoscaling_service_lib.get_json_body_from_service', autospec=True):
        assert autoscaling_service_lib.get_http_utilization_for_all_tasks(
            marathon_service_config=mock.Mock(),
            marathon_tasks=fake_marathon_tasks,
            endpoint='fake-endpoint',
            json_mapper=mock_json_mapper,
        ) == 1.0