summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-10-07 19:56:47 +0200
committerChristian Breunig <christian@breunig.cc>2026-10-31 09:58:29 +0000
commit0b9903a85ccbef75b653a4d4349db5710ee9638d (patch)
treefe853124478847d772207e316a3bb0eb086d65d7 /src/tests
parent724c38de924caab6cb3e2c0b57173ef0742ffa40 (diff)
downloadvyos-1x-0b9903a85ccbef75b653a4d4349db5710ee9638d.tar.gz
vyos-1x-0b9903a85ccbef75b653a4d4349db5710ee9638d.zip
interfaces: T3871: persist interface names on the first boot of a pre-built image
The check guarding that write looked for a marker which an activation script creates only after interface naming has already run. On a deployed qcow2 the marker is absent on the first boot, so nothing was recorded and the next boot named the hardware from scratch. Removing a card then moved every name below it onto the neighbouring port, taking that interface's address with it. Only an encrypted configuration has a volume which may still be locked, so ask about that instead - everywhere else the directory is already the persistent one.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_ifname_store.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/tests/test_ifname_store.py b/src/tests/test_ifname_store.py
index 3f12594d4..7f6aa7852 100644
--- a/src/tests/test_ifname_store.py
+++ b/src/tests/test_ifname_store.py
@@ -29,6 +29,7 @@ from unittest import mock
from vyos.ifconfig.ifname_store import STORE_VERSION
from vyos.ifconfig.ifname_store import canonical_sort_key
+from vyos.ifconfig.ifname_store import config_dir_is_mounted
from vyos.ifconfig.ifname_store import device_matches
from vyos.ifconfig.ifname_store import ambiguous_keys
from vyos.ifconfig.ifname_store import hardware_key
@@ -136,8 +137,7 @@ class TestReplacedHardware(unittest.TestCase):
class TestStoreIO(unittest.TestCase):
@staticmethod
def _config_dir(d):
- """A directory that looks like a properly mounted config volume."""
- (Path(d) / '.vyatta_config').touch()
+ """An ordinary, unencrypted config directory - the common case."""
return Path(d) / 'interface-mapping.json'
def test_roundtrip(self):
@@ -147,14 +147,37 @@ class TestStoreIO(unittest.TestCase):
self.assertTrue(save_store(s, p))
self.assertEqual(load_store(p), s)
- def test_refuses_to_write_when_config_volume_is_not_mounted(self):
+ def test_refuses_to_write_when_the_encrypted_volume_is_not_mounted(self):
# TPM/LUKS unlock failed: vyos-router continues, but persisting here
# would write a shadow store that the real volume masks later
- with tempfile.TemporaryDirectory() as d:
- p = Path(d) / 'interface-mapping.json' # no .vyatta_config marker
+ with tempfile.TemporaryDirectory() as d, \
+ mock.patch('vyos.ifconfig.ifname_store.encrypted_config_volume',
+ return_value=True):
+ p = Path(d) / 'interface-mapping.json' # a plain dir, not a mount
self.assertFalse(save_store(store_of({'eth0': 'x'}), p))
self.assertFalse(p.exists())
+ def test_writes_on_the_first_boot_of_a_prebuilt_image(self):
+ # T3871: the check used to key on '.vyatta_config', which an
+ # activation script writes only AFTER interface naming has run. On a
+ # qcow2 that marker is absent on the first boot, so no store was ever
+ # written and the next boot named the hardware from scratch - pull a
+ # card and every name below it moved onto the wrong port.
+ with tempfile.TemporaryDirectory() as d:
+ p = Path(d) / 'interface-mapping.json'
+ self.assertFalse((Path(d) / '.vyatta_config').exists())
+ self.assertTrue(save_store(store_of({'eth0': 'pci-0000:00:12.0'}), p))
+ self.assertTrue(p.exists())
+
+ def test_unencrypted_config_needs_no_mount_point(self):
+ # the config directory of an ordinary install is not a mount of its
+ # own - only an encrypted one is
+ with tempfile.TemporaryDirectory() as d, \
+ mock.patch('vyos.ifconfig.ifname_store.encrypted_config_volume',
+ return_value=False):
+ self.assertTrue(config_dir_is_mounted(
+ Path(d) / 'interface-mapping.json'))
+
def test_missing_file_is_empty_store(self):
with tempfile.TemporaryDirectory() as d:
self.assertEqual(load_store(Path(d) / 'nope.json'), empty_store())
@@ -170,7 +193,7 @@ class TestStoreIO(unittest.TestCase):
p = self._config_dir(d)
save_store(store_of({'eth0': 'pci-0000:00:12.0'}), p)
self.assertEqual(sorted(f.name for f in Path(d).iterdir()),
- ['.vyatta_config', 'interface-mapping.json'])
+ ['interface-mapping.json'])
def final_names(report):