Skip to content

Commit bf3e19d

Browse files
committed
test: add unit tests for nested virtualization detection
Add test_nested_virtualization.py covering _supports_nested_virtualization() in VMLauncher. Tests verify that C8i, M8i, R8i, C7i, M7i, R7i, X8i, I7i families (and flex/d variants) are correctly detected as supporting nested virtualization, while older families (c5a, c6g, t3, m5) are not. Signed-off-by: Norbert Manthey <nmanthey@amazon.de>
1 parent a30d0d2 commit bf3e19d

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""Unit tests for nested virtualization support in launch_vm."""
2+
# pylint: disable=protected-access
3+
4+
__authors__ = ["Norbert Manthey <nmanthey@amazon.de>"]
5+
__copyright__ = "Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved."
6+
# SPDX-License-Identifier: Apache-2.0
7+
8+
from unittest.mock import patch, MagicMock
9+
10+
import pytest
11+
12+
from kernel_ci_cloud_labs.launch_vm import VMLauncher
13+
14+
15+
@pytest.fixture
16+
def _mock_boto3():
17+
"""Patch boto3 so VMLauncher.__init__ doesn't need real AWS credentials."""
18+
with patch("kernel_ci_cloud_labs.launch_vm.boto3") as mock_boto:
19+
mock_boto.client.return_value = MagicMock()
20+
yield mock_boto
21+
22+
23+
class TestNestedVirtualization:
24+
"""Tests for _supports_nested_virtualization and CpuOptions."""
25+
26+
def _make_launcher(self, instance_type, _mock_boto3):
27+
"""Create a VMLauncher with a given instance_type, mocking AWS."""
28+
vm_config = {
29+
"instance_type": instance_type,
30+
"ami_id": "ami-test123",
31+
"role_name": "test-role",
32+
"s3_bucket": "test-bucket",
33+
"run_prefix": "run_test",
34+
}
35+
return VMLauncher(vm_config)
36+
37+
def test_c8i_supports_nested(self, _mock_boto3):
38+
launcher = self._make_launcher("c8i.4xlarge", _mock_boto3)
39+
assert launcher._supports_nested_virtualization() is True
40+
41+
def test_c8i_flex_supports_nested(self, _mock_boto3):
42+
launcher = self._make_launcher("c8i-flex.2xlarge", _mock_boto3)
43+
assert launcher._supports_nested_virtualization() is True
44+
45+
def test_m8i_supports_nested(self, _mock_boto3):
46+
launcher = self._make_launcher("m8i.large", _mock_boto3)
47+
assert launcher._supports_nested_virtualization() is True
48+
49+
def test_r8i_supports_nested(self, _mock_boto3):
50+
launcher = self._make_launcher("r8i.xlarge", _mock_boto3)
51+
assert launcher._supports_nested_virtualization() is True
52+
53+
def test_c7i_supports_nested(self, _mock_boto3):
54+
launcher = self._make_launcher("c7i.2xlarge", _mock_boto3)
55+
assert launcher._supports_nested_virtualization() is True
56+
57+
def test_m7i_supports_nested(self, _mock_boto3):
58+
launcher = self._make_launcher("m7i.xlarge", _mock_boto3)
59+
assert launcher._supports_nested_virtualization() is True
60+
61+
def test_x8i_supports_nested(self, _mock_boto3):
62+
launcher = self._make_launcher("x8i.large", _mock_boto3)
63+
assert launcher._supports_nested_virtualization() is True
64+
65+
def test_i7i_supports_nested(self, _mock_boto3):
66+
launcher = self._make_launcher("i7i.xlarge", _mock_boto3)
67+
assert launcher._supports_nested_virtualization() is True
68+
69+
def test_c5a_does_not_support_nested(self, _mock_boto3):
70+
launcher = self._make_launcher("c5a.4xlarge", _mock_boto3)
71+
assert launcher._supports_nested_virtualization() is False
72+
73+
def test_c6g_does_not_support_nested(self, _mock_boto3):
74+
launcher = self._make_launcher("c6g.4xlarge", _mock_boto3)
75+
assert launcher._supports_nested_virtualization() is False
76+
77+
def test_t3_does_not_support_nested(self, _mock_boto3):
78+
launcher = self._make_launcher("t3.micro", _mock_boto3)
79+
assert launcher._supports_nested_virtualization() is False
80+
81+
def test_m5_does_not_support_nested(self, _mock_boto3):
82+
launcher = self._make_launcher("m5.large", _mock_boto3)
83+
assert launcher._supports_nested_virtualization() is False

0 commit comments

Comments
 (0)