Skip to content

Commit 00c868b

Browse files
pb8odianpopa
authored andcommitted
Add a way to simply restore a snapshot in tests
Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 4cae256 commit 00c868b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/framework/microvm.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,36 @@ def pause_to_snapshot(
856856
response.status_code
857857
), response.text
858858

859+
def restore_from_snapshot(
860+
self,
861+
*,
862+
snapshot_mem: Path,
863+
snapshot_vmstate: Path,
864+
snapshot_disks: list[Path],
865+
snapshot_is_diff: bool = False,
866+
):
867+
"""
868+
Restores a snapshot, and resumes the microvm
869+
"""
870+
871+
# Hardlink all the snapshot files into the microvm jail.
872+
jailed_mem = self.create_jailed_resource(snapshot_mem)
873+
jailed_vmstate = self.create_jailed_resource(snapshot_vmstate)
874+
875+
assert len(snapshot_disks) > 0, "Snapshot requires at least one disk."
876+
jailed_disks = []
877+
for disk in snapshot_disks:
878+
jailed_disks.append(self.create_jailed_resource(disk))
879+
880+
response = self.snapshot.load(
881+
mem_file_path=jailed_mem,
882+
snapshot_path=jailed_vmstate,
883+
diff=snapshot_is_diff,
884+
resume=True,
885+
)
886+
assert response.ok
887+
return True
888+
859889
def start_console_logger(self, log_fifo):
860890
"""
861891
Start a thread that monitors the microVM console.

0 commit comments

Comments
 (0)