Skip to content

Commit 51630ca

Browse files
committed
test: use build_n_from_snapshot to replace explicit loops
Replace snapshot creation loops in test_5_snapshots, test_vmgenid and test_restore_latency with calls to build_n_from_snapshot Signed-off-by: Patrick Roy <[email protected]>
1 parent cf48f33 commit 51630ca

File tree

3 files changed

+8
-49
lines changed

3 files changed

+8
-49
lines changed

tests/framework/microvm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ def build_n_from_snapshot(
11431143
"""
11441144
for _ in range(nr_vms):
11451145
microvm = self.build()
1146-
microvm.spawn(emit_metrics=True)
1146+
microvm.spawn()
11471147

11481148
uffd_path = None
11491149
if uffd_handler_name is not None:

tests/integration_tests/functional/test_snapshot_basic.py

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,9 @@ def test_5_snapshots(
149149
snapshot = vm.make_snapshot(snapshot_type)
150150
vm.kill()
151151

152-
for i in range(seq_len):
153-
logger.info("Load snapshot #%s, mem %s", i, snapshot.mem)
154-
microvm = microvm_factory.build()
155-
microvm.spawn()
156-
copied_snapshot = microvm.restore_from_snapshot(snapshot, resume=True)
157-
152+
for microvm in microvm_factory.build_n_from_snapshot(
153+
snapshot, seq_len, incremental=True, use_snapshot_editor=use_snapshot_editor
154+
):
158155
# FIXME: This and the sleep below reduce the rate of vsock/ssh connection
159156
# related spurious test failures, although we do not know why this is the case.
160157
time.sleep(2)
@@ -171,21 +168,6 @@ def test_5_snapshots(
171168
check_filesystem(microvm.ssh, "squashfs", "/dev/vda")
172169

173170
time.sleep(2)
174-
logger.info("Create snapshot %s #%d.", snapshot_type, i + 1)
175-
new_snapshot = microvm.make_snapshot(snapshot_type)
176-
177-
# If we are testing incremental snapshots we must merge the base with
178-
# current layer.
179-
if snapshot.is_diff:
180-
logger.info("Base: %s, Layer: %s", snapshot.mem, new_snapshot.mem)
181-
new_snapshot = new_snapshot.rebase_snapshot(
182-
snapshot, use_snapshot_editor=use_snapshot_editor
183-
)
184-
185-
microvm.kill()
186-
copied_snapshot.delete()
187-
# Update the base for next iteration.
188-
snapshot = new_snapshot
189171

190172

191173
def test_patch_drive_snapshot(uvm_nano, microvm_factory):
@@ -524,27 +506,13 @@ def test_vmgenid(guest_kernel_linux_6_1, rootfs, microvm_factory, snapshot_type)
524506
base_snapshot = snapshot
525507
base_vm.kill()
526508

527-
for i in range(5):
528-
vm = microvm_factory.build()
529-
vm.spawn()
530-
copied_snapshot = vm.restore_from_snapshot(snapshot, resume=True)
531-
509+
for i, vm in enumerate(
510+
microvm_factory.build_n_from_snapshot(base_snapshot, 5, incremental=True)
511+
):
532512
# We should have as DMESG_VMGENID_RESUME messages as
533513
# snapshots we have resumed
534514
check_vmgenid_update_count(vm, i + 1)
535515

536-
snapshot = vm.make_snapshot(snapshot_type)
537-
vm.kill()
538-
copied_snapshot.delete()
539-
540-
# If we are testing incremental snapshots we ust merge the base with
541-
# current layer.
542-
if snapshot.is_diff:
543-
snapshot = snapshot.rebase_snapshot(base_snapshot)
544-
545-
# Update the base for next iteration
546-
base_snapshot = snapshot
547-
548516

549517
# TODO add `global_props.host_os == "amzn2"` condition
550518
# once amazon linux kernels have patches.

tests/integration_tests/performance/test_snapshot_ab.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ def sample_latency(self, microvm_factory, snapshot) -> List[float]:
8080
"""Collects latency samples for the microvm configuration specified by this instance"""
8181
values = []
8282

83-
for _ in range(ITERATIONS):
84-
microvm = microvm_factory.build(
85-
monitor_memory=False,
86-
)
87-
microvm.spawn(emit_metrics=True)
88-
snapshot_copy = microvm.restore_from_snapshot(snapshot, resume=True)
89-
83+
for microvm in microvm_factory.build_n_from_snapshot(snapshot, ITERATIONS):
9084
value = 0
9185
# Parse all metric data points in search of load_snapshot time.
9286
microvm.flush_metrics()
@@ -98,10 +92,7 @@ def sample_latency(self, microvm_factory, snapshot) -> List[float]:
9892
break
9993
assert value > 0
10094
values.append(value)
101-
microvm.kill()
102-
snapshot_copy.delete()
10395

104-
snapshot.delete()
10596
return values
10697

10798

0 commit comments

Comments
 (0)