Skip to content

Commit

Permalink
PCIe, Slots in pcie-root numbered [1,31]
Browse files Browse the repository at this point in the history
This commit adds automation of tests where pcie-root-port controllers
should have target with slot numbered from 1 to 31 (in hexadecimal
numbers).

VIRT-55414
  • Loading branch information
Vaclav Hodina committed Feb 15, 2023
1 parent 5e957e3 commit d4f1d32
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
17 changes: 17 additions & 0 deletions libvirt/tests/cfg/controller/pcie_root_port_controller.cfg
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
- pcie_root_port_controller:
type = pcie_root_port_controller
start_vm = "no"
controller_type = "pci"
controller_model = "pcie-root-port"
controller_target = '{"chassis":1,"port":"0x8"}'
slot_equal_after_define = "yes"
variants:
- positive_test:
status_error = "no"
variants:
- controllers_different_chassis_same_port:
second_controller_model = "pcie-root-port"
second_controller_target = "{'chassis':2,'port':'0x8'}"
- address_slot_too_low:
test_define_only = "yes"
controller_address = '{"type": "pci", "domain": "0x0000", "bus": "0x00", "slot": "0x00", "function":"0x0"}'
slot_equal_after_define = "no"
- address_slot_min_value:
test_define_only = "yes"
controller_address = '{"type": "pci", "domain": "0x0000", "bus": "0x00", "slot": "0x01", "function":"0x0"}'
- address_slot_max_value:
test_define_only = "yes"
controller_type = "sata"
controller_model = ""
controller_address = '{"type": "pci", "domain": "0x0000", "bus": "0x02", "slot": "0x1f", "function":"0x02"}'
- negative_test:
status_error = "yes"
variants:
Expand Down Expand Up @@ -54,3 +68,6 @@
test_define_only = "yes"
controller_index = xxx
failure_message = "Invalid value for attribute 'index' in element 'controller': 'xxx'. Expected integer value|internal error: Cannot parse controller index xxx"
- address_slot_too_high:
test_define_only = "yes"
controller_address = '{"type": "pci", "domain": "0x0000", "bus": "0x02", "slot": "0x20", "function":"0x0"}'
41 changes: 32 additions & 9 deletions libvirt/tests/src/controller/pcie_root_port_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def setup_test(params):
:param params: Test parameters object
"""
controller_type = params.get("controller_type")
controller_model = params.get("controller_model")
controller_target = ast.literal_eval(params.get("controller_target"))
controller_index = params.get("controller_index", 0)
Expand All @@ -35,12 +36,13 @@ def setup_test(params):
return

index += 1
contr_dict = create_controller_dict(controller_model, controller_target, index)
contr_dict = create_controller_dict(controller_type, controller_model,
controller_target, index)
libvirt_vmxml.modify_vm_device(vmxml, "controller", contr_dict, index)

if second_controller_model and second_controller_target:
index += 1
contr_dict = create_controller_dict(second_controller_model,
contr_dict = create_controller_dict(controller_type, second_controller_model,
second_controller_target, index)
libvirt_vmxml.modify_vm_device(vmxml, "controller", contr_dict, index)

Expand All @@ -58,12 +60,12 @@ def execute_test(vm, test, params):
test_define_only = params.get("test_define_only") == "yes"
if test_define_only:
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name)
check_define_vm(vmxml, params)
check_define_vm(vmxml, test, params)
else:
check_vm_start(vm, params)


def create_controller_dict(model, target, index, address=None):
def create_controller_dict(controller_type, model, target, index, address=None):
"""
Creates a dictionary for PCI controller.
Expand All @@ -73,16 +75,18 @@ def create_controller_dict(model, target, index, address=None):
:param address: Dict, optional, device address example: {'attrs': {'bus': 0x01}}
:returns Built in dictionary, prepared to be added to VM XML
"""
contr_dict = {'type': 'pci',
'model': model,
"index": index,
'target': target}
contr_dict = {'type': controller_type,
"index": index}
if target:
contr_dict.update({"target": model})
if model:
contr_dict.update({"model": model})
if address:
contr_dict.update({"address": address})
return contr_dict


def check_define_vm(vmxml, params):
def check_define_vm(vmxml, test, params):
"""
Alternate function for checking and finishing the test.
Checks only if VM define action was successful instead of VM start.
Expand All @@ -105,6 +109,10 @@ def check_define_vm(vmxml, params):
index = get_controller_index(vmxml, params)
if address:
address["bus"] = hex(index + bus_offset)
slot_equal_after_define= params.get("slot_equal_after_define", "yes") == "yes"
max_indexes = libvirt_pcicontr.get_max_contr_indexes(vmxml, 'pci', model, 1)
index = max_indexes[0] + 1
address["bus"] = hex(index + bus_offset)
contr_dict = {'controller_type': 'pci',
'controller_model': model,
"controller_index": index,
Expand All @@ -123,6 +131,21 @@ def check_define_vm(vmxml, params):
libvirt.check_result(cmd_result, [failure_message])
else:
libvirt.check_exit_status(cmd_result, status_error)
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(
params.get("main_vm", "avocado-vt-vm1"))
expected_value = address["slot"]
if not check_slot_in_controller(vmxml, index, expected_value,
slot_equal_after_define):
test.fail("Controller slot doesn't have the expected value of %s.", expected_value)


def check_slot_in_controller(vmxml, device_index, expected_value, expected_equal=True):
controllers = vmxml.get_devices("controller")
device = controllers[device_index]
print("vh" + str(device))
if expected_equal:
return device["controller_addr"]["slot"] == expected_value
return device.controller_addr.slot != expected_value


def get_controller_index(vmxml, params):
Expand Down

0 comments on commit d4f1d32

Please sign in to comment.