@@ -23,7 +23,9 @@ class MockSystemDManager(SystemDManager):
23
23
execution : MicroVM | None = None
24
24
process : Process | None = None
25
25
26
- async def enable_and_start (self , vm_hash : str ):
26
+ async def enable_and_start (self , service : str ) -> tuple [MicroVM , Process ]:
27
+ vm_hash = service .split ("@" , maxsplit = 1 )[1 ].split ("." , maxsplit = 1 )[0 ]
28
+
27
29
config_path = Path (f"{ settings .EXECUTION_ROOT } /{ vm_hash } -controller.json" )
28
30
config = configuration_from_file (config_path )
29
31
self .execution , self .process = await execute_persistent_vm (config )
@@ -35,7 +37,7 @@ def is_service_enabled(self, service: str):
35
37
def is_service_active (self , service : str ):
36
38
return self .process is not None
37
39
38
- async def stop_and_disable (self , vm_hash : str ):
40
+ async def stop_and_disable (self , service : str ):
39
41
if self .execution :
40
42
await self .execution .shutdown ()
41
43
await self .execution .stop ()
@@ -45,25 +47,31 @@ async def stop_and_disable(self, vm_hash: str):
45
47
46
48
47
49
@pytest .mark .asyncio
48
- async def test_create_instance ():
49
- """
50
- Create a fake instance locally and check that it start / init / stop properly.
50
+ async def test_create_firecracker_instance (mocker ):
51
+ """Create a fake instance locally and check that it start / init / stop properly.
52
+
53
+ NOTE: If Firecracker VM fail to boot because the disk is broken try:
54
+ ```bash
55
+ sudo dmsetup remove decadecadecadecadecadecadecadecadecadecadecadecadecadecadecadeca_rootfs
56
+ sudo dmsetup remove decadecadecadecadecadecadecadecadecadecadecadecadecadecadecadeca_base
57
+ sudo losetup -l | grep 'persistent' | grep deleted | awk '{print $1}' | sudo xargs -I{} losetup -d {}
58
+ sudo rm -rf /var/lib/aleph/vm/volumes/persistent/decadecadecadecadecadecadecadecadecadecadecadecadecadecadecadeca/rootfs.btrfs
59
+ ```
51
60
"""
61
+ mocker .patch .object (settings , "ALLOW_VM_NETWORKING" , True )
62
+ mocker .patch .object (settings , "USE_FAKE_INSTANCE_BASE" , True )
63
+ mocker .patch .object (settings , "FAKE_DATA_PROGRAM" , settings .BENCHMARK_FAKE_DATA_PROGRAM )
64
+ mocker .patch .object (settings , "USE_JAILER" , True )
52
65
53
- settings .USE_FAKE_INSTANCE_BASE = True
54
- settings .FAKE_DATA_PROGRAM = settings .BENCHMARK_FAKE_DATA_PROGRAM
55
- # settings.FAKE_INSTANCE_MESSAGE
56
- settings .ALLOW_VM_NETWORKING = True
57
- settings .USE_JAILER = True
58
-
59
- logging .basicConfig (level = logging .DEBUG )
60
- settings .PRINT_SYSTEM_LOGS = True
66
+ # logging.basicConfig(level=logging.DEBUG)
61
67
62
68
# Ensure that the settings are correct and required files present.
63
69
settings .setup ()
64
70
settings .check ()
65
71
if not settings .FAKE_INSTANCE_BASE .exists ():
66
- pytest .xfail ("Test Runtime not setup. run `cd runtimes/instance-rootfs && sudo ./create-debian-12-disk.sh`" )
72
+ pytest .xfail (
73
+ f"Test Runtime not setup. { settings .FAKE_INSTANCE_BASE } . run `cd runtimes/instance-rootfs && sudo ./create-debian-12-disk.sh`"
74
+ )
67
75
68
76
# The database is required for the metrics and is currently not optional.
69
77
engine = metrics .setup_engine ()
@@ -93,7 +101,7 @@ async def test_create_instance():
93
101
message = message .content ,
94
102
original = message .content ,
95
103
snapshot_manager = None ,
96
- systemd_manager = None ,
104
+ systemd_manager = mock_systemd_manager ,
97
105
persistent = True ,
98
106
)
99
107
@@ -114,13 +122,17 @@ async def test_create_instance():
114
122
assert vm .enable_networking
115
123
116
124
await execution .start ()
117
- firecracker_execution , process = await mock_systemd_manager .enable_and_start (execution .vm_hash )
125
+ # firecracker_execution, process = await mock_systemd_manager.enable_and_start(execution.vm_hash)
126
+ firecracker_execution = mock_systemd_manager .execution
118
127
assert isinstance (firecracker_execution , MicroVM )
119
128
assert firecracker_execution .proc is not None
120
- await execution .wait_for_persistent_boot ()
121
129
122
- # This sleep is to leave the instance to boot up and prevent disk corruption
130
+ await execution .init_task
131
+ assert execution .init_task .result () is True , "VM failed to start"
132
+
133
+ # This sleep is to leave the instance to boo
134
+ # up and prevent disk corruption
123
135
await asyncio .sleep (60 )
124
- firecracker_execution , process = await mock_systemd_manager .stop_and_disable (execution .vm_hash )
136
+ firecracker_execution , process = await mock_systemd_manager .stop_and_disable (execution .controller_service )
125
137
await execution .stop ()
126
138
assert firecracker_execution is None
0 commit comments