virttest.qemu_devices package¶
Submodules¶
virttest.qemu_devices.qbuses module¶
Autotest representations of qemu buses.
These classes emulates the usual qemu buses behaviors in order to create or match the autotest params into qemu qdev structure.
copyright: | 2012-2013 Red Hat Inc. |
---|
-
class
virttest.qemu_devices.qbuses.
QAHCIBus
(busid, aobject=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QBusUnitBus
AHCI bus (ich9-ahci, ahci)
-
class
virttest.qemu_devices.qbuses.
QBusUnitBus
(busid, bus_type, lengths, aobject=None, atype=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QDenseBus
Implementation of bus-unit bus (ahci, ide)
-
class
virttest.qemu_devices.qbuses.
QDenseBus
(bus_item, addr_spec, busid, bus_type=None, aobject=None, atype=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QSparseBus
Dense bus representation. The only difference from SparseBus is the output string format. DenseBus iterates over all addresses and show free slots too. SparseBus on the other hand prints always the device address.
-
class
virttest.qemu_devices.qbuses.
QDriveBus
(busid, aobject=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QSparseBus
QDrive bus representation (single slot, drive=...)
-
class
virttest.qemu_devices.qbuses.
QFloppyBus
(busid, aobject=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QDenseBus
Floppy bus (-global isa-fdc.drive?=$drive)
-
class
virttest.qemu_devices.qbuses.
QIDEBus
(busid, aobject=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QBusUnitBus
IDE bus (piix3-ide)
-
class
virttest.qemu_devices.qbuses.
QNoAddrCustomBus
(bus_item, addr_spec, busid, bus_type=None, aobject=None, atype=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QSparseBus
This is the opposite of QStrictCustomBus. Even when addr is set it’s not updated in the device’s params.
-
class
virttest.qemu_devices.qbuses.
QOldFloppyBus
(busid, aobject=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QDenseBus
Floppy bus (-drive index=n)
-
class
virttest.qemu_devices.qbuses.
QPCIBus
(busid, bus_type, aobject=None, length=32, first_port=0)[source]¶ Bases:
virttest.qemu_devices.qbuses.QSparseBus
PCI Bus representation (bus&addr, uses hex digits)
-
class
virttest.qemu_devices.qbuses.
QPCISwitchBus
(busid, bus_type, downstream_type, aobject=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QPCIBus
PCI Switch bus representation (creates downstream device while inserting a device).
-
class
virttest.qemu_devices.qbuses.
QSCSIBus
(busid, bus_type, addr_spec, aobject=None, atype=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QSparseBus
SCSI bus representation (bus + 2 leves, don’t iterate over lun by default)
-
class
virttest.qemu_devices.qbuses.
QSparseBus
(bus_item, addr_spec, busid, bus_type=None, aobject=None, atype=None)[source]¶ Bases:
object
Universal bus representation object.
It creates an abstraction of the way how buses works in qemu. Additionally it can store incorrect records (out-of-range addr, multiple devs, ...). Everything with bad* prefix means it concerns the bad records (badbus).
You can insert and remove device to certain address, address ranges or let the bus assign first free address. The order of addr_spec does matter since the last item is incremented first.
There are 3 different address representation used:
- stor_addr
- stored address representation ‘$first-$second-...-$ZZZ’
- addr
- internal address representation [$first, $second, ..., $ZZZ]
- device_addr
- qemu address stored into separate device params (bus, port) device{$param1:$first, $param2:$second, ..., $paramZZZ, $ZZZ}
Note: When you insert a device, it’s properties might be updated (addr,..) -
get
(item)[source]¶ Parameters: item – autotest id or QObject-like object Returns: First matching object from this bus or None
-
get_free_slot
(addr_pattern)[source]¶ Finds unoccupied address
Parameters: addr_pattern – Address pattern (full qualified or with Nones) Returns: First free address when found, (free or reserved for this dev) None when no free address is found, (all occupied) False in case of incorrect address (oor)
-
insert
(device, strict_mode=False)[source]¶ Insert device into this bus representation.
Parameters: - device – qdevices.QBaseDevice device
- strict_mode – Use strict mode (set optional params)
Returns: list of added devices on success, string indicating the failure on failure.
-
match_bus
(bus_spec, type_test=True)[source]¶ Check if the bus matches the bus_specification. :param bus_spec: Bus specification :type bus_spec: dict :param type_test: Match only type :type type_test: bool :return: True when the bus matches the specification :rtype: bool
-
remove
(device)[source]¶ Remove device from this bus :param device: qdevices.QBaseDevice device :return: True when removed, False when the device wasn’t found
-
class
virttest.qemu_devices.qbuses.
QStrictCustomBus
(bus_item, addr_spec, busid, bus_type=None, aobject=None, atype=None, first_port=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QSparseBus
Similar to QSparseBus. The address starts with 1 and addr is always set
-
class
virttest.qemu_devices.qbuses.
QUSBBus
(length, busid, bus_type, aobject=None, port_prefix=None)[source]¶ Bases:
virttest.qemu_devices.qbuses.QSparseBus
USB bus representation including usb-hub handling.
virttest.qemu_devices.qcontainer module¶
Autotest qdev-structure representation.
This is the main class which represent qdev-structure. It allows to create, interact and verify the qemu qdev structure.
copyright: | 2012-2013 Red Hat Inc. |
---|
-
class
virttest.qemu_devices.qcontainer.
DevContainer
(qemu_binary, vmname, strict_mode='no', workaround_qemu_qmp_crash='no', allow_hotplugged_vm='yes')[source]¶ Bases:
object
Device container class
-
cdroms_define_by_params
(name, image_params, media=None, index=None, image_boot=None, image_bootindex=None)[source]¶ Wrapper for creating cdrom and related hbas from autotest image params.
Note: To skip the argument use None, to disable it use False
Note: Strictly bool options accept “yes”, “on” and True (“no”...)
Note: Options starting with ‘_’ are optional and used only when strict_mode is True
Parameters: - name – Name of the new disk
- params – Disk params (params.object_params(name))
-
cmdline
(dynamic=True)[source]¶ Creates cmdline arguments for creating all defined devices :return: cmdline of all devices (without qemu-cmd itself)
-
execute_qemu
(options, timeout=5)[source]¶ Execute this qemu and return the stdout+stderr output. :param options: additional qemu options :type options: string :param timeout: execution timeout :type timeout: int :return: Output of the qemu :rtype: string
-
get
(item)[source]¶ Parameters: item – autotest id or QObject-like object Returns: First matching object defined in this QDevContainer or None
-
get_buses
(bus_spec, type_test=False)[source]¶ Parameters: Returns: All matching buses
Return type: List of QSparseBus
-
get_by_params
(filt)[source]¶ Return list of matching devices :param filt: filter {‘param’: ‘value’, ...} :type filt: dict
-
get_by_properties
(filt)[source]¶ Return list of matching devices :param filt: filter {‘property’: ‘value’, ...} :type filt: dict
-
get_first_free_bus
(bus_spec, addr)[source]¶ Parameters: - bus_spec – Bus specification (dictionary)
- addr – Desired address
Returns: First matching bus with free desired address (the latest added matching bus)
-
has_device
(device)[source]¶ Parameters: device – Desired device Returns: Is the desired device supported by current qemu?
-
has_hmp_cmd
(cmd)[source]¶ Parameters: cmd – Desired command Returns: Is the desired command supported by this qemu’s human monitor?
-
has_option
(option)[source]¶ Parameters: option – Desired option Returns: Is the desired option supported by current qemu?
-
has_qmp_cmd
(cmd)[source]¶ Parameters: cmd – Desired command Returns: Is the desired command supported by this qemu’s QMP monitor?
-
hotplug_verified
()[source]¶ This function should be used after you verify, that hotplug was successful. For each hotplug call, hotplug_verified have to be executed in order to mark VM as clear.
Warning: If you can’t verify, that hotplug was successful, don’t use this function! You could screw-up following tests.
-
idx_of_next_named_bus
(bus_pattern)[source]¶ Parameters: bus_pattern – Bus name prefix without %s and tailing digit Returns: Name of the next bus (integer is appended and incremented until there is no existing bus).
-
images_define_by_params
(name, image_params, media=None, index=None, image_boot=None, image_bootindex=None)[source]¶ Wrapper for creating disks and related hbas from autotest image params.
Note: To skip the argument use None, to disable it use False
Note: Strictly bool options accept “yes”, “on” and True (“no”...)
Note: Options starting with ‘_’ are optional and used only when strict_mode is True
Parameters: - name – Name of the new disk
- params – Disk params (params.object_params(name))
-
images_define_by_variables
(name, filename, index=None, fmt=None, cache=None, werror=None, rerror=None, serial=None, snapshot=None, boot=None, blkdebug=None, bus=None, unit=None, port=None, bootindex=None, removable=None, min_io_size=None, opt_io_size=None, physical_block_size=None, logical_block_size=None, readonly=None, scsiid=None, lun=None, aio=None, strict_mode=None, media=None, imgfmt=None, pci_addr=None, scsi_hba=None, x_data_plane=None, blk_extra_params=None, scsi=None, pci_bus='pci.0', drv_extra_params=None, num_queues=None, bus_extra_params=None, force_fmt=None)[source]¶ Creates related devices by variables :note: To skip the argument use None, to disable it use False :note: Strictly bool options accept “yes”, “on” and True (“no”...) :param name: Autotest name of this disk :param filename: Path to the disk file :param index: drive index (used for generating names) :param fmt: drive subsystem type (ide, scsi, virtio, usb2, ...) :param force_fmt: Force to use specific drive format :param cache: disk cache (none, writethrough, writeback) :param werror: What to do when write error occurs (stop, ...) :param rerror: What to do when read error occurs (stop, ...) :param serial: drive serial number ($string) :param snapshot: use snapshot? ($bool) :param boot: is bootable? ($bool) :param blkdebug: use blkdebug (None, blkdebug_filename) :param bus: 1st level of disk location (index of bus) ($int) :param unit: 2nd level of disk location (unit/scsiid/...) ($int) :param port: 3rd level of disk location (port/lun/...) ($int) :param bootindex: device boot priority ($int) :param removable: can the drive be removed? ($bool) :param min_io_size: Min allowed io size :param opt_io_size: Optimal io size :param physical_block_size: set physical_block_size ($int) :param logical_block_size: set logical_block_size ($int) :param readonly: set the drive readonly ($bool) :param scsiid: Deprecated 2nd level of disk location (&unit) :param lun: Deprecated 3rd level of disk location (&port) :param aio: set the type of async IO (native, threads, ..) :param strict_mode: enforce optional parameters (address, ...) ($bool) :param media: type of the media (disk, cdrom, ...) :param imgfmt: image format (qcow2, raw, ...) :param pci_addr: drive pci address ($int) :param scsi_hba: Custom scsi HBA :param num_queues: performace option for virtio-scsi-pci :param bus_extra_params: options want to add to virtio-scsi-pci bus
-
insert
(devices, strict_mode=None)[source]¶ Inserts devices into this VM representation :param devices: List of qdevices.QBaseDevice devices :raise DeviceError: On failure. The representation remains unchanged.
-
list_missing_named_buses
(bus_pattern, bus_type, bus_count)[source]¶ Parameters: - bus_pattern – Bus name pattern with 1x%s for idx or %s is appended in the end. (‘mybuses’ or ‘my%sbus’).
- bus_type – Type of the bus.
- bus_count – Desired number of buses.
Returns: List of buses, which are missing in range(bus_count)
-
machine_by_params
(params=None)[source]¶ Choose the used machine and set the default devices accordingly :param params: VM params :return: List of added devices (including default buses)
-
pcic_by_params
(name, params)[source]¶ Creates pci controller/switch/... based on params
Parameters: - name – Autotest name
- params – PCI controller params
Note: x3130 creates x3130-upstream bus + xio3130-downstream port for each inserted device.
Warning: x3130-upstream device creates only x3130-upstream device and you are responsible for creating the downstream ports.
-
remove
(device, recursive=True)[source]¶ Remove device from this representation :param device: autotest id or QObject-like object :param recursive: remove children recursively :return: None on success, -1 when the device is not present
-
simple_hotplug
(device, monitor)[source]¶ Function hotplug device to devices representation. If verification is supported by hodplugged device and result of verification is True then it calls set_clean. Otherwise it don’t call set_clean because devices representatio don’t know if device is added correctly.
Parameters: - device (string, qdevices.QDevice.) – Device which should be unplugged.
- monitor (qemu_monitor.Monitor) – Monitor from vm.
Returns: tuple(monitor.cmd(), verify_hotplug output)
-
simple_unplug
(device, monitor)[source]¶ Function unplug device to devices representation. If verification is supported by unplugged device and result of verification is True then it calls set_clean. Otherwise it don’t call set_clean because devices representatio don’t know if device is added correctly.
Parameters: - device (string, qdevices.QDevice.) – Device which should be unplugged.
- monitor (qemu_monitor.Monitor) – Monitor from vm.
Returns: tuple(monitor.cmd(), verify_unplug output)
-
usb_by_params
(usb_name, params)[source]¶ Wrapper for creating usb devices from autotest params. :param usb_name: Name of the usb :param params: USB device’s params :return: QDev device
-
usb_by_variables
(usb_name, usb_type, controller_type, bus=None, port=None)[source]¶ Creates usb-devices by variables. :param usb_name: usb name :param usb_type: usb type (usb-tablet, usb-serial, ...) :param controller_type: type of the controller (uhci, ehci, xhci, ...) :param bus: the bus name (my_bus.0, ...) :param port: port specifiacation (4, 4.1.2, ...) :return: QDev device
-
usbc_by_params
(usb_name, params)[source]¶ Wrapper for creating usb bus from autotest usb params. :param usb_name: Name of the usb bus :param params: USB params (params.object_params(usb_name)) :return: List of QDev devices
-
usbc_by_variables
(usb_id, usb_type, multifunction=False, masterbus=None, firstport=None, freq=None, max_ports=6, pci_addr=None, pci_bus='pci.0')[source]¶ Creates usb-controller devices by variables :param usb_id: Usb bus name :param usb_type: Usb bus type :param multifunction: Is the bus multifunction :param masterbus: Is this bus master? :param firstport: Offset of the first port :param freq: Bus frequency :param max_ports: How many ports this bus have [6] :param pci_addr: Desired PCI address :return: List of QDev devices
-
virttest.qemu_devices.qdevices module¶
Autotest representation of qemu devices.
These classes implements various features in order to simulate, verify or interact with qemu qdev structure.
copyright: | 2012-2013 Red Hat Inc. |
---|
-
class
virttest.qemu_devices.qdevices.
QBaseDevice
(dev_type='QBaseDevice', params=None, aobject=None, parent_bus=None, child_bus=None)[source]¶ Bases:
object
Base class of qemu objects
-
add_child_bus
(bus)[source]¶ Add child bus :param bus: Bus, which this device contains :type bus: QSparseBus-like
-
cmdline_nd
()[source]¶ Command line without dynamic params.
Returns: cmdline command to define this device without dynamic parameters
-
rm_child_bus
(bus)[source]¶ removes child bus :param bus: Bus, which this device contains :type bus: QSparseBus-like
-
set_param
(option, value, option_type=None, dynamic=False)[source]¶ Set device param using qemu notation (“on”, “off” instead of bool...) :param option: which option’s value to set :param value: new value :param option_type: type of the option (bool) :param dynamic: if true value is changed to DYN for not_dynamic compare
-
-
class
virttest.qemu_devices.qdevices.
QCustomDevice
(dev_type, params=None, aobject=None, parent_bus=None, child_bus=None, backend=None)[source]¶ Bases:
virttest.qemu_devices.qdevices.QBaseDevice
Representation of the ‘-$option $param1=$value1,$param2...’ qemu object. This representation handles only cmdline.
-
class
virttest.qemu_devices.qdevices.
QDevice
(driver=None, params=None, aobject=None, parent_bus=None, child_bus=None)[source]¶ Bases:
virttest.qemu_devices.qdevices.QCustomDevice
Representation of the ‘-device’ qemu object. It supports all methods. :note: Use driver format in full form - ‘driver’ = ‘...’ (usb-ehci, ide-hd)
-
class
virttest.qemu_devices.qdevices.
QDrive
(aobject, use_device=True)[source]¶ Bases:
virttest.qemu_devices.qdevices.QCustomDevice
Representation of the ‘-drive’ qemu object without hotplug support.
-
set_param
(option, value, option_type=None)[source]¶ Set device param using qemu notation (“on”, “off” instead of bool...) It restricts setting of the ‘id’ param as it’s automatically created. :param option: which option’s value to set :param value: new value :param option_type: type of the option (bool)
-
-
class
virttest.qemu_devices.qdevices.
QFloppy
(unit=None, drive=None, aobject=None, parent_bus=None, child_bus=None)[source]¶ Bases:
virttest.qemu_devices.qdevices.QGlobal
Imitation of qemu floppy disk defined by -global isa-fdc.drive?=$drive
-
class
virttest.qemu_devices.qdevices.
QGlobal
(driver, prop, value, aobject=None, parent_bus=None, child_bus=None)[source]¶ Bases:
virttest.qemu_devices.qdevices.QBaseDevice
Representation of qemu global setting (-global driver.property=value)
-
class
virttest.qemu_devices.qdevices.
QHPDrive
(aobject)[source]¶ Bases:
virttest.qemu_devices.qdevices.QDrive
Representation of the ‘-drive’ qemu object with hotplug support.
-
class
virttest.qemu_devices.qdevices.
QOldDrive
(aobject, use_device=True)[source]¶ Bases:
virttest.qemu_devices.qdevices.QDrive
This is a variant for -drive without ‘addr’ support
-
class
virttest.qemu_devices.qdevices.
QRHDrive
(aobject)[source]¶ Bases:
virttest.qemu_devices.qdevices.QDrive
Representation of the ‘-drive’ qemu object with RedHat hotplug support.
-
class
virttest.qemu_devices.qdevices.
QStringDevice
(dev_type='dummy', params=None, aobject=None, parent_bus=None, child_bus=None, cmdline='', cmdline_nd=None)[source]¶ Bases:
virttest.qemu_devices.qdevices.QBaseDevice
General device which allows to specify methods by fixed or parametrizable strings in this format:
"%(type)s,id=%(id)s,addr=%(addr)s"
params
will be used to subst%()s
virttest.qemu_devices.utils module¶
Shared classes and functions (exceptions, ...)
copyright: | 2013 Red Hat Inc. |
---|
-
exception
virttest.qemu_devices.utils.
DeviceError
[source]¶ Bases:
exceptions.Exception
General device exception
-
exception
virttest.qemu_devices.utils.
DeviceHotplugError
(device, reason, vmdev)[source]¶ Bases:
virttest.qemu_devices.utils.DeviceInsertError
Fail to hotplug device
-
exception
virttest.qemu_devices.utils.
DeviceInsertError
(device, reason, vmdev)[source]¶ Bases:
virttest.qemu_devices.utils.DeviceError
Fail to insert device
-
exception
virttest.qemu_devices.utils.
DeviceRemoveError
(device, reason, vmdev)[source]¶ Bases:
virttest.qemu_devices.utils.DeviceInsertError
Fail to remove device
-
exception
virttest.qemu_devices.utils.
DeviceUnplugError
(device, reason, vmdev)[source]¶ Bases:
virttest.qemu_devices.utils.DeviceHotplugError
Fail to unplug device