|
| 1 | +import re |
| 2 | + |
| 3 | +from virttest import virsh |
| 4 | +from virttest import utils_net |
| 5 | +from virttest.libvirt_xml import vm_xml |
| 6 | +from virttest.utils_libvirt import libvirt_vmxml |
| 7 | +from virttest.utils_test import libvirt |
| 8 | + |
| 9 | +from provider.virtual_network import network_base |
| 10 | +from provider.interface import interface_base |
| 11 | + |
| 12 | +VIRSH_ARGS = {'ignore_status': False, 'debug': True} |
| 13 | + |
| 14 | + |
| 15 | +def check_packed_virtqueue(session, expected_packed_bit, test): |
| 16 | + """ |
| 17 | + Check if packed virtqueue is enabled on the VM |
| 18 | +
|
| 19 | + :param session: VM session |
| 20 | + :param expected_packed_bit: Expected packed bit value |
| 21 | + :param test: Test instance |
| 22 | + """ |
| 23 | + test.log.debug("Checking packed virtqueue configuration...") |
| 24 | + |
| 25 | + # 1. Get the PCI address of the network device |
| 26 | + lspci_output = session.cmd_output("lspci | grep Eth") |
| 27 | + test.log.debug(f"lspci output: {lspci_output}") |
| 28 | + |
| 29 | + # 2. Extract PCI address and find virtio features file |
| 30 | + pci_address = re.match(r'^([0-9a-f]{2}:[0-9a-f]{2}\.[0-9a-f])', lspci_output.strip()) |
| 31 | + if not pci_address: |
| 32 | + test.fail(f"Could not extract PCI address from lspci output: {lspci_output}") |
| 33 | + pci_addr = pci_address.group(1) |
| 34 | + test.log.debug(f"Extracted PCI address: {pci_addr}") |
| 35 | + |
| 36 | + find_cmd = 'find / -name features | grep "%s"' % pci_addr |
| 37 | + virtio_features_file = session.cmd_output(find_cmd) |
| 38 | + |
| 39 | + if not virtio_features_file: |
| 40 | + test.fail(f"Virtio features file not found for PCI address {pci_addr}") |
| 41 | + test.log.debug(f"Using virtio features file: {virtio_features_file}") |
| 42 | + |
| 43 | + packed_bit_cmd = f"cat {virtio_features_file}" |
| 44 | + output_lines = session.cmd_output(packed_bit_cmd).split('\n') |
| 45 | + test.log.debug(f"Features file output lines: {len(output_lines)}") |
| 46 | + |
| 47 | + # Use the second line if available, otherwise first line |
| 48 | + if len(output_lines) > 1 and output_lines[1].strip(): |
| 49 | + features_line = output_lines[1] |
| 50 | + else: |
| 51 | + features_line = output_lines[0] |
| 52 | + test.log.debug(f"Using features line: {features_line}") |
| 53 | + |
| 54 | + if len(features_line) <= 34: |
| 55 | + test.fail(f"Features line too short: {len(features_line)} chars, need at least 35 for bit 34") |
| 56 | + |
| 57 | + packed_bit = features_line[34] |
| 58 | + test.log.debug(f"Packed bit: {packed_bit}") |
| 59 | + |
| 60 | + if packed_bit == expected_packed_bit: |
| 61 | + test.log.debug("Packed bit check: PASS") |
| 62 | + else: |
| 63 | + test.fail(f"Expected packed bit {expected_packed_bit}, but got {packed_bit}") |
| 64 | + |
| 65 | + |
| 66 | +def check_multiqueue_settings(session, expected_queue_count, test): |
| 67 | + """ |
| 68 | + Check multiqueue settings on the VM using utils_net.get_channel_info |
| 69 | +
|
| 70 | + :param session: VM session |
| 71 | + :param expected_queue_count: Expected number of queues |
| 72 | + :param test: Test instance |
| 73 | + """ |
| 74 | + test.log.debug("Checking multiqueue settings...") |
| 75 | + # Get the network interface name |
| 76 | + vm_iface = interface_base.get_vm_iface(session) |
| 77 | + test.log.debug(f"VM interface: {vm_iface}") |
| 78 | + |
| 79 | + # Use utils_net.get_channel_info to get channel information |
| 80 | + maximum_channels, current_channels = utils_net.get_channel_info(session, vm_iface) |
| 81 | + test.log.debug(f"Maximum channels: {maximum_channels}") |
| 82 | + test.log.debug(f"Current channels: {current_channels}") |
| 83 | + |
| 84 | + # Check Combined queue count |
| 85 | + max_combined = int(maximum_channels.get("Combined", "0")) |
| 86 | + current_combined = int(current_channels.get("Combined", "0")) |
| 87 | + |
| 88 | + if max_combined == expected_queue_count and current_combined == expected_queue_count: |
| 89 | + test.log.debug("Multiqueue settings check: PASS") |
| 90 | + else: |
| 91 | + test.fail(f"Expected {expected_queue_count} queues, but got max: {max_combined}, current: {current_combined}") |
| 92 | + |
| 93 | + |
| 94 | +def run(test, params, env): |
| 95 | + """ |
| 96 | + Test 'driver' element with 'packed' attribute of interface |
| 97 | + """ |
| 98 | + |
| 99 | + vm_name = params.get('main_vm') |
| 100 | + vm = env.get_vm(vm_name) |
| 101 | + outside_ip = params.get('outside_ip') |
| 102 | + vcpu_num = params.get('vcpu_num', '4') |
| 103 | + iface_attrs = eval(params.get('iface_attrs', '{}')) |
| 104 | + packed_check = params.get('packed_check', 'no') == 'yes' |
| 105 | + expected_packed_bit = params.get('expected_packed_bit', '1') |
| 106 | + check_multiqueue = params.get('check_multiqueue', 'no') == 'yes' |
| 107 | + expected_queue_count = int(params.get('expected_queue_count', '4')) |
| 108 | + |
| 109 | + vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) |
| 110 | + bkxml = vmxml.copy() |
| 111 | + |
| 112 | + try: |
| 113 | + # Set CPU count |
| 114 | + vmxml.vcpu = int(vcpu_num) |
| 115 | + vmxml.placement = 'static' |
| 116 | + |
| 117 | + # Remove existing interfaces and add new one with packed virtqueue |
| 118 | + vmxml.del_device('interface', by_tag=True) |
| 119 | + libvirt_vmxml.modify_vm_device(vmxml, 'interface', iface_attrs) |
| 120 | + test.log.debug(f'VMXML of {vm_name}:\n{virsh.dumpxml(vm_name).stdout_text}') |
| 121 | + |
| 122 | + # Start VM |
| 123 | + vm.start() |
| 124 | + virsh.domiflist(vm_name, **VIRSH_ARGS) |
| 125 | + iflist = libvirt.get_interface_details(vm_name) |
| 126 | + test.log.debug(f'iface attrs of vm: {iflist}') |
| 127 | + |
| 128 | + # Login to VM and run tests |
| 129 | + session = vm.wait_for_serial_login() |
| 130 | + |
| 131 | + test.log.debug("Test Step 1: Check network connectivity") |
| 132 | + vm_iface = interface_base.get_vm_iface(session) |
| 133 | + test.log.debug(f"VM interface: {vm_iface}") |
| 134 | + |
| 135 | + ips = {'outside_ip': outside_ip} |
| 136 | + network_base.ping_check(params, ips, session, force_ipv4=True) |
| 137 | + test.log.debug("Network connectivity test: PASS") |
| 138 | + |
| 139 | + test.log.debug("Test Step 2: Check packed virtqueue configuration") |
| 140 | + if packed_check: |
| 141 | + check_packed_virtqueue(session, expected_packed_bit, test) |
| 142 | + |
| 143 | + test.log.debug("Test Step 3: Check multiqueue settings") |
| 144 | + if check_multiqueue: |
| 145 | + check_multiqueue_settings(session, expected_queue_count, test) |
| 146 | + |
| 147 | + session.close() |
| 148 | + |
| 149 | + finally: |
| 150 | + test.log.debug("Clean up the env") |
| 151 | + bkxml.sync() |
0 commit comments