From: Josh Durgin Date: Sun, 2 Feb 2020 21:29:13 +0000 (-0500) Subject: mgr/pg_autoscaler: add unit tests for effective_target_ratio X-Git-Tag: v15.1.1~489^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F33035%2Fhead;p=ceph.git mgr/pg_autoscaler: add unit tests for effective_target_ratio Signed-off-by: Josh Durgin --- diff --git a/src/pybind/mgr/pg_autoscaler/__init__.py b/src/pybind/mgr/pg_autoscaler/__init__.py index e7c7b8fc01bc..f0bffcdcd629 100644 --- a/src/pybind/mgr/pg_autoscaler/__init__.py +++ b/src/pybind/mgr/pg_autoscaler/__init__.py @@ -1 +1 @@ -from .module import PgAutoscaler +from .module import PgAutoscaler, effective_target_ratio diff --git a/src/pybind/mgr/pg_autoscaler/tests/test_autoscaler.py b/src/pybind/mgr/pg_autoscaler/tests/test_autoscaler.py new file mode 100644 index 000000000000..122d95274d07 --- /dev/null +++ b/src/pybind/mgr/pg_autoscaler/tests/test_autoscaler.py @@ -0,0 +1,34 @@ +from pg_autoscaler import effective_target_ratio +from pytest import approx + +def check_simple_ratio(target_ratio, tot_ratio): + etr = effective_target_ratio(target_ratio, tot_ratio, 0, 0) + assert (target_ratio / tot_ratio) == approx(etr) + return etr + +def test_simple(): + etr1 = check_simple_ratio(0.2, 0.9) + etr2 = check_simple_ratio(2, 9) + etr3 = check_simple_ratio(20, 90) + assert etr1 == approx(etr2) + assert etr1 == approx(etr3) + + etr = check_simple_ratio(0.9, 0.9) + assert etr == approx(1.0) + etr1 = check_simple_ratio(1, 2) + etr2 = check_simple_ratio(0.5, 1.0) + assert etr1 == approx(etr2) + +def test_total_bytes(): + etr = effective_target_ratio(1, 10, 5, 10) + assert etr == approx(0.05) + etr = effective_target_ratio(0.1, 1, 5, 10) + assert etr == approx(0.05) + etr = effective_target_ratio(1, 1, 5, 10) + assert etr == approx(0.5) + etr = effective_target_ratio(1, 1, 0, 10) + assert etr == approx(1.0) + etr = effective_target_ratio(0, 1, 5, 10) + assert etr == approx(0.0) + etr = effective_target_ratio(1, 1, 10, 10) + assert etr == approx(0.0) diff --git a/src/pybind/mgr/requirements.txt b/src/pybind/mgr/requirements.txt index 21a5b35af45f..f14efb8cd80d 100644 --- a/src/pybind/mgr/requirements.txt +++ b/src/pybind/mgr/requirements.txt @@ -4,4 +4,5 @@ ipaddress; python_version < '3.3' ../../python-common kubernetes requests-mock -pyyaml \ No newline at end of file +pyyaml +prettytable diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index ac3424e87cb1..d9ea1ef5fd05 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -5,7 +5,7 @@ skipsdist = true [testenv] setenv = UNITTEST = true deps = -r requirements.txt -commands = pytest -v --cov --cov-append --cov-report=term --doctest-modules {posargs:mgr_util.py tests/ cephadm/ progress/} +commands = pytest -v --cov --cov-append --cov-report=term --doctest-modules {posargs:mgr_util.py tests/ cephadm/ pg_autoscaler/ progress/} [testenv:mypy] basepython = python3