Skip to content

Commit 940b360

Browse files
pb8otommady
authored andcommitted
tests: parametrize uvm_any fixture family with vcpus and memory
Add a parameter so that we can control vcpu number and memory. Right now it uses a hardcoded value, but it can be overridden per test. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 0861767 commit 940b360

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

tests/conftest.py

+46-8
Original file line numberDiff line numberDiff line change
@@ -455,20 +455,34 @@ def uvm_with_initrd(
455455
yield uvm
456456

457457

458-
def uvm_booted(microvm_factory, guest_kernel, rootfs, cpu_template):
458+
@pytest.fixture
459+
def vcpu_count():
460+
"""Return default vcpu_count. Use indirect parametrization to override."""
461+
return 2
462+
463+
464+
@pytest.fixture
465+
def mem_size_mib():
466+
"""Return memory size. Use indirect parametrization to override."""
467+
return 256
468+
469+
470+
def uvm_booted(
471+
microvm_factory, guest_kernel, rootfs, cpu_template, vcpu_count=2, mem_size_mib=256
472+
):
459473
"""Return a booted uvm"""
460474
uvm = microvm_factory.build(guest_kernel, rootfs)
461475
uvm.spawn()
462-
uvm.basic_config(vcpu_count=2, mem_size_mib=256)
476+
uvm.basic_config(vcpu_count=vcpu_count, mem_size_mib=mem_size_mib)
463477
uvm.set_cpu_template(cpu_template)
464478
uvm.add_net_iface()
465479
uvm.start()
466480
return uvm
467481

468482

469-
def uvm_restored(microvm_factory, guest_kernel, rootfs, cpu_template):
483+
def uvm_restored(microvm_factory, guest_kernel, rootfs, cpu_template, **kwargs):
470484
"""Return a restored uvm"""
471-
uvm = uvm_booted(microvm_factory, guest_kernel, rootfs, cpu_template)
485+
uvm = uvm_booted(microvm_factory, guest_kernel, rootfs, cpu_template, **kwargs)
472486
snapshot = uvm.snapshot_full()
473487
uvm.kill()
474488
uvm2 = microvm_factory.build_from_snapshot(snapshot)
@@ -483,12 +497,36 @@ def uvm_ctor(request):
483497

484498

485499
@pytest.fixture
486-
def uvm_any(microvm_factory, uvm_ctor, guest_kernel, rootfs, cpu_template_any):
500+
def uvm_any(
501+
microvm_factory,
502+
uvm_ctor,
503+
guest_kernel,
504+
rootfs,
505+
cpu_template_any,
506+
vcpu_count,
507+
mem_size_mib,
508+
):
487509
"""Return booted and restored uvms"""
488-
return uvm_ctor(microvm_factory, guest_kernel, rootfs, cpu_template_any)
510+
return uvm_ctor(
511+
microvm_factory,
512+
guest_kernel,
513+
rootfs,
514+
cpu_template_any,
515+
vcpu_count=vcpu_count,
516+
mem_size_mib=mem_size_mib,
517+
)
489518

490519

491520
@pytest.fixture
492-
def uvm_any_booted(microvm_factory, guest_kernel, rootfs, cpu_template_any):
521+
def uvm_any_booted(
522+
microvm_factory, guest_kernel, rootfs, cpu_template_any, vcpu_count, mem_size_mib
523+
):
493524
"""Return booted uvms"""
494-
return uvm_booted(microvm_factory, guest_kernel, rootfs, cpu_template_any)
525+
return uvm_booted(
526+
microvm_factory,
527+
guest_kernel,
528+
rootfs,
529+
cpu_template_any,
530+
vcpu_count=vcpu_count,
531+
mem_size_mib=mem_size_mib,
532+
)

0 commit comments

Comments
 (0)