示例#1
0
def create_hostdev_xml(adapter_name="", **kwargs):
    """
    Create vhba hostdev xml.

    :param adapter_name: The name of the scsi adapter
    :param kwargs: Could contain addr_bus, addr_target,
     addr_unit, mode, and managed
    :return: a xml object set by kwargs
    """
    addr_bus = kwargs.get('addr_bus', 0)
    addr_target = kwargs.get('addr_target', 0)
    addr_unit = kwargs.get('addr_unit', 0)
    mode = kwargs.get('mode', 'subsystem')
    managed = kwargs.get('managed', 'no')

    hostdev_xml = hostdev.Hostdev()
    hostdev_xml.type = "scsi"
    hostdev_xml.managed = managed
    hostdev_xml.mode = mode

    source_args = {}
    source_args['adapter_name'] = adapter_name
    source_args['bus'] = addr_bus
    source_args['target'] = addr_target
    source_args['unit'] = addr_unit
    hostdev_xml.source = hostdev_xml.new_source(**source_args)
    LOG.info(hostdev_xml)
    return hostdev_xml
def create_hostdev_device(hostdev_dict):
    """
    Create Hostdev device

    :param hostdev_dict: Dict, attrs of Hostdev
    :return: Object of Hostdev device
    """
    host_dev = hostdev.Hostdev()
    host_dev.setup_attrs(**hostdev_dict)

    return host_dev
示例#3
0
def create_hostdev(hostdev_dict):
    """
    Create hostdev device

    :param hostdev_dict: Dict, attrs of hostdev
    :return: hostdev device object
    """
    hostdev_dev = hostdev.Hostdev()
    hostdev_dev.setup_attrs(**hostdev_dict)

    logging.debug("Hostdev XML: %s", hostdev_dev)
    return hostdev_dev
示例#4
0
    def prepare_hostdev_xml(**kwargs):
        """
        Prepare the scsi device's xml

        :param kwargs: The arguments to generate scsi host device xml.
        :return: The xml of the scsi host device.
        """
        hostdev_xml = hostdev.Hostdev()
        hostdev_xml.type = "scsi"
        if kwargs.get("managed"):
            hostdev_xml.managed = kwargs.get("managed")
        hostdev_xml.mode = kwargs.get("mode", "subsystem")
        if kwargs.get("sgio"):
            hostdev_xml.sgio = kwargs.get("sgio")
        if kwargs.get("rawio"):
            hostdev_xml.rawio = kwargs.get("rawio")
        hostdev_xml.readonly = "yes" == kwargs.get("readonly")
        hostdev_xml.shareable = "yes" == kwargs.get("shareable")

        source_args = {}
        source_protocol = kwargs.get("source_protocol")
        if source_protocol == "iscsi":
            # Use iscsi lun directly
            source_args['protocol'] = "iscsi"
            source_args['host_name'] = kwargs.get("iscsi_host", "ISCSI_HOST")
            source_args['host_port'] = kwargs.get("iscsi_port", "ISCSI_PORT")
            source_args['source_name'] = kwargs.get("iqn_name", "IQN_NAME")
            source_args['auth_user'] = kwargs.get("auth_user")
            source_args['secret_type'] = kwargs.get("secret_type")
            source_args['secret_uuid'] = kwargs.get("secret_uuid")
            source_args['secret_usage'] = kwargs.get("secret_usage")
            source_args['iqn_id'] = kwargs.get("iqn_id")
        elif source_protocol:
            test.cancel("We do not support source protocol = %s yet" %
                        source_protocol)
        else:
            # Use local scsi device
            source_args['adapter_name'] = kwargs.get("adapter_name",
                                                     "scsi_host999")
            source_args['bus'] = kwargs.get("addr_bus", "0")
            source_args['target'] = kwargs.get('addr_target', "0")
            source_args['unit'] = kwargs.get('addr_unit', "0")
        # If any attributes not used, remove them from source dict to avoid
        # attr="" or attr="None" situation.
        for key, value in list(source_args.items()):
            if not value:
                source_args.pop(key)
        hostdev_xml.source = hostdev_xml.new_source(**source_args)
        logging.info("hostdev xml is: %s", hostdev_xml)
        return hostdev_xml
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()