def run(test, params, env): ''' 1. Check if the crypto device in host valiable for passthrough 2. Passthrough the crypto device 2. Create the mdev 3. Confirm the mdev was created successfully 4. Confirm device availability in guest 5. Destroy the mdev 6. Confirm the mdev was destroyed successfully NOTE: It can take a while after loading vfio_ap for the matrix device to become available due to current performance issues with the API if there are several mdev definitions already available. The test supposes no other mdev devices have been defined yet in order to avoid complexity in the test code. :param test: test object :param params: Dict with test parameters :param env: Dict with the test environment :return: ''' libvirt_version.is_libvirt_feature_supported(params) matrix_cap = 'ap_matrix' device_file = None mask_helper = None info = CryptoDeviceInfoBuilder.get() if int(info.entries[0].hwtype) < HWTYPE: test.cancel("vfio-ap requires HWTYPE bigger than %s." % HWTYPE) uuid = str(uuid1()) adapter = info.entries[0].card domain = info.entries[1].domain try: if not find_devices_by_cap(test, matrix_cap): load_vfio_ap() if find_devices_by_cap(test, matrix_cap): devices = [info.domains[0]] mask_helper = APMaskHelper.from_infos(devices) device_file = create_nodedev_from_xml(uuid, adapter, domain) else: raise test.fail("Could not get %s correctly through nodedev-API" % matrix_cap) check_device_was_created(test, uuid, adapter, domain) # the test assumes there's no other mdev dev_name = find_devices_by_cap(test, 'mdev')[0] destroy_nodedev(dev_name) check_device_was_destroyed(test) finally: if mask_helper: mask_helper.return_to_host_all() unload_vfio_ap() if device_file: os.remove(device_file)
def run(test, params, env): ''' 1. Check if the crypto device in host valiable for passthrough 2. Passthrough the crypto device 2. Create the mdev 3. Confirm the mdev was created successfully 4. Confirm device availability in guest 5. Destroy the mdev 6. Confirm the mdev was destroyed successfully :param test: test object :param params: Dict with test parameters :param env: Dict with the test environment :return: ''' libvirt_version.is_libvirt_feature_supported(params) matrix_cap = 'ap_matrix' device_file = None info = CryptoDeviceInfoBuilder.get() if int(info.entries[0].hwtype) < HWTYPE: test.cancel("vfio-ap requires HWTYPE bigger than %s." % HWTYPE) uuid = str(uuid1()) adapter = info.entries[0].card domain = info.entries[1].domain try: if not find_devices_by_cap(test, matrix_cap): load_vfio_ap() if find_devices_by_cap(test, matrix_cap): devices = [info.domains[0]] APMaskHelper.from_infos(devices) device_file = create_nodedev_from_xml(uuid, adapter, domain) else: raise test.fail("Could not get %s correctly through nodedev-API" % matrix_cap) check_device_was_created(test, uuid, adapter, domain) # the test assumes there's no other mdev dev_name = find_devices_by_cap(test, 'mdev')[0] destroy_nodedev(dev_name) check_device_was_destroyed(test) finally: unload_vfio_ap() if device_file: os.remove(device_file)
def run(test, params, env): """ Tests vfio-ap passthrough on s390x 1. Control guest lifecycle for cold- vs. hotplug 2. Set up passthrough attaching new device 3. Confirm device availability in guest """ vm_name = params.get("main_vm") vm = env.get_vm(vm_name) vmxml_backup = VMXML.new_from_inactive_dumpxml(vm_name) plug = params.get("plug") mask_helper = None matrix_dev = None try: if plug == "cold" and vm.is_alive(): vm.destroy() if plug == "hot" and vm.is_dead(): vm.start() vm.wait_for_login() load_vfio_ap() info = CryptoDeviceInfoBuilder.get() if not info.entries or int(info.domains[0].hwtype) < MIN_HWTYPE: test.error("vfio-ap requires at least HWTYPE %s." % MIN_HWTYPE) devices = [info.domains[0]] mask_helper = APMaskHelper.from_infos(devices) matrix_dev = MatrixDevice.from_infos(devices) hostdev_xml = hostdev.Hostdev() hostdev_xml.mode = "subsystem" hostdev_xml.model = "vfio-ap" hostdev_xml.type = "mdev" uuid = matrix_dev.uuid hostdev_xml.source = hostdev_xml.new_source(**{"uuid": uuid}) hostdev_xml.xmltreefile.write() logging.debug("Attaching %s", hostdev_xml.xmltreefile) virsh.attach_device(vm_name, hostdev_xml.xml, flagstr="--current", ignore_status=False) if plug == "cold": vm.start() session = vm.wait_for_login() def verify_passed_through(): guest_info = CryptoDeviceInfoBuilder.get(session) logging.debug("Guest lszcrypt got %s", guest_info) if guest_info.domains: default_driver_on_host = devices[0].driver driver_in_guest = guest_info.domains[0].driver logging.debug( "Expecting default drivers from host and guest" " to be the same: { host: %s, guest: %s }", default_driver_on_host, driver_in_guest) return default_driver_on_host == driver_in_guest return False if not wait_for(verify_passed_through, timeout=60, step=10): test.fail("Crypto domain not attached correctly in guest." " Please, check the test log for details.") finally: vmxml_backup.sync() if matrix_dev: matrix_dev.unassign_all() if mask_helper: mask_helper.return_to_host_all() unload_vfio_ap()