Skip to content

Commit

Permalink
tests: save metadata on snapshot
Browse files Browse the repository at this point in the history
There is some information in the Microvm class that we don't save in the
snapshot. Some tests do depend on those, so to make the booted/restored
case homogenous, make room in the snapshot to save metadata that we can
then restore.

Signed-off-by: Pablo Barbáchano <[email protected]>
  • Loading branch information
pb8o committed Dec 3, 2024
1 parent 81bae9f commit 426790e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/framework/microvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Snapshot:
disks: dict
ssh_key: Path
snapshot_type: SnapshotType
meta: dict

@property
def is_diff(self) -> bool:
Expand Down Expand Up @@ -110,6 +111,7 @@ def copy_to_chroot(self, chroot) -> "Snapshot":
disks=self.disks,
ssh_key=self.ssh_key,
snapshot_type=self.snapshot_type,
meta=self.meta,
)

@classmethod
Expand All @@ -125,6 +127,7 @@ def load_from(cls, src: Path) -> "Snapshot":
disks={dsk: src / p for dsk, p in obj["disks"].items()},
ssh_key=src / obj["ssh_key"],
snapshot_type=SnapshotType(obj["snapshot_type"]),
meta=obj["meta"],
)

def save_to(self, dst: Path):
Expand Down Expand Up @@ -917,6 +920,9 @@ def make_snapshot(
net_ifaces=[x["iface"] for ifname, x in self.iface.items()],
ssh_key=self.ssh_key,
snapshot_type=snapshot_type,
meta={
"kernel_file": self.kernel_file,
},
)

def snapshot_diff(self, *, mem_path: str = "mem", vmstate_path="vmstate"):
Expand Down Expand Up @@ -954,6 +960,9 @@ def restore_from_snapshot(
if uffd_path is not None:
mem_backend = {"backend_type": "Uffd", "backend_path": str(uffd_path)}

for key, value in snapshot.meta.items():
setattr(self, key, value)

self.api.snapshot_load.put(
mem_backend=mem_backend,
snapshot_path=str(jailed_vmstate),
Expand Down

0 comments on commit 426790e

Please sign in to comment.