feat: add host-backed entropy device support and update kernel configuration
This commit is contained in:
@@ -3,9 +3,11 @@ from __future__ import annotations
|
||||
import unittest
|
||||
from ipaddress import IPv4Address, IPv4Network
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from uvm.config import Settings
|
||||
from uvm.domain import VmRecord
|
||||
from uvm.errors import FirecrackerError
|
||||
from uvm.firecracker.api import FirecrackerClient
|
||||
from uvm.firecracker.config import build_config, vcpu_count
|
||||
|
||||
@@ -45,6 +47,10 @@ class FirecrackerConfigTests(unittest.TestCase):
|
||||
self.assertEqual("keep_bootcon" in arguments, architecture != "x86_64")
|
||||
self.assertIn("console=ttyS0", arguments)
|
||||
self.assertIn("ip=10.42.0.2::10.42.0.1:255.255.255.0::eth0:off", arguments)
|
||||
client = RecordingFirecrackerClient()
|
||||
client.configure_and_start(config)
|
||||
self.assertEqual(client.calls[-2], ("PUT", "/entropy", {}))
|
||||
self.assertEqual(client.calls[-1], ("PUT", "/actions", {"action_type": "InstanceStart"}))
|
||||
|
||||
def test_builds_a_writable_vm_disk_configuration(self) -> None:
|
||||
vm = VmRecord(
|
||||
@@ -101,6 +107,7 @@ class FirecrackerConfigTests(unittest.TestCase):
|
||||
"/boot-source",
|
||||
"/drives/rootfs",
|
||||
"/network-interfaces/eth0",
|
||||
"/entropy",
|
||||
"/actions",
|
||||
],
|
||||
)
|
||||
@@ -110,6 +117,36 @@ class FirecrackerConfigTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(client.calls[-1][2], {"action_type": "InstanceStart"})
|
||||
|
||||
def test_entropy_failure_prevents_guest_boot(self) -> None:
|
||||
config = {
|
||||
"machine-config": {"vcpu_count": 1, "mem_size_mib": 512},
|
||||
"boot-source": {},
|
||||
"drives": [{}],
|
||||
"network-interfaces": [{}],
|
||||
"entropy": {},
|
||||
}
|
||||
client = RecordingFirecrackerClient()
|
||||
|
||||
def request(method: str, path: str, body: object) -> None:
|
||||
client.calls.append((method, path, body))
|
||||
if path == "/entropy":
|
||||
raise FirecrackerError("entropy device unavailable")
|
||||
|
||||
with patch.object(client, "_request", side_effect=request):
|
||||
with self.assertRaisesRegex(FirecrackerError, "entropy device unavailable"):
|
||||
client.configure_and_start(config)
|
||||
|
||||
self.assertEqual(client.calls[-1], ("PUT", "/entropy", {}))
|
||||
self.assertNotIn("/actions", [path for _method, path, _body in client.calls])
|
||||
|
||||
for entropy in (None, [], False):
|
||||
with self.subTest(entropy=entropy):
|
||||
client.calls.clear()
|
||||
config["entropy"] = entropy
|
||||
with self.assertRaisesRegex(FirecrackerError, "no valid entropy device"):
|
||||
client.configure_and_start(config)
|
||||
self.assertEqual(client.calls, [])
|
||||
|
||||
def test_uses_the_configured_network_netmask_in_guest_boot_arguments(self) -> None:
|
||||
settings = Settings(
|
||||
network=IPv4Network("10.50.0.0/16"),
|
||||
|
||||
Reference in New Issue
Block a user