summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2025-11-06 20:52:05 +0100
committerGitHub <noreply@github.com>2025-11-06 20:52:05 +0100
commit71591b72493da9fa55e41e1b7c175ec95d8addf9 (patch)
treefb0180db68ce76cda4f41c95de9f4b9fc926b8f4 /python
parentc21b0669b13d8ecbaf33d63d47737d83f08a047d (diff)
parent354517677fb9eceb82e478f33a7c481c469b248a (diff)
downloadvyos-1x-71591b72493da9fa55e41e1b7c175ec95d8addf9.tar.gz
vyos-1x-71591b72493da9fa55e41e1b7c175ec95d8addf9.zip
Merge pull request #4823 from l0crian1/fix-wlb-multi-int
wlb: T7977: Fix weight calculation for multiple interfaces
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/misc.py29
-rw-r--r--python/vyos/wanloadbalance.py2
2 files changed, 30 insertions, 1 deletions
diff --git a/python/vyos/utils/misc.py b/python/vyos/utils/misc.py
index c7f7e7343..20e3de746 100644
--- a/python/vyos/utils/misc.py
+++ b/python/vyos/utils/misc.py
@@ -12,6 +12,9 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+import time
+
+from typing import Callable, Any
def begin(*args):
"""
@@ -64,3 +67,29 @@ def install_into_config(conf, config_paths, override_prompt=True):
if count > 0:
print(f'{count} value(s) installed. Use "compare" to see the pending changes, and "commit" to apply.')
+
+def wait_for(
+ func: Callable[..., Any],
+ *args,
+ interval: float = 1.0,
+ timeout: float = 5.0,
+ **kwargs
+) -> bool:
+ """
+ Repeatedly calls `func()` until it returns True or the timeout expires.
+
+ Args:
+ func: A function with no arguments that returns a truthy value when ready.
+ interval: Seconds to wait between calls (default: 1.0).
+ timeout: Maximum time to wait in seconds (default: 5.0).
+
+ Returns:
+ True if the function returned True within the timeout, otherwise False.
+ """
+ start = time.monotonic()
+ while True:
+ if func(*args, **kwargs):
+ return True
+ if (time.monotonic() - start) >= timeout:
+ return False
+ time.sleep(interval)
diff --git a/python/vyos/wanloadbalance.py b/python/vyos/wanloadbalance.py
index afe005731..05ae6b536 100644
--- a/python/vyos/wanloadbalance.py
+++ b/python/vyos/wanloadbalance.py
@@ -154,7 +154,7 @@ def wlb_weight_interfaces(rule_conf, health_state):
for ifname, weight in sorted(interfaces, key=lambda i: i[1]): # build weight ranges
end = start + weight - 1
out.append((ifname, f'{start}-{end}' if end > start else start))
- start = weight
+ start += weight
return out, total_weight