def test_http_metrics_provider():
    fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])]

    with mock.patch(
        'paasta_tools.autoscaling.autoscaling_service_lib.get_json_body_from_service',
        autospec=True,
    ) as mock_get_json_body_from_service:
        mock_get_json_body_from_service.return_value = {'utilization': 0.5}
        assert autoscaling_service_lib.http_metrics_provider(
            marathon_service_config=mock.Mock(),
            marathon_tasks=fake_marathon_tasks,
        ) == 0.5
Esempio n. 2
0
def test_http_metrics_provider():
    fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])]

    with mock.patch(
        'paasta_tools.autoscaling.autoscaling_service_lib.get_json_body_from_service',
        autospec=True,
    ) as mock_get_json_body_from_service:
        mock_get_json_body_from_service.return_value = {'utilization': 0.5}
        assert autoscaling_service_lib.http_metrics_provider(
            marathon_service_config=mock.Mock(),
            marathon_tasks=fake_marathon_tasks,
        ) == 0.5
Esempio n. 3
0
def test_http_metrics_provider_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_request_result = mock.Mock(json=mock.Mock(
        return_value='malformed_result'))
    with mock.patch(
            'paasta_tools.autoscaling.autoscaling_service_lib.requests.get',
            autospec=True,
            return_value=mock_request_result):
        with raises(autoscaling_service_lib.MetricsProviderNoDataError):
            autoscaling_service_lib.http_metrics_provider(
                fake_marathon_service_config, fake_marathon_tasks,
                mock.Mock()) == 0.5
Esempio n. 4
0
def test_http_metrics_provider():
    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_request_result = mock.Mock(json=mock.Mock(
        return_value={'utilization': '0.5'}))
    with mock.patch(
            'paasta_tools.autoscaling.autoscaling_service_lib.requests.get',
            autospec=True,
            return_value=mock_request_result):
        assert autoscaling_service_lib.http_metrics_provider(
            fake_marathon_service_config, fake_marathon_tasks,
            mock.Mock()) == 0.5