-
Notifications
You must be signed in to change notification settings - Fork 184
CPI: Add test case to check hypervisor bit of cpi info #6759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import logging as log | ||
| import re | ||
| import time | ||
|
|
||
| from virttest import utils_misc, virsh | ||
| from virttest import utils_package | ||
| from virttest.utils_cpi import ( | ||
| CPIChecker, | ||
| get_cpi_config, | ||
|
|
@@ -298,6 +300,100 @@ def test_long_system_name(long_system_name): | |
|
|
||
| logging.info("Long system name validation test passed") | ||
|
|
||
| def test_nested_kvm_cpi(): | ||
| """ | ||
| Test case 4: Test CPI system_level behavior in nested KVM environment | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test cases in avocado aren't ordered but can be executed in any order, please remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious about why does other function in this python file have the test case number?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because it wasn't properly reviewed, can you point me to it? i have only seen step enumeration, not test case enumeration
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fbq815 nevermind, I've found it myself. Please can you help make sure that none of the test cases have enumeration?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smitterl if you have a look at |
||
|
|
||
| Steps: | ||
| 1. L2 guest: Check /sys/firmware/cpi/system_level and verify hypervisor_bit is '0' | ||
| 2. L2 guest: enable nested and Boot L3 guest | ||
| 3. L2 guest: Check /sys/firmware/cpi/system_level and verify hypervisor_bit is '1' | ||
| """ | ||
| logging.info("=== Test Case 4: Nested KVM CPI ===") | ||
fbq815 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def check_and_enable_nested(session): | ||
| current_nested = None | ||
| try: | ||
| # Check on L2 guest | ||
| current_nested = (session.cmd_output( | ||
| "cat /sys/module/kvm/parameters/nested", | ||
| timeout=30).strip()) | ||
| logging.info(f"Current nested status: {current_nested}") | ||
| except Exception as e: | ||
| logging.warning( | ||
| f"Failed to check current nested status: {e}") | ||
|
|
||
| # Reload kvm module with nested=1 if not already enabled | ||
| if current_nested != "1": | ||
| logging.info("Reloading kvm module with nested=1") | ||
| try: | ||
| # Reload kvm modules with nested enabled on L2 guest | ||
| session.cmd_output( | ||
| "modprobe -r kvm ; modprobe kvm nested=1", | ||
| timeout=30) | ||
| # Verify nested is enabled | ||
| new_status = session.cmd_output( | ||
| "cat /sys/module/kvm/parameters/nested", | ||
| timeout=30).strip() | ||
| if new_status != "1": | ||
| test.fail("Failed to enable nested virtualization") | ||
| logging.info( | ||
| "Nested virtualization enabled successfully") | ||
| except Exception as e: | ||
| test.fail(f"Failed to reload kvm module: {e}") | ||
| else: | ||
| logging.info("Nested virtualization already enabled") | ||
|
|
||
| logging.info("Step 1: Checking CPI system_level on L2 guest") | ||
| session = None | ||
| try: | ||
| # Login L2 guest | ||
| session = vm.wait_for_login(timeout=60) | ||
|
|
||
| checker = CPIChecker(vm, serial=serial) | ||
| system_level = checker.get_cpi_field("system_level") | ||
| parsed = checker._parse_system_level(system_level) | ||
| if parsed['hypervisor_bit'] != 0: | ||
| test.fail(f"L2 hypervisor_bit should be 0, but actual is " | ||
| f"{parsed['hypervisor_bit']}") | ||
|
|
||
| logging.info("Step 2: Enable nested on L2 guest and Boot L3 guest") | ||
| check_and_enable_nested(session) | ||
|
|
||
| # install qemu-kvm on L2 | ||
| logging.info("Installing qemu-kvm") | ||
| utils_package.package_install("qemu-kvm", session=session) | ||
|
|
||
| logging.info("Starting L3 guest") | ||
| start_cmd = \ | ||
| "/usr/libexec/qemu-kvm -machine s390-ccw-virtio -no-shutdown &" | ||
| try: | ||
| session.sendline(start_cmd) | ||
| except Exception as e: | ||
| logging.error(f"Failed to start L3 guest: {e}") | ||
| test.fail(f"Failed to start L3 guest: {e}") | ||
fbq815 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # wait L3 guest to boot up | ||
| logging.info("waiting for L3 guest to boot") | ||
| time.sleep(5) | ||
| # Verify qemu-kvm process is running | ||
| qemu_status = session.cmd_status("pgrep -f qemu-kvm") | ||
| if qemu_status != 0: | ||
| test.fail("L3 guest (qemu-kvm) process not found") | ||
|
|
||
| logging.info("Step 3: Checking CPI system_level on L2 guest") | ||
| system_level = checker.get_cpi_field("system_level") | ||
| parsed = checker._parse_system_level(system_level) | ||
| if parsed['hypervisor_bit'] != 1: | ||
| test.fail(f"L2 hypervisor_bit should be 1, but actual is " | ||
| f"{parsed['hypervisor_bit']}") | ||
| finally: | ||
| if session is not None: | ||
| try: | ||
| session.close() | ||
| except Exception as e: | ||
| logging.warning(f"Failed to close session: {e}") | ||
|
|
||
| def cleanup_cpi_config(): | ||
| """ | ||
| Clean up CPI configuration by restoring from backup | ||
|
|
@@ -315,6 +411,8 @@ def cleanup_cpi_config(): | |
| test_managedsave() | ||
| elif test_case_name == "long_system_name": | ||
| test_long_system_name(test_system_name) | ||
| elif test_case_name == "nested_kvm_cpi": | ||
| test_nested_kvm_cpi() | ||
| else: | ||
| test.error(f"Unknown test case: {test_case_name}") | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.