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

29 lines
1.1 KiB
Python

"""Checks for the host-side storage precondition."""
import importlib.util
import unittest
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[2]
spec = importlib.util.spec_from_file_location('sandbox_host', ROOT / 'scripts/network-sandbox-host.py')
host = importlib.util.module_from_spec(spec)
spec.loader.exec_module(host)
class SandboxHostTests(unittest.TestCase):
def test_expected_writable_ssd_is_accepted(self):
with patch.object(host, 'run', side_effect=[host.EXPECTED_UUID, 'rw,relatime']), \
patch.object(Path, 'is_symlink', return_value=False):
host.verify_data()
def test_wrong_or_readonly_filesystem_is_rejected(self):
for uuid, options in [('other', 'rw,relatime'), (host.EXPECTED_UUID, 'ro,relatime')]:
with self.subTest(uuid=uuid, options=options), \
patch.object(host, 'run', side_effect=[uuid, options]):
with self.assertRaises(RuntimeError):
host.verify_data()
if __name__ == '__main__':
unittest.main()