diff options
| author | Christian Breunig <christian@breunig.cc> | 2025-11-02 09:30:05 +0100 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2025-11-03 21:09:14 +0100 |
| commit | ae6d3437dc3247c396444b7f65eb49a98b0dd800 (patch) | |
| tree | 79b3e008ad916e476c67eea1af327ddcfd67552c /smoketest/scripts/cli | |
| parent | f61656f9a0010498b1778c43a599862e84250b7d (diff) | |
| download | vyos-1x-ae6d3437dc3247c396444b7f65eb49a98b0dd800.tar.gz vyos-1x-ae6d3437dc3247c396444b7f65eb49a98b0dd800.zip | |
container: T7305: fix VRF loss when restarting pods
Container networks are only started when there is at least one active consumer.
If a network is created without any attached containers, it does not need to be
assigned to a VRF yet.
When the last container in a pod is stopped, its associated container network
is removed. Upon container restart, the kernel recreates the network, but the
VRF assignment may be lost in the process.
This change ensures that all container networks are correctly reattached to
their designated VRFs when a pod restarts.
Diffstat (limited to 'smoketest/scripts/cli')
| -rwxr-xr-x | smoketest/scripts/cli/test_container.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/smoketest/scripts/cli/test_container.py b/smoketest/scripts/cli/test_container.py index b41a7dd53..ae85273e8 100755 --- a/smoketest/scripts/cli/test_container.py +++ b/smoketest/scripts/cli/test_container.py @@ -23,6 +23,7 @@ from base_vyostest_shim import VyOSUnitTestSHIM from ipaddress import ip_interface from vyos.configsession import ConfigSessionError +from vyos.utils.network import get_interface_vrf from vyos.utils.process import cmd from vyos.utils.process import process_named_running @@ -51,6 +52,7 @@ class TestContainer(VyOSUnitTestSHIM.TestCase): # ensure we can also run this test on a live system - so lets clean # out the current configuration :) cls.cli_delete(cls, base_path) + cls.cli_delete(cls, ['vrf']) @classmethod def tearDownClass(cls): @@ -133,7 +135,6 @@ class TestContainer(VyOSUnitTestSHIM.TestCase): self.assertEqual(l['Config']['Healthcheck']['Timeout'], 1000000000) self.assertEqual(l['Config']['Healthcheck']['Retries'], 2) - def test_name_server(self): cont_name = 'dns-test' net_name = 'net-test' @@ -517,6 +518,30 @@ class TestContainer(VyOSUnitTestSHIM.TestCase): # We expect the same amount of containers from the API that we started above self.assertEqual(len(container_list), len(tmp)) + def test_network_vrf(self): + cont_name = 'vrf-test50' + net_name = 'vrf-test50' + vrf_name = 'red-15' + + # create temporary VRF for testing + self.cli_set(['vrf', 'name', vrf_name, 'table', '100']) + + self.cli_set(base_path + ['name', cont_name, 'image', busybox_image]) + self.cli_set(base_path + ['name', cont_name, 'network', net_name]) + self.cli_set(base_path + ['network', net_name, 'prefix', '192.168.0.0/24']) + self.cli_set(base_path + ['network', net_name, 'vrf', vrf_name]) + + self.cli_commit() + + tmp = get_interface_vrf(f'pod-{net_name}') + self.assertEqual(tmp, vrf_name) + + # Restart container and validate VRF assignment + self.op_mode(['restart', 'container', cont_name]) + tmp = get_interface_vrf(f'pod-{net_name}') + self.assertEqual(tmp, vrf_name) + + self.cli_delete(['vrf', 'name', vrf_name]) if __name__ == '__main__': unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on()) |
