@@ -50,39 +50,25 @@ def _get_guest_drive_size(ssh_connection, guest_dev_name="/dev/vdb"):
50
50
return lines [1 ].strip ()
51
51
52
52
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.
55
56
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`
58
60
"""
59
61
vm = uvm_nano
60
62
vm .add_net_iface ()
61
63
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
-
81
64
snapshot = vm .snapshot_full ()
82
-
83
65
restored_vm = microvm_factory .build ()
84
66
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"
86
72
87
73
88
74
def test_snapshot_current_version (uvm_nano ):
@@ -228,9 +214,7 @@ def test_patch_drive_snapshot(uvm_nano, microvm_factory):
228
214
229
215
# Load snapshot in a new Firecracker microVM.
230
216
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 )
234
218
235
219
# Attempt to connect to resumed microvm and verify the new microVM has the
236
220
# right scratch drive.
@@ -319,9 +303,7 @@ def test_negative_postload_api(uvm_plain, microvm_factory):
319
303
basevm .kill ()
320
304
321
305
# 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 )
325
307
326
308
fail_msg = "The requested operation is not supported after starting the microVM"
327
309
with pytest .raises (RuntimeError , match = fail_msg ):
@@ -486,9 +468,7 @@ def test_diff_snapshot_overlay(guest_kernel, rootfs, microvm_factory):
486
468
487
469
assert not filecmp .cmp (merged_snapshot .mem , first_snapshot_backup , shallow = False )
488
470
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 )
492
472
493
473
# Check that the restored VM works
494
474
@@ -510,9 +490,7 @@ def test_snapshot_overwrite_self(guest_kernel, rootfs, microvm_factory):
510
490
snapshot = base_vm .snapshot_full ()
511
491
base_vm .kill ()
512
492
513
- vm = microvm_factory .build ()
514
- vm .spawn ()
515
- vm .restore_from_snapshot (snapshot , resume = True )
493
+ vm = microvm_factory .build_from_snapshot (snapshot )
516
494
517
495
# When restoring a snapshot, vm.restore_from_snapshot first copies
518
496
# the memory file (inside of the jailer) to /mem.src
0 commit comments