Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libvirt/tests/cfg/guest_kernel_debugging/cpi_info.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
- long_system_name:
test_case_name = long_system_name
test_system_name = "VERYLONGSYSTEMNAME123456789"
- nested_kvm_cpi:
test_case_name = nested_kvm_cpi
kvm_module_parameters = 'nested=1'

98 changes: 98 additions & 0 deletions libvirt/tests/src/guest_kernel_debugging/cpi_info.py
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,
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smitterl if you have a look at
line 75:
def test_cpi_functionality():
"""
Test case 1: CPI functionality with automatic SE guest detection and handling
line 184:
def test_managedsave():
"""
Test case 2: Test managedsave behavior
line 250:
def test_long_system_name(long_system_name):
"""
Test case 3: Test system_name length validation (>8 characters)


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 ===")

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}")

# 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
Expand All @@ -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}")

Expand Down