Beispiel #1
0
    def test_scale_paas_app_much_fewer_instances(self, mock_get_statsd_client,
                                                 mock_paas_client, *args):
        """ We don't scale down more than 1 instance at a time """
        app_guid = '11111-11111-11111111-1111'
        app_name = 'app-name-1'
        cf_info = {'name': app_name, 'instances': 4, 'guid': app_guid}
        app = self._get_mock_app(app_name, cf_info)
        app.get_desired_instance_count = Mock(return_value=1)

        autoscaler = Autoscaler()
        autoscaler.cooldown_seconds_after_scale_up = SCALEUP_COOLDOWN_SECONDS
        autoscaler.cooldown_seconds_after_scale_down = SCALEDOWN_COOLDOWN_SECONDS

        # we scaled down 600 seconds ago, scaled up 325 seconds ago
        autoscaler._set_last_scale(
            'last_scale_down', app_name,
            (self._now() - SCALEDOWN_COOLDOWN_SECONDS * 10))
        autoscaler._set_last_scale('last_scale_up', app_name,
                                   (self._now() -
                                    (SCALEUP_COOLDOWN_SECONDS + 25)))
        autoscaler.scale(app)
        assert float(autoscaler.redis_client.hget('last_scale_down',
                                                  app_name)) == self._now()
        mock_get_statsd_client.return_value.gauge.assert_called_once_with(
            "{}.instance-count".format(app_name), 3)
        mock_paas_client.return_value.update.assert_called_once_with(
            app_guid, 3)
Beispiel #2
0
    def test_scale_paas_app_fewer_instances_recent_scale_down(self, mock_get_statsd_client, mock_paas_client, *args):
        app_guid = '11111-11111-11111111-1111'
        app_name = 'app-name-1'
        cf_info = {'name': app_name, 'instances': 4, 'guid': app_guid}
        app = self._get_mock_app(app_name, cf_info)
        app.get_desired_instance_count = Mock(return_value=3)

        autoscaler = Autoscaler()
        autoscaler.cooldown_seconds_after_scale_up = SCALEUP_COOLDOWN_SECONDS
        autoscaler.cooldown_seconds_after_scale_down = SCALEDOWN_COOLDOWN_SECONDS

        # we scaled up 600 seconds ago, scaled down 30 seconds ago
        autoscaler._set_last_scale('last_scale_down', app_name, (self._now() - 30))
        autoscaler._set_last_scale('last_scale_up', app_name, (self._now() - 600))

        autoscaler.scale(app)
        mock_get_statsd_client.return_value.gauge.assert_called_once_with("{}.instance-count".format(app_name), 4)
        mock_paas_client.return_value.assert_not_called()