@@ -23,7 +23,13 @@ class MockSystemDManager(SystemDManager):
23
23
execution : QemuVM | 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 [QemuVM | None , Process | None ]:
27
+ # aleph-vm-controller@decadecadecadecadecadecadecadecadecadecadecadecadecadecadecadeca.service-controller.json
28
+ if '@' in service :
29
+ vm_hash = service .split ('@' , maxsplit = 1 )[1 ].split ('.' , maxsplit = 1 )[0 ]
30
+ else :
31
+ vm_hash = service
32
+
27
33
config_path = Path (f"{ settings .EXECUTION_ROOT } /{ vm_hash } -controller.json" )
28
34
config = configuration_from_file (config_path )
29
35
self .execution , self .process = await execute_persistent_vm (config )
@@ -33,7 +39,7 @@ def is_service_enabled(self, service: str):
33
39
return self .process is not None
34
40
35
41
def is_service_active (self , service : str ):
36
- return self .process is not None
42
+ return self .process is not None and not self . process . returncode
37
43
38
44
async def stop_and_disable (self , vm_hash : str ):
39
45
if self .process :
@@ -92,34 +98,39 @@ async def test_create_qemu_instance():
92
98
assert vm .vm_id == vm_id
93
99
94
100
await execution .start ()
95
- qemu_execution , process = await mock_systemd_manager .enable_and_start (execution .vm_hash )
101
+ qemu_execution , process = await mock_systemd_manager .enable_and_start (execution .controller_service )
96
102
assert isinstance (qemu_execution , QemuVM )
97
103
assert qemu_execution .qemu_process is not None
98
- qemu_execution , process = await mock_systemd_manager .stop_and_disable (execution .vm_hash )
104
+ await mock_systemd_manager .stop_and_disable (execution .vm_hash )
105
+ await qemu_execution .qemu_process .wait ()
106
+ assert qemu_execution .qemu_process .returncode is not None
99
107
await execution .stop ()
100
- assert qemu_execution is None
101
108
102
109
103
110
@pytest .mark .asyncio
104
- async def test_create_qemu_instance_online ():
111
+ async def test_create_qemu_instance_online (mocker ):
105
112
"""
106
113
Create an instance and check that it start / init / stop properly.
114
+ With network, wait for ping
107
115
"""
108
-
109
- settings .USE_FAKE_INSTANCE_BASE = True
110
- settings .FAKE_INSTANCE_MESSAGE = settings .FAKE_INSTANCE_QEMU_MESSAGE
111
- settings .FAKE_INSTANCE_BASE = settings .FAKE_QEMU_INSTANCE_BASE
112
- settings .ENABLE_CONFIDENTIAL_COMPUTING = False
113
- settings .ALLOW_VM_NETWORKING = True
114
- settings .USE_JAILER = False
116
+ mocker .patch .object (settings , "ALLOW_VM_NETWORKING" , True )
117
+ mocker .patch .object (settings , "USE_FAKE_INSTANCE_BASE" , True )
118
+ mocker .patch .object (settings , "FAKE_INSTANCE_MESSAGE" , settings .FAKE_INSTANCE_QEMU_MESSAGE )
119
+ mocker .patch .object (settings , "FAKE_INSTANCE_BASE" , settings .FAKE_INSTANCE_QEMU_MESSAGE )
120
+ mocker .patch .object (settings , "ENABLE_CONFIDENTIAL_COMPUTING" , False )
121
+ mocker .patch .object (settings , "USE_JAILER" , False )
115
122
116
123
logging .basicConfig (level = logging .DEBUG )
117
124
118
125
# Ensure that the settings are correct and required files present.
119
126
settings .setup ()
120
127
settings .check ()
121
128
if not settings .FAKE_INSTANCE_BASE .exists ():
122
- pytest .xfail ("Test Runtime not setup. run `cd runtimes/instance-rootfs && sudo ./create-debian-12-disk.sh`" )
129
+ pytest .xfail (
130
+ "Test instance disk {} not setup. run `cd runtimes/instance-rootfs && sudo ./create-debian-12-disk.sh` " .format (
131
+ settings .FAKE_QEMU_INSTANCE_BASE
132
+ )
133
+ )
123
134
124
135
# The database is required for the metrics and is currently not optional.
125
136
engine = metrics .setup_engine ()
@@ -130,29 +141,26 @@ async def test_create_qemu_instance_online():
130
141
131
142
mock_systemd_manager = MockSystemDManager ()
132
143
133
- network = (
134
- Network (
135
- vm_ipv4_address_pool_range = settings .IPV4_ADDRESS_POOL ,
136
- vm_network_size = settings .IPV4_NETWORK_PREFIX_LENGTH ,
137
- external_interface = settings .NETWORK_INTERFACE ,
138
- ipv6_allocator = make_ipv6_allocator (
139
- allocation_policy = settings .IPV6_ALLOCATION_POLICY ,
140
- address_pool = settings .IPV6_ADDRESS_POOL ,
141
- subnet_prefix = settings .IPV6_SUBNET_PREFIX ,
142
- ),
143
- use_ndp_proxy = False ,
144
- ipv6_forwarding_enabled = False ,
145
- )
146
- if settings .ALLOW_VM_NETWORKING
147
- else None
144
+ network = Network (
145
+ vm_ipv4_address_pool_range = settings .IPV4_ADDRESS_POOL ,
146
+ vm_network_size = settings .IPV4_NETWORK_PREFIX_LENGTH ,
147
+ external_interface = settings .NETWORK_INTERFACE ,
148
+ ipv6_allocator = make_ipv6_allocator (
149
+ allocation_policy = settings .IPV6_ALLOCATION_POLICY ,
150
+ address_pool = settings .IPV6_ADDRESS_POOL ,
151
+ subnet_prefix = settings .IPV6_SUBNET_PREFIX ,
152
+ ),
153
+ use_ndp_proxy = False ,
154
+ ipv6_forwarding_enabled = False ,
148
155
)
156
+ network .setup ()
149
157
150
158
execution = VmExecution (
151
159
vm_hash = vm_hash ,
152
160
message = message .content ,
153
161
original = message .content ,
154
162
snapshot_manager = None ,
155
- systemd_manager = None ,
163
+ systemd_manager = mock_systemd_manager ,
156
164
persistent = True ,
157
165
)
158
166
@@ -170,10 +178,11 @@ async def test_create_qemu_instance_online():
170
178
assert vm .vm_id == vm_id
171
179
172
180
await execution .start ()
173
- qemu_execution , process = await mock_systemd_manager .enable_and_start ( execution . vm_hash )
181
+ qemu_execution = mock_systemd_manager .execution
174
182
assert isinstance (qemu_execution , QemuVM )
175
183
assert qemu_execution .qemu_process is not None
176
- await execution .wait_for_init ()
184
+ await execution .init_task
185
+ assert execution .init_task .result () is True , "VM failed to start"
177
186
qemu_execution , process = await mock_systemd_manager .stop_and_disable (execution .vm_hash )
178
187
await execution .stop ()
179
188
assert qemu_execution is None
0 commit comments