1
1
import asyncio
2
2
import logging
3
+ import tempfile
3
4
from asyncio .subprocess import Process
4
5
from pathlib import Path
5
6
@@ -53,14 +54,24 @@ async def test_create_qemu_instance(mocker):
53
54
No network.
54
55
We don't actually check that the system ping since there is no network
55
56
"""
57
+ original_linux_path = settings .LINUX_PATH
56
58
mocker .patch .object (settings , "ALLOW_VM_NETWORKING" , False )
57
59
mocker .patch .object (settings , "USE_FAKE_INSTANCE_BASE" , True )
58
60
mocker .patch .object (settings , "FAKE_INSTANCE_MESSAGE" , settings .FAKE_INSTANCE_QEMU_MESSAGE )
59
- mocker .patch .object (settings , "FAKE_INSTANCE_BASE" , settings .FAKE_INSTANCE_QEMU_MESSAGE )
61
+ mocker .patch .object (settings , "FAKE_INSTANCE_BASE" , settings .FAKE_QEMU_INSTANCE_BASE )
60
62
mocker .patch .object (settings , "ENABLE_CONFIDENTIAL_COMPUTING" , False )
61
63
mocker .patch .object (settings , "USE_JAILER" , False )
64
+ tmp_dir = tempfile .TemporaryDirectory (prefix = "alephtest_" )
65
+ tmp_path = Path (tmp_dir .name )
66
+ cache_root = tmp_path / "cache"
67
+ exec_root = tmp_path / "exec"
68
+ mocker .patch .object (settings , "CACHE_ROOT" , cache_root )
69
+ mocker .patch .object (settings , "EXECUTION_ROOT" , exec_root )
70
+ mocker .patch .object (settings , "PERSISTENT_VOLUMES_DIR" , exec_root / "volumes" / "persistent" )
71
+ mocker .patch .object (settings , "JAILER_BASE_DIRECTORY" , exec_root / "jailer" )
72
+ mocker .patch .object (settings , "EXECUTION_LOG_DIRECTORY" , exec_root / "executions" )
62
73
63
- # Patch journal.stream so the output of qemu proecss is shown in the test output
74
+ # Patch journal.stream so the output of qemu process is shown in the test output
64
75
mocker .patch ("aleph.vm.hypervisors.qemu.qemuvm.journal.stream" , return_value = None )
65
76
66
77
if not settings .FAKE_INSTANCE_BASE .exists ():
@@ -69,10 +80,12 @@ async def test_create_qemu_instance(mocker):
69
80
)
70
81
71
82
logging .basicConfig (level = logging .DEBUG )
72
-
83
+ logger = logging . getLogger ( __name__ )
73
84
# Ensure that the settings are correct and required files present.
74
85
settings .setup ()
75
86
settings .check ()
87
+ logger .info (settings .EXECUTION_ROOT )
88
+ logger .info (settings .PERSISTENT_VOLUMES_DIR )
76
89
77
90
# The database is required for the metrics and is currently not optional.
78
91
engine = metrics .setup_engine ()
@@ -110,6 +123,7 @@ async def test_create_qemu_instance(mocker):
110
123
await qemu_execution .qemu_process .wait ()
111
124
assert qemu_execution .qemu_process .returncode is not None
112
125
await execution .stop ()
126
+ settings .LINUX_PATH = original_linux_path
113
127
114
128
115
129
@pytest .mark .asyncio
@@ -118,26 +132,37 @@ async def test_create_qemu_instance_online(mocker):
118
132
Create an instance and check that it start / init / stop properly.
119
133
With network, wait for ping
120
134
"""
135
+ original_linux_path = settings .LINUX_PATH
121
136
mocker .patch .object (settings , "ALLOW_VM_NETWORKING" , True )
122
137
mocker .patch .object (settings , "USE_FAKE_INSTANCE_BASE" , True )
123
138
mocker .patch .object (settings , "FAKE_INSTANCE_MESSAGE" , settings .FAKE_INSTANCE_QEMU_MESSAGE )
124
- mocker .patch .object (settings , "FAKE_INSTANCE_BASE" , settings .FAKE_INSTANCE_QEMU_MESSAGE )
139
+ mocker .patch .object (settings , "FAKE_INSTANCE_BASE" , settings .FAKE_QEMU_INSTANCE_BASE )
125
140
mocker .patch .object (settings , "ENABLE_CONFIDENTIAL_COMPUTING" , False )
126
141
mocker .patch .object (settings , "USE_JAILER" , False )
127
142
143
+ tmp_dir = tempfile .TemporaryDirectory (prefix = "alephtest_" )
144
+ tmp_path = Path (tmp_dir .name )
145
+ cache_root = tmp_path / "cache"
146
+ exec_root = tmp_path / "exec"
147
+ mocker .patch .object (settings , "CACHE_ROOT" , cache_root )
148
+ mocker .patch .object (settings , "EXECUTION_ROOT" , exec_root )
149
+ mocker .patch .object (settings , "PERSISTENT_VOLUMES_DIR" , exec_root / "volumes" / "persistent" )
150
+ mocker .patch .object (settings , "JAILER_BASE_DIRECTORY" , exec_root / "jailer" )
151
+ mocker .patch .object (settings , "EXECUTION_LOG_DIRECTORY" , exec_root / "executions" )
152
+
128
153
# Patch journal.stream so the output of qemu process is shown in the test output
129
154
mocker .patch ("aleph.vm.hypervisors.qemu.qemuvm.journal.stream" , return_value = None )
130
155
131
156
if not settings .FAKE_INSTANCE_BASE .exists ():
132
157
pytest .xfail (
133
- "Test instance disk {} not setup. run `cd runtimes/instance-rootfs && sudo ./create-debian-12-qemu-disk.sh` " .format (
134
- settings .FAKE_QEMU_INSTANCE_BASE
135
- )
158
+ f"Test instance disk { settings .FAKE_QEMU_INSTANCE_BASE } not setup. run `cd runtimes/instance-rootfs && sudo ./create-debian-12-qemu-disk.sh` "
136
159
)
160
+ logger = logging .getLogger (__name__ )
137
161
# Ensure that the settings are correct and required files present.
138
162
settings .setup ()
139
163
settings .check ()
140
-
164
+ logger .info (settings .EXECUTION_ROOT )
165
+ logger .info (settings .PERSISTENT_VOLUMES_DIR )
141
166
# The database is required for the metrics and is currently not optional.
142
167
engine = metrics .setup_engine ()
143
168
await metrics .create_tables (engine )
@@ -192,3 +217,5 @@ async def test_create_qemu_instance_online(mocker):
192
217
qemu_execution , process = await mock_systemd_manager .stop_and_disable (execution .vm_hash )
193
218
await execution .stop ()
194
219
assert qemu_execution is None
220
+
221
+ settings .LINUX_PATH = original_linux_path
0 commit comments