Skip to content

Commit c80beaa

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 51db0b8 commit c80beaa

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
@@ -1277,11 +1277,13 @@ def build(self, kernel=None, rootfs=None, **kwargs):
12771277
vm.ssh_key = ssh_key
12781278
return vm
12791279

1280-
def build_from_snapshot(self, snapshot: Snapshot):
1280+
def build_from_snapshot(self, snapshot: Snapshot, uffd_handler_name=None):
12811281
"""Build a microvm from a snapshot"""
12821282
vm = self.build()
12831283
vm.spawn()
1284-
vm.restore_from_snapshot(snapshot, resume=True)
1284+
vm.restore_from_snapshot(
1285+
snapshot, resume=True, uffd_handler_name=uffd_handler_name
1286+
)
12851287
return vm
12861288

12871289
def build_n_from_snapshot(
@@ -1340,18 +1342,6 @@ def build_n_from_snapshot(
13401342
last_snapshot.delete()
13411343
current_snapshot.delete()
13421344

1343-
def clone_uvm(self, uvm, uffd_handler_name=None):
1344-
"""
1345-
Clone the given VM and start it.
1346-
"""
1347-
snapshot = uvm.snapshot_full()
1348-
restored_vm = self.build()
1349-
restored_vm.spawn()
1350-
restored_vm.restore_from_snapshot(
1351-
snapshot, resume=True, uffd_handler_name=uffd_handler_name
1352-
)
1353-
return restored_vm
1354-
13551345
def kill(self):
13561346
"""Clean up all built VMs"""
13571347
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)