Skip to content

Commit d9aebba

Browse files
committed
test: add a test to check for nested virtualization
Check that nested virtualization is disabled in all our CPU templates. Other tests already check for CPU features explicitly, but this test just checks that virtualization is not available to the guest, however the means. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 2d0d509 commit d9aebba

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,18 @@ def custom_cpu_template(request, record_property):
293293
return request.param
294294

295295

296+
@pytest.fixture(
297+
params=list(static_cpu_templates_params()) + list(custom_cpu_templates_params())
298+
)
299+
def cpu_template_any(request, record_property):
300+
"""This fixture combines static and custom CPU templates"""
301+
if "name" in request.param:
302+
record_property("custom_cpu_template", request.param["name"])
303+
else:
304+
record_property("static_cpu_template", request.param)
305+
return request.param
306+
307+
296308
@pytest.fixture(params=["Sync", "Async"])
297309
def io_engine(request):
298310
"""All supported io_engines"""
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Tests ensuring nested virtualization is not present when using CPU templates.
5+
6+
We have tests that ensure CPU templates provide a consistent set of features in
7+
the guest:
8+
9+
- file:../functional/test_cpu_features.py
10+
- file:../functional/test_feat_parity.py
11+
- Commit: 681e781f999e3390b6d46422a3c7b1a7e36e1b24
12+
13+
These already include the absence of VMX/SVM in the guest.
14+
15+
This test is a safety-net to make the test explicit and catch cases where we
16+
start providing the feature by mistake.
17+
"""
18+
19+
import pytest
20+
21+
22+
@pytest.fixture
23+
def uvm_with_cpu_template(
24+
microvm_factory, guest_kernel, rootfs_ubuntu_22, cpu_template_any
25+
):
26+
"""A microvm fixture parametrized with all possible templates"""
27+
vm = microvm_factory.build(guest_kernel, rootfs_ubuntu_22)
28+
vm.spawn()
29+
cpu_template = None
30+
if isinstance(cpu_template_any, str):
31+
cpu_template = cpu_template_any
32+
vm.basic_config(cpu_template=cpu_template)
33+
if cpu_template is None:
34+
vm.api.cpu_config.put(**cpu_template_any["template"])
35+
vm.add_net_iface()
36+
vm.start()
37+
yield vm
38+
39+
40+
def test_no_nv_when_using_cpu_templates(uvm_with_cpu_template):
41+
"""
42+
Double-check that guests using CPU templates don't have Nested Virtualization
43+
enabled.
44+
"""
45+
46+
vm = uvm_with_cpu_template
47+
rc, _, _ = vm.ssh.run("[ ! -e /dev/kvm ]")
48+
assert rc == 0, "/dev/kvm exists"

0 commit comments

Comments
 (0)