summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli
diff options
context:
space:
mode:
authorRuben Herold <ruben@puettmann.net>2026-08-05 16:13:56 +0200
committerRuben Herold <ruben@puettmann.net>2026-08-05 16:13:56 +0200
commit4432fcf72ca20be430aa9577eee0446d35a2539b (patch)
tree39f3f99055f79c72c367c7f477938629df2afd0a /smoketest/scripts/cli
parentd42d8ef1976b0ab8d0b498bf7073f8afea8d19e3 (diff)
downloadvyos-1x-4432fcf72ca20be430aa9577eee0446d35a2539b.tar.gz
vyos-1x-4432fcf72ca20be430aa9577eee0446d35a2539b.zip
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
Diffstat (limited to 'smoketest/scripts/cli')
-rwxr-xr-xsmoketest/scripts/cli/test_service_ntp.py46
1 files changed, 28 insertions, 18 deletions
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])