Exemple #1
0
def test_set_boost_factor_with_defaults():
    fake_region = 'westeros-1'
    fake_pool = 'default'
    base_path = cluster_boost.get_zk_boost_path(fake_region, fake_pool)

    with patch_zk_client() as mock_zk_client:
        cluster_boost.set_boost_factor(fake_region, fake_pool)

    expected_end_time = float(TEST_CURRENT_TIME.timestamp()
                              ) + 60 * cluster_boost.DEFAULT_BOOST_DURATION

    assert mock_zk_client.set.call_args_list == [
        mock.call(
            base_path + '/end_time',
            str(expected_end_time).encode('utf-8'),
        ),
        mock.call(
            base_path + '/factor',
            str(cluster_boost.DEFAULT_BOOST_FACTOR).encode('utf-8'),
        ),
        mock.call(
            base_path + '/expected_load',
            '0'.encode('utf-8'),
        ),
    ]
Exemple #2
0
def test_get_boost_values():
    fake_region = 'westeros-1'
    fake_pool = 'default'
    base_path = cluster_boost.get_zk_boost_path(fake_region, fake_pool)

    fake_end_time = 12345.0
    fake_boost_factor = 1.5
    fake_expected_load = 80

    with patch_zk_client({
            base_path + '/end_time':
            str(fake_end_time).encode('utf-8'),
            base_path + '/factor':
            str(fake_boost_factor).encode('utf-8'),
            base_path + '/expected_load':
            str(fake_expected_load).encode('utf-8'),
    }) as mock_zk_client:

        assert cluster_boost.get_boost_values(
            region=fake_region,
            pool=fake_pool,
            zk=mock_zk_client,
        ) == cluster_boost.BoostValues(
            end_time=fake_end_time,
            boost_factor=fake_boost_factor,
            expected_load=fake_expected_load,
        )
Exemple #3
0
def test_set_boost_factor_with_active_boost_override():
    fake_region = 'westeros-1'
    fake_pool = 'default'
    base_path = cluster_boost.get_zk_boost_path(fake_region, fake_pool)

    fake_end_time = float(TEST_CURRENT_TIME.timestamp()) + 10
    fake_boost_factor = 1.5
    fake_expected_load = 80

    mock_boost_values = {
        base_path + '/end_time': str(fake_end_time).encode('utf-8'),
        base_path + '/factor': str(fake_boost_factor).encode('utf-8'),
        base_path + '/expected_load': str(fake_expected_load).encode('utf-8'),
    }

    # patch zk client so that it returns an end time that
    # indicates an active boost
    with patch_zk_client(mock_boost_values) as mock_zk_client:

        # we need the zk.set to actually override the initial mocked values
        def mock_set(key, value):
            mock_boost_values[key] = value

        mock_zk_client.set = mock_set

        # set boost will go through with an active boost if override is toggled on
        assert cluster_boost.set_boost_factor(
            region=fake_region,
            pool=fake_pool,
            override=True,
        )
Exemple #4
0
def test_set_boost_factor_with_active_boost():
    fake_region = 'westeros-1'
    fake_pool = 'default'
    base_path = cluster_boost.get_zk_boost_path(fake_region, fake_pool)

    fake_end_time = float(TEST_CURRENT_TIME.timestamp()) + 10
    fake_boost_factor = 1.5
    fake_expected_load = 80

    # patch zk client so that it returns an end time that
    # indicates an active boost
    with patch_zk_client({
            base_path + '/end_time':
            str(fake_end_time).encode('utf-8'),
            base_path + '/factor':
            str(fake_boost_factor).encode('utf-8'),
            base_path + '/expected_load':
            str(fake_expected_load).encode('utf-8'),
    }):
        # by default, set boost should not go through if there's an active boost
        assert not cluster_boost.set_boost_factor(region=fake_region,
                                                  pool=fake_pool)
Exemple #5
0
def test_get_zk_boost_path():
    fake_region = 'westeros-1'
    fake_pool = 'default'
    expected_result = '/paasta_cluster_autoscaler/westeros-1/default/boost'
    assert cluster_boost.get_zk_boost_path(fake_region,
                                           fake_pool) == expected_result