@@ -50,39 +50,25 @@ def _get_guest_drive_size(ssh_connection, guest_dev_name="/dev/vdb"):
5050 return lines [1 ].strip ()
5151
5252
53- def test_resume_after_restoration (uvm_nano , microvm_factory ):
54- """Tests snapshot is resumable after restoration.
53+ @pytest .mark .parametrize ("resume_at_restore" , [True , False ])
54+ def test_resume (uvm_nano , microvm_factory , resume_at_restore ):
55+ """Tests snapshot is resumable at or after restoration.
5556
56- Check that a restored microVM is resumable by calling PATCH /vm with Resumed
57- after PUT /snapshot/load with `resume_vm=False`.
57+ Check that a restored microVM is resumable by either
58+ a. PUT /snapshot/load with `resume_vm=False`, then calling PATCH /vm resume=True
59+ b. PUT /snapshot/load with `resume_vm=True`
5860 """
5961 vm = uvm_nano
6062 vm .add_net_iface ()
6163 vm .start ()
62-
63- snapshot = vm .snapshot_full ()
64-
65- restored_vm = microvm_factory .build ()
66- restored_vm .spawn ()
67- restored_vm .restore_from_snapshot (snapshot )
68- restored_vm .resume ()
69-
70-
71- def test_resume_at_restoration (uvm_nano , microvm_factory ):
72- """Tests snapshot is resumable at restoration.
73-
74- Check that a restored microVM is resumable by calling PUT /snapshot/load
75- with `resume_vm=True`.
76- """
77- vm = uvm_nano
78- vm .add_net_iface ()
79- vm .start ()
80-
8164 snapshot = vm .snapshot_full ()
82-
8365 restored_vm = microvm_factory .build ()
8466 restored_vm .spawn ()
85- restored_vm .restore_from_snapshot (snapshot , resume = True )
67+ restored_vm .restore_from_snapshot (snapshot , resume = resume_at_restore )
68+ if not resume_at_restore :
69+ assert restored_vm .state == "Paused"
70+ restored_vm .resume ()
71+ assert restored_vm .state == "Running"
8672
8773
8874def test_snapshot_current_version (uvm_nano ):
@@ -228,9 +214,7 @@ def test_patch_drive_snapshot(uvm_nano, microvm_factory):
228214
229215 # Load snapshot in a new Firecracker microVM.
230216 logger .info ("Load snapshot, mem %s" , snapshot .mem )
231- vm = microvm_factory .build ()
232- vm .spawn ()
233- vm .restore_from_snapshot (snapshot , resume = True )
217+ vm = microvm_factory .build_from_snapshot (snapshot )
234218
235219 # Attempt to connect to resumed microvm and verify the new microVM has the
236220 # right scratch drive.
@@ -319,9 +303,7 @@ def test_negative_postload_api(uvm_plain, microvm_factory):
319303 basevm .kill ()
320304
321305 # Do not resume, just load, so we can still call APIs that work.
322- microvm = microvm_factory .build ()
323- microvm .spawn ()
324- microvm .restore_from_snapshot (snapshot , resume = True )
306+ microvm = microvm_factory .build_from_snapshot (snapshot )
325307
326308 fail_msg = "The requested operation is not supported after starting the microVM"
327309 with pytest .raises (RuntimeError , match = fail_msg ):
@@ -486,9 +468,7 @@ def test_diff_snapshot_overlay(guest_kernel, rootfs, microvm_factory):
486468
487469 assert not filecmp .cmp (merged_snapshot .mem , first_snapshot_backup , shallow = False )
488470
489- new_vm = microvm_factory .build ()
490- new_vm .spawn ()
491- new_vm .restore_from_snapshot (merged_snapshot , resume = True )
471+ _ = microvm_factory .build_from_snapshot (merged_snapshot )
492472
493473 # Check that the restored VM works
494474
@@ -510,9 +490,7 @@ def test_snapshot_overwrite_self(guest_kernel, rootfs, microvm_factory):
510490 snapshot = base_vm .snapshot_full ()
511491 base_vm .kill ()
512492
513- vm = microvm_factory .build ()
514- vm .spawn ()
515- vm .restore_from_snapshot (snapshot , resume = True )
493+ vm = microvm_factory .build_from_snapshot (snapshot )
516494
517495 # When restoring a snapshot, vm.restore_from_snapshot first copies
518496 # the memory file (inside of the jailer) to /mem.src
0 commit comments