From 4432fcf72ca20be430aa9577eee0446d35a2539b Mon Sep 17 00:00:00 2001 From: Ruben Herold Date: Wed, 5 Aug 2026 16:13:56 +0200 Subject: ntp: T9159: harden smoketest per CodeRabbit feedback - assertRaisesRegex instead of bare assertRaises for the two duplicate- per-family checks and the non-local-address check, so each test verifies it hit the specific validation branch it's meant to, not just that *some* ConfigSessionError fired - wrap the duplicate-address tests' cleanup in try/finally so a failed assertion doesn't leave the dummy interface / source-address behind for subsequent tests to trip over --- smoketest/scripts/cli/test_service_ntp.py | 46 +++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'smoketest/scripts/cli') diff --git a/smoketest/scripts/cli/test_service_ntp.py b/smoketest/scripts/cli/test_service_ntp.py index 06d59d398..03caa73b3 100755 --- a/smoketest/scripts/cli/test_service_ntp.py +++ b/smoketest/scripts/cli/test_service_ntp.py @@ -143,15 +143,21 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): self.cli_set(base_path + ['source-address', '192.0.2.1']) self.cli_set(base_path + ['source-address', '192.0.2.2']) - with self.assertRaises(ConfigSessionError): + try: + with self.assertRaisesRegex( + ConfigSessionError, + 'Only admits one ipv4 value for source-address'): + self.cli_commit() + finally: + # remove the invalid subtree entirely (rather than leaving a + # non-local address configured) so chronyd is left running for + # tearDown -- in a finally block so a failed assertion above + # doesn't leave the dummy interface/source-address behind for + # subsequent tests + self.cli_delete(base_path + ['source-address']) + self.cli_delete(dummy_if_path) self.cli_commit() - # remove the invalid subtree entirely (rather than leaving a - # non-local address configured) so chronyd is left running for tearDown - self.cli_delete(base_path + ['source-address']) - self.cli_delete(dummy_if_path) - self.cli_commit() - def test_source_address_rejects_multiple_ipv6(self): # commit the dummy addresses on their own first, so they are # actually live before NTP's verify() checks is_addr_assigned() -- @@ -164,24 +170,28 @@ class TestSystemNTP(VyOSUnitTestSHIM.TestCase): self.cli_set(base_path + ['source-address', '2001:db8::1']) self.cli_set(base_path + ['source-address', '2001:db8::2']) - with self.assertRaises(ConfigSessionError): + try: + with self.assertRaisesRegex( + ConfigSessionError, + 'Only admits one ipv6 value for source-address'): + self.cli_commit() + finally: + # see the ipv4 test above for why this is in a finally block + self.cli_delete(base_path + ['source-address']) + self.cli_delete(dummy_if_path) self.cli_commit() - # remove the invalid subtree entirely (rather than leaving a - # non-local address configured) so chronyd is left running for tearDown - self.cli_delete(base_path + ['source-address']) - self.cli_delete(dummy_if_path) - self.cli_commit() - def test_source_address_rejects_non_local(self): # source-address must be assigned to a local interface self.cli_set(base_path + ['source-address', '192.0.2.1']) - with self.assertRaises(ConfigSessionError): + try: + with self.assertRaisesRegex(ConfigSessionError, + 'not assigned to any interface'): + self.cli_commit() + finally: + self.cli_delete(base_path + ['source-address']) self.cli_commit() - self.cli_delete(base_path + ['source-address']) - self.cli_commit() - def test_source_interface(self): interface = 'eth0' self.cli_set(base_path + ['source-interface', interface]) -- cgit v1.2.3