Skip to content

Commit 64d38fd

Browse files
committed
refactor: remove clone_vm and extend build_from_snapshot to accept uffd
These two functions were doing a similar thing. Let's extend the build_from_snapshot to support uffd and drop the newly introduced clone_vm. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent f00cdcb commit 64d38fd

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

tests/framework/microvm.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,13 @@ def build(self, kernel=None, rootfs=None, **kwargs):
12791279
vm.ssh_key = ssh_key
12801280
return vm
12811281

1282-
def build_from_snapshot(self, snapshot: Snapshot):
1282+
def build_from_snapshot(self, snapshot: Snapshot, uffd_handler_name=None):
12831283
"""Build a microvm from a snapshot"""
12841284
vm = self.build()
12851285
vm.spawn()
1286-
vm.restore_from_snapshot(snapshot, resume=True)
1286+
vm.restore_from_snapshot(
1287+
snapshot, resume=True, uffd_handler_name=uffd_handler_name
1288+
)
12871289
return vm
12881290

12891291
def build_n_from_snapshot(
@@ -1342,18 +1344,6 @@ def build_n_from_snapshot(
13421344
last_snapshot.delete()
13431345
current_snapshot.delete()
13441346

1345-
def clone_uvm(self, uvm, uffd_handler_name=None):
1346-
"""
1347-
Clone the given VM and start it.
1348-
"""
1349-
snapshot = uvm.snapshot_full()
1350-
restored_vm = self.build()
1351-
restored_vm.spawn()
1352-
restored_vm.restore_from_snapshot(
1353-
snapshot, resume=True, uffd_handler_name=uffd_handler_name
1354-
)
1355-
return restored_vm
1356-
13571347
def kill(self):
13581348
"""Clean up all built VMs"""
13591349
for vm in self.vms:

tests/integration_tests/performance/test_hotplug_memory.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def uvm_resumed_memhp(
6565
uvm = uvm_booted_memhp(
6666
uvm_plain, rootfs, microvm_factory, vhost_user, memhp_config, huge_pages, None
6767
)
68-
return microvm_factory.clone_uvm(uvm, uffd_handler_name=uffd_handler)
68+
snapshot = uvm.snapshot_full()
69+
return microvm_factory.build_from_snapshot(snapshot, uffd_handler_name=uffd_handler)
6970

7071

7172
@pytest.fixture(
@@ -282,7 +283,8 @@ def test_snapshot_restore_persistence(uvm_plain_6_1, microvm_factory):
282283

283284
_, checksum_before, _ = uvm.ssh.check_output("sha256sum /dev/shm/mem_hp_test")
284285

285-
restored_vm = microvm_factory.clone_uvm(uvm)
286+
snapshot = uvm.make_snapshot(snapshot_type)
287+
restored_vm = microvm_factory.build_from_snapshot(snapshot)
286288

287289
_, checksum_after, _ = restored_vm.ssh.check_output(
288290
"sha256sum /dev/shm/mem_hp_test"

0 commit comments

Comments
 (0)