]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Allow resetting `setWeightedBalancingFactor()` to zero
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 4 Dec 2024 13:39:56 +0000 (14:39 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 4 Dec 2024 13:39:56 +0000 (14:39 +0100)
Zero is the initial value, but until now it was only possible to pass
a value greater than or equal to 1.0 to `setWeightedBalancingFactor()`
so it was not possible to reset it to the default value.

pdns/dnsdist-lua.cc
regression-tests.dnsdist/test_Routing.py

index 411deb9d050591959264f7ea915de2ad86be3d45..87bd853b4fa73f262ed22434e7ffad3ec7c1c357 100644 (file)
@@ -2138,7 +2138,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
 
   luaCtx.writeFunction("setWeightedBalancingFactor", [](double factor) {
     setLuaSideEffect();
-    if (factor >= 1.0) {
+    if (factor >= 1.0 || factor == 0) {
       g_weightedBalancingFactor = factor;
     }
     else {
index 186cba069217e39ff790e4c0d3ccf754ac0fba0b..f72a2f45d6ebeb317f09e308f1e69dfef776a518 100644 (file)
@@ -645,6 +645,9 @@ class TestRoutingWRandom(DNSDistTest):
     _config_params = ['_testServerPort', '_testServer2Port']
     _config_template = """
     setServerPolicy(wrandom)
+    setWeightedBalancingFactor(1.0)
+    -- this is the default, but let's ensure we can reset it to the initial value
+    setWeightedBalancingFactor(0)
     s1 = newServer{address="127.0.0.1:%s", weight=1}
     s1:setUp()
     s2 = newServer{address="127.0.0.1:%s", weight=2}