88import tempfile
99from pathlib import Path
1010
11+ import pytest
12+
1113from conftest import _test_images_s3_bucket
1214from framework .artifacts import ArtifactCollection , ArtifactSet
1315from framework .builder import MicrovmBuilder , SnapshotBuilder , SnapshotType
@@ -40,38 +42,59 @@ def _get_guest_drive_size(ssh_connection, guest_dev_name="/dev/vdb"):
4042 return stdout .readline ().strip ()
4143
4244
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
4878 diff_snapshots = snapshot_type == SnapshotType .DIFF
4979
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 ()
5883
5984 # Create a rw copy artifact.
60- root_disk = context . disk .copy ()
85+ root_disk = disk .copy ()
6186 # Get ssh key from read-only artifact.
62- ssh_key = context . disk .ssh_key ()
87+ ssh_key = disk .ssh_key ()
6388 # Create a fresh microvm from artifacts.
6489 vm_instance = vm_builder .build (
65- kernel = context . kernel ,
90+ kernel = kernel ,
6691 disks = [root_disk ],
6792 ssh_key = ssh_key ,
68- config = context . microvm ,
93+ config = microvm ,
6994 diff_snapshots = diff_snapshots ,
7095 )
7196 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 } " )
7598
7699 basevm .start ()
77100 ssh_connection = net_tools .SSHConnection (basevm .ssh_config )
@@ -80,15 +103,13 @@ def _test_seq_snapshots(context):
80103 exit_code , _ , _ = ssh_connection .execute_command ("sync" )
81104 assert exit_code == 0
82105
83- test_fc_session_root_path = context .custom ["test_fc_session_root_path" ]
84- vsock_helper = context .custom ["bin_vsock_path" ]
85106 vm_blob_path = "/tmp/vsock/test.blob"
86107 # Generate a random data file for vsock.
87108 blob_path , blob_hash = make_blob (test_fc_session_root_path )
88109 # 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 )
90111
91- logger .info ("Create {} #0." . format ( snapshot_type ) )
112+ logger .info ("Create %s #0." , snapshot_type )
92113 # Create a snapshot builder from a microvm.
93114 snapshot_builder = SnapshotBuilder (basevm )
94115
@@ -99,7 +120,7 @@ def _test_seq_snapshots(context):
99120 basevm .kill ()
100121
101122 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 )
103124 microvm , _ = vm_builder .build_from_snapshot (
104125 snapshot , resume = True , diff_snapshots = diff_snapshots
105126 )
@@ -117,7 +138,7 @@ def _test_seq_snapshots(context):
117138 # Check that the root device is not corrupted.
118139 check_filesystem (ssh_connection , "ext4" , "/dev/vda" )
119140
120- logger .info ("Create snapshot #{}." . format ( i + 1 ) )
141+ logger .info ("Create snapshot #%d." , i + 1 )
121142
122143 # Create a snapshot builder from the currently running microvm.
123144 snapshot_builder = SnapshotBuilder (microvm )
@@ -129,7 +150,7 @@ def _test_seq_snapshots(context):
129150 # If we are testing incremental snapshots we must merge the base with
130151 # current layer.
131152 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 )
133154 snapshot .rebase_snapshot (base_snapshot )
134155 # Update the base for next iteration.
135156 base_snapshot = snapshot
@@ -244,88 +265,6 @@ def test_patch_drive_snapshot(bin_cloner_path):
244265 microvm .kill ()
245266
246267
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-
329268def test_load_snapshot_failure_handling (test_microvm_with_api ):
330269 """
331270 Test error case of loading empty snapshot files.
0 commit comments