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