my-homelab-configs/tests/jeannie/test_registry_storage_mount.py

39 lines
1.5 KiB
Python

"""Storage prerequisites. Run on the Debian deployment host."""
import importlib.util
import json
from pathlib import Path
import unittest
SPEC = importlib.util.spec_from_file_location(
"registry_storage_mount", Path(__file__).resolve().parents[2] / "scripts/registry-storage-reconcile.py"
)
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
class RegistryStorageMountTests(unittest.TestCase):
def mount(self, target, options="rw,relatime"):
return lambda command: json.dumps({"filesystems": [{"target": target, "source": "/dev/example", "options": options}]})
def test_missing_data_mount_cannot_fall_back_to_root(self):
with self.assertRaisesRegex(RuntimeError, "refusing root-filesystem fallback"):
MODULE.require_remote_data_mount(self.mount("/"), "/data")
def test_read_only_data_disk_is_refused(self):
with self.assertRaisesRegex(RuntimeError, "not writable"):
MODULE.require_remote_data_mount(self.mount("/data", "ro,relatime"), "/data")
def test_writable_declared_mount_is_accepted(self):
MODULE.require_remote_data_mount(self.mount("/data"), "/data")
def test_profile_without_separate_mount_requires_no_probe(self):
def unexpected_probe(command):
self.fail("A profile without a declared mount must not require /data to be a separate disk")
MODULE.require_remote_data_mount(unexpected_probe, "")
if __name__ == "__main__":
unittest.main()