|
| 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