8
8
import tempfile
9
9
from pathlib import Path
10
10
11
+ import pytest
12
+
11
13
from conftest import _test_images_s3_bucket
12
14
from framework .artifacts import ArtifactCollection , ArtifactSet
13
15
from framework .builder import MicrovmBuilder , SnapshotBuilder , SnapshotType
@@ -40,38 +42,59 @@ def _get_guest_drive_size(ssh_connection, guest_dev_name="/dev/vdb"):
40
42
return stdout .readline ().strip ()
41
43
42
44
43
- def _test_seq_snapshots (context ):
44
- logger = context .custom ["logger" ]
45
- seq_len = context .custom ["seq_len" ]
46
- vm_builder = context .custom ["builder" ]
47
- snapshot_type = context .custom ["snapshot_type" ]
45
+ ARTIFACTS = ArtifactCollection (_test_images_s3_bucket ())
46
+
47
+ # Testing matrix:
48
+ # - Guest kernel: All supported ones
49
+ # - Rootfs: Ubuntu 18.04
50
+ # - Microvm: 2vCPU with 512 MB RAM
51
+ # TODO: Multiple microvm sizes must be tested in the async pipeline.
52
+ @pytest .mark .parametrize (
53
+ "microvm" , ARTIFACTS .microvms (keyword = "2vcpu_512mb" ), ids = lambda x : x .name ()
54
+ )
55
+ @pytest .mark .parametrize ("kernel" , ARTIFACTS .kernels (), ids = lambda x : x .name ())
56
+ @pytest .mark .parametrize (
57
+ "disk" , ARTIFACTS .disks (keyword = "ubuntu" ), ids = lambda x : x .name ()
58
+ )
59
+ @pytest .mark .parametrize ("snapshot_type" , [SnapshotType .DIFF , SnapshotType .FULL ])
60
+ def test_5_snapshots (
61
+ bin_cloner_path ,
62
+ bin_vsock_path ,
63
+ test_fc_session_root_path ,
64
+ microvm ,
65
+ kernel ,
66
+ disk ,
67
+ snapshot_type ,
68
+ ):
69
+ """
70
+ Create and load 5 snapshots.
71
+
72
+ @type: functional
73
+ """
74
+ logger = logging .getLogger ("snapshot_sequence" )
75
+
76
+ vm_builder = MicrovmBuilder (bin_cloner_path )
77
+ seq_len = 5
48
78
diff_snapshots = snapshot_type == SnapshotType .DIFF
49
79
50
- logger .info (
51
- 'Testing {} with microvm: "{}", kernel {}, disk {} ' .format (
52
- snapshot_type ,
53
- context .microvm .name (),
54
- context .kernel .name (),
55
- context .disk .name (),
56
- )
57
- )
80
+ disk .download ()
81
+ kernel .download ()
82
+ microvm .download ()
58
83
59
84
# Create a rw copy artifact.
60
- root_disk = context . disk .copy ()
85
+ root_disk = disk .copy ()
61
86
# Get ssh key from read-only artifact.
62
- ssh_key = context . disk .ssh_key ()
87
+ ssh_key = disk .ssh_key ()
63
88
# Create a fresh microvm from artifacts.
64
89
vm_instance = vm_builder .build (
65
- kernel = context . kernel ,
90
+ kernel = kernel ,
66
91
disks = [root_disk ],
67
92
ssh_key = ssh_key ,
68
- config = context . microvm ,
93
+ config = microvm ,
69
94
diff_snapshots = diff_snapshots ,
70
95
)
71
96
basevm = vm_instance .vm
72
- basevm .vsock .put (
73
- vsock_id = "vsock0" , guest_cid = 3 , uds_path = "/{}" .format (VSOCK_UDS_PATH )
74
- )
97
+ basevm .vsock .put (vsock_id = "vsock0" , guest_cid = 3 , uds_path = f"/{ VSOCK_UDS_PATH } " )
75
98
76
99
basevm .start ()
77
100
ssh_connection = net_tools .SSHConnection (basevm .ssh_config )
@@ -80,15 +103,13 @@ def _test_seq_snapshots(context):
80
103
exit_code , _ , _ = ssh_connection .execute_command ("sync" )
81
104
assert exit_code == 0
82
105
83
- test_fc_session_root_path = context .custom ["test_fc_session_root_path" ]
84
- vsock_helper = context .custom ["bin_vsock_path" ]
85
106
vm_blob_path = "/tmp/vsock/test.blob"
86
107
# Generate a random data file for vsock.
87
108
blob_path , blob_hash = make_blob (test_fc_session_root_path )
88
109
# Copy the data file and a vsock helper to the guest.
89
- _copy_vsock_data_to_guest (ssh_connection , blob_path , vm_blob_path , vsock_helper )
110
+ _copy_vsock_data_to_guest (ssh_connection , blob_path , vm_blob_path , bin_vsock_path )
90
111
91
- logger .info ("Create {} #0." . format ( snapshot_type ) )
112
+ logger .info ("Create %s #0." , snapshot_type )
92
113
# Create a snapshot builder from a microvm.
93
114
snapshot_builder = SnapshotBuilder (basevm )
94
115
@@ -99,7 +120,7 @@ def _test_seq_snapshots(context):
99
120
basevm .kill ()
100
121
101
122
for i in range (seq_len ):
102
- logger .info ("Load snapshot #{} , mem {}" . format ( i , snapshot .mem ) )
123
+ logger .info ("Load snapshot #%s , mem %s" , i , snapshot .mem )
103
124
microvm , _ = vm_builder .build_from_snapshot (
104
125
snapshot , resume = True , diff_snapshots = diff_snapshots
105
126
)
@@ -117,7 +138,7 @@ def _test_seq_snapshots(context):
117
138
# Check that the root device is not corrupted.
118
139
check_filesystem (ssh_connection , "ext4" , "/dev/vda" )
119
140
120
- logger .info ("Create snapshot #{}." . format ( i + 1 ) )
141
+ logger .info ("Create snapshot #%d." , i + 1 )
121
142
122
143
# Create a snapshot builder from the currently running microvm.
123
144
snapshot_builder = SnapshotBuilder (microvm )
@@ -129,7 +150,7 @@ def _test_seq_snapshots(context):
129
150
# If we are testing incremental snapshots we must merge the base with
130
151
# current layer.
131
152
if snapshot_type == SnapshotType .DIFF :
132
- logger .info ("Base: {} , Layer: {}" . format ( base_snapshot .mem , snapshot .mem ) )
153
+ logger .info ("Base: %s , Layer: %s" , base_snapshot .mem , snapshot .mem )
133
154
snapshot .rebase_snapshot (base_snapshot )
134
155
# Update the base for next iteration.
135
156
base_snapshot = snapshot
@@ -244,88 +265,6 @@ def test_patch_drive_snapshot(bin_cloner_path):
244
265
microvm .kill ()
245
266
246
267
247
- def test_5_full_snapshots (
248
- network_config , bin_cloner_path , bin_vsock_path , test_fc_session_root_path
249
- ):
250
- """
251
- Create and load 5 full sequential snapshots.
252
-
253
- @type: functional
254
- """
255
- logger = logging .getLogger ("snapshot_sequence" )
256
-
257
- artifacts = ArtifactCollection (_test_images_s3_bucket ())
258
- # Testing matrix:
259
- # - Guest kernel: All supported ones
260
- # - Rootfs: Ubuntu 18.04
261
- # - Microvm: 2vCPU with 512 MB RAM
262
- # TODO: Multiple microvm sizes must be tested in the async pipeline.
263
- microvm_artifacts = ArtifactSet (artifacts .microvms (keyword = "2vcpu_512mb" ))
264
- kernel_artifacts = ArtifactSet (artifacts .kernels ())
265
- disk_artifacts = ArtifactSet (artifacts .disks (keyword = "ubuntu" ))
266
-
267
- # Create a test context and add builder, logger, network.
268
- test_context = TestContext ()
269
- test_context .custom = {
270
- "builder" : MicrovmBuilder (bin_cloner_path ),
271
- "network_config" : network_config ,
272
- "logger" : logger ,
273
- "snapshot_type" : SnapshotType .FULL ,
274
- "seq_len" : 5 ,
275
- "bin_vsock_path" : bin_vsock_path ,
276
- "test_fc_session_root_path" : test_fc_session_root_path ,
277
- }
278
-
279
- # Create the test matrix.
280
- test_matrix = TestMatrix (
281
- context = test_context ,
282
- artifact_sets = [microvm_artifacts , kernel_artifacts , disk_artifacts ],
283
- )
284
-
285
- test_matrix .run_test (_test_seq_snapshots )
286
-
287
-
288
- def test_5_inc_snapshots (
289
- network_config , bin_cloner_path , bin_vsock_path , test_fc_session_root_path
290
- ):
291
- """
292
- Create and load 5 incremental snapshots.
293
-
294
- @type: functional
295
- """
296
- logger = logging .getLogger ("snapshot_sequence" )
297
-
298
- artifacts = ArtifactCollection (_test_images_s3_bucket ())
299
- # Testing matrix:
300
- # - Guest kernel: All supported ones
301
- # - Rootfs: Ubuntu 18.04
302
- # - Microvm: 2vCPU with 512MB RAM
303
- # TODO: Multiple microvm sizes must be tested in the async pipeline.
304
- microvm_artifacts = ArtifactSet (artifacts .microvms (keyword = "2vcpu_512mb" ))
305
- kernel_artifacts = ArtifactSet (artifacts .kernels ())
306
- disk_artifacts = ArtifactSet (artifacts .disks (keyword = "ubuntu" ))
307
-
308
- # Create a test context and add builder, logger, network.
309
- test_context = TestContext ()
310
- test_context .custom = {
311
- "builder" : MicrovmBuilder (bin_cloner_path ),
312
- "network_config" : network_config ,
313
- "logger" : logger ,
314
- "snapshot_type" : SnapshotType .DIFF ,
315
- "seq_len" : 5 ,
316
- "bin_vsock_path" : bin_vsock_path ,
317
- "test_fc_session_root_path" : test_fc_session_root_path ,
318
- }
319
-
320
- # Create the test matrix.
321
- test_matrix = TestMatrix (
322
- context = test_context ,
323
- artifact_sets = [microvm_artifacts , kernel_artifacts , disk_artifacts ],
324
- )
325
-
326
- test_matrix .run_test (_test_seq_snapshots )
327
-
328
-
329
268
def test_load_snapshot_failure_handling (test_microvm_with_api ):
330
269
"""
331
270
Test error case of loading empty snapshot files.
0 commit comments