def test_autoscale_marathon_instance():
    fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
        service='fake-service',
        instance='fake-instance',
        cluster='fake-cluster',
        config_dict={'min_instances': 1, 'max_instances': 10},
        branch_dict={},
    )
    with contextlib.nested(
        mock.patch('paasta_tools.autoscaling_lib.set_instances_for_marathon_service', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_service_metrics_provider', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_decision_policy', autospec=True,
                   return_value=mock.Mock(return_value=1)),
        mock.patch.object(marathon_tools.MarathonServiceConfig, 'get_instances', autospec=True, return_value=1),
        mock.patch('paasta_tools.autoscaling_lib._log', autospec=True),
    ) as (
        mock_set_instances_for_marathon_service,
        _,
        _,
        _,
        _,
    ):
        autoscaling_lib.autoscale_marathon_instance(fake_marathon_service_config, [mock.Mock()], [mock.Mock()])
        mock_set_instances_for_marathon_service.assert_called_once_with(
            service='fake-service', instance='fake-instance', instance_count=2)
예제 #2
0
def test_autoscale_marathon_instance():
    fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
        service='fake-service',
        instance='fake-instance',
        cluster='fake-cluster',
        config_dict={'min_instances': 1, 'max_instances': 10},
        branch_dict={},
    )
    with contextlib.nested(
        mock.patch('paasta_tools.autoscaling_lib.set_instances_for_marathon_service', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_service_metrics_provider', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_decision_policy', autospec=True,
                   return_value=mock.Mock(return_value=1)),
        mock.patch.object(marathon_tools.MarathonServiceConfig, 'get_instances', autospec=True, return_value=1),
        mock.patch('paasta_tools.autoscaling_lib._log', autospec=True),
    ) as (
        mock_set_instances_for_marathon_service,
        _,
        _,
        _,
        _,
    ):
        autoscaling_lib.autoscale_marathon_instance(fake_marathon_service_config, [mock.Mock()], [mock.Mock()])
        mock_set_instances_for_marathon_service.assert_called_once_with(
            service='fake-service', instance='fake-instance', instance_count=2)
예제 #3
0
def test_autoscaling_marathon_instance():
    fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
        service='fake-service',
        instance='fake-instance',
        cluster='fake-cluster',
        config_dict={'max_instances': 5, 'min_instances': 1},
        branch_dict={},
    )
    with contextlib.nested(
            mock.patch('paasta_tools.autoscaling_lib.KazooClient', autospec=True,
                       return_value=mock.Mock(get=mock.Mock(side_effect=NoNodeError))),
            mock.patch('paasta_tools.autoscaling_lib.load_system_paasta_config', autospec=True,
                       return_value=mock.Mock(get_zk_hosts=mock.Mock())),
            mock.patch('paasta_tools.autoscaling_lib.get_autoscaling_method', autospec=True,
                       return_value=mock.Mock(return_value=2)),
            mock.patch('paasta_tools.autoscaling_lib.set_instances_for_marathon_service', autospec=True),
    ) as (
        _,
        _,
        _,
        mock_set_instances_for_marathon_service,
    ):
        autoscaling_lib.autoscale_marathon_instance(fake_marathon_service_config)
        mock_set_instances_for_marathon_service.assert_called_once_with(
            service='fake-service',
            instance='fake-instance',
            instance_count=3,
        )
예제 #4
0
def test_autoscale_marathon_instance_aborts_when_task_deploying():
    fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
        service="fake-service",
        instance="fake-instance",
        cluster="fake-cluster",
        config_dict={"min_instances": 1, "max_instances": 10},
        branch_dict={},
    )
    with contextlib.nested(
        mock.patch("paasta_tools.autoscaling_lib.set_instances_for_marathon_service", autospec=True),
        mock.patch("paasta_tools.autoscaling_lib.get_service_metrics_provider", autospec=True),
        mock.patch(
            "paasta_tools.autoscaling_lib.get_decision_policy", autospec=True, return_value=mock.Mock(return_value=1)
        ),
        mock.patch.object(marathon_tools.MarathonServiceConfig, "get_instances", autospec=True, return_value=500),
        mock.patch("paasta_tools.autoscaling_lib._log", autospec=True),
    ) as (mock_set_instances_for_marathon_service, _, _, _, _):
        autoscaling_lib.autoscale_marathon_instance(fake_marathon_service_config, [mock.Mock()], [mock.Mock()])
        assert not mock_set_instances_for_marathon_service.called