From abad3cedc61432dd18a0f09f7537b68625466185 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 19 Mar 2026 13:15:46 +0100 Subject: [PATCH] confd: actually fix stratum-weight semantics and flaky test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The setting 'stratumweight 0.0' disables stratum in Chrony source selection (pure distance-based), making client_stratum_selection non-deterministic on a LAN. Setting it to 1.0 gives srv1 a 1-second effective advantage per stratum level, which no realistic distance fluctuation can overcome. Also correct the YANG descriptions in infix-system and infix-ntp which had the semantics backwards — claiming 0.0 "ensures lower stratum is always preferred" when in fact higher values do that. Fixes #1361 Signed-off-by: Joachim Wiberg --- src/confd/yang/confd/infix-ntp.yang | 24 ++++++++++++------- src/confd/yang/confd/infix-system.yang | 24 ++++++++++++------- .../case/ntp/client_stratum_selection/test.py | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/confd/yang/confd/infix-ntp.yang b/src/confd/yang/confd/infix-ntp.yang index 19addf89..9a2582b8 100644 --- a/src/confd/yang/confd/infix-ntp.yang +++ b/src/confd/yang/confd/infix-ntp.yang @@ -33,8 +33,10 @@ module infix-ntp { description "Add stratumweight to NTP server configuration. Allows tuning the weight of stratum in NTP source selection - relative to measured distance. Setting to 0.0 ensures lower - stratum sources are always preferred regardless of distance."; + relative to measured distance. Higher values give more preference + to lower-stratum sources; use 1.0 to guarantee stratum-based + selection on local networks. Setting to 0.0 disables stratum + weighting (pure distance-based selection)."; reference "internal"; } @@ -75,13 +77,19 @@ module infix-ntp { description "Weight of stratum in NTP source selection relative to measured distance. - A one-stratum difference counts as this many seconds of additional - distance when comparing candidates. + Each stratum level adds this many seconds of effective distance when + comparing candidates. Higher values give more preference to lower-stratum + sources. - The default (0.001 = 1ms) means stratum only wins when distance - differences are less than 1ms. Setting it to 0.0 ensures that a - lower-stratum source is always preferred over a higher-stratum source, - regardless of their measured distances."; + The default (0.001 = 1ms per stratum level) is suitable for most networks. + On a LAN where all servers have similar round-trip times, a lower-stratum + source wins unless its synchronization distance degrades (e.g., due to + missed polls) by more than this amount. + + Use 1.0 or larger to guarantee stratum-based selection on local networks + regardless of transient distance fluctuations. Setting it to 0.0 disables + stratum weighting; selection is then based purely on measured + synchronization distance."; } container makestep { diff --git a/src/confd/yang/confd/infix-system.yang b/src/confd/yang/confd/infix-system.yang index 16c8de18..3e60a5b8 100644 --- a/src/confd/yang/confd/infix-system.yang +++ b/src/confd/yang/confd/infix-system.yang @@ -32,8 +32,10 @@ module infix-system { description "Add stratumweight to NTP client configuration. Allows tuning the weight of stratum in NTP source selection - relative to measured distance. Setting to 0.0 ensures lower - stratum sources are always preferred regardless of distance."; + relative to measured distance. Higher values give more preference + to lower-stratum sources; use 1.0 to guarantee stratum-based + selection on local networks. Setting to 0.0 disables stratum + weighting (pure distance-based selection)."; reference "internal"; } @@ -327,13 +329,19 @@ module infix-system { description "Weight of stratum in NTP source selection relative to measured distance. - A one-stratum difference counts as this many seconds of additional - distance when comparing candidates. + Each stratum level adds this many seconds of effective distance when + comparing candidates. Higher values give more preference to lower-stratum + sources. - The default (0.001 = 1ms) means stratum only wins when distance - differences are less than 1ms. Setting it to 0.0 ensures that a - lower-stratum source is always preferred over a higher-stratum source, - regardless of their measured distances."; + The default (0.001 = 1ms per stratum level) is suitable for most networks. + On a LAN where all servers have similar round-trip times, a lower-stratum + source wins unless its synchronization distance degrades (e.g., due to + missed polls) by more than this amount. + + Use 1.0 or larger to guarantee stratum-based selection on local networks + regardless of transient distance fluctuations. Setting it to 0.0 disables + stratum weighting; selection is then based purely on measured + synchronization distance."; } } diff --git a/test/case/ntp/client_stratum_selection/test.py b/test/case/ntp/client_stratum_selection/test.py index 073d4a7e..f52be546 100755 --- a/test/case/ntp/client_stratum_selection/test.py +++ b/test/case/ntp/client_stratum_selection/test.py @@ -107,7 +107,7 @@ with infamy.Test() as test: "system": { "ntp": { "enabled": True, - "infix-system:stratum-weight": 0.0, + "infix-system:stratum-weight": 1.0, "server": [{ "name": "srv1", "udp": {