Skip to content

Commit 778992e

Browse files
Add device-passthrough testcase for CH platform
Add test case to verify if passthrough-devices are visible to guest for CH platform Signed-off-by: Smit Gardhariya <[email protected]>
1 parent 7b264b4 commit 778992e

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT license.
3+
from pathlib import Path
4+
from typing import Any, Dict, cast
5+
6+
from lisa import (
7+
Environment,
8+
Logger,
9+
Node,
10+
TestCaseMetadata,
11+
TestSuite,
12+
TestSuiteMetadata,
13+
)
14+
from lisa.sut_orchestrator import CLOUD_HYPERVISOR
15+
from lisa.sut_orchestrator.libvirt.ch_platform import CloudHypervisorPlatform
16+
from lisa.sut_orchestrator.libvirt.context import get_node_context as get_ch_context
17+
from lisa.sut_orchestrator.libvirt.schema import BaseLibvirtNodeSchema
18+
from lisa.testsuite import TestResult, simple_requirement
19+
from lisa.tools import Lspci
20+
from lisa.util import LisaException, SkippedException
21+
22+
23+
@TestSuiteMetadata(
24+
area="cvm",
25+
category="functional",
26+
description="""
27+
This test suite is for generating CVM attestation report only for azure cvms.
28+
""",
29+
)
30+
class DevicePassthroughFunctionalTests(TestSuite):
31+
@TestCaseMetadata(
32+
description="""
33+
Check if passthrough device is visible to guest.
34+
This testcase support only on CLOUD_HYPERVISOR
35+
platform of LISA.
36+
""",
37+
priority=4,
38+
requirement=simple_requirement(
39+
supported_platform_type=[CLOUD_HYPERVISOR],
40+
),
41+
)
42+
def verify_device_passthrough_on_guest(
43+
self,
44+
log: Logger,
45+
node: Node,
46+
environment: Environment,
47+
log_path: Path,
48+
result: TestResult,
49+
variables: Dict[str, Any],
50+
) -> None:
51+
ctx = get_ch_context(node)
52+
if not ctx.passthrough_devices:
53+
raise SkippedException("No device-passthrough is set for node")
54+
55+
lspci = node.tools[Lspci]
56+
platform = cast(CloudHypervisorPlatform, environment.platform)
57+
rb = environment.platform.runbook.get_extended_runbook(BaseLibvirtNodeSchema)
58+
libvirt_runbook = cast(BaseLibvirtNodeSchema, rb)
59+
60+
pool_vendor_device_map = {}
61+
for pool in platform.platform_runbook.device_pools:
62+
pool_type = str(pool.type.value)
63+
vendor_device_id = {
64+
"vendord_id": pool.devices[0].vendor_id,
65+
"device_id": pool.devices[0].device_id,
66+
}
67+
pool_vendor_device_map[pool_type] = vendor_device_id
68+
69+
for req in libvirt_runbook.device_passthrough:
70+
pool_type = str(req.pool_type.value)
71+
ven_dev_of_pool = pool_vendor_device_map[pool_type]
72+
ven_id = ven_dev_of_pool["vendor_id"]
73+
dev_id = ven_dev_of_pool["device_id"]
74+
devices = lspci.get_devices_by_vendor_device_id(
75+
vendor_id=ven_id,
76+
device_id=dev_id,
77+
force_run=True,
78+
)
79+
if len(devices) != req.count:
80+
raise LisaException(
81+
f"Device count don't match, got total: {len(devices)} devices on "
82+
f"guest vm. As per runbook, Required device count: {req.count}, "
83+
f"for pool_type: {pool_type} having Vendor/Device ID as "
84+
f"vendor_id = {ven_id}, device_id={dev_id}"
85+
)

0 commit comments

Comments
 (0)