virttest.qemu_vm: Add a new list for supported devices

Other test scripts can use this list directly to check
whether some device is supported by qemu binary.

This patch also moves 'has_device' function in
'make_create_command' method into VM class, so that we
can use this method out of VM class scope.

Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
Qemu Test: pci_hotplug: Update this test case

This patch creates a series of sub functions for device add
action in different version of qemu.

Changes from V1:
 * Fix 'is_support_device' -> 'is_supported_device'.

Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
virttest.qemu_monitor: Add APIs for device hotplug/unplug

This patch adds interfaces for hotplug operation:
 * device_add/device_del: For qemu which has '-device' option.
 * pci_add/pci_del: For some old version of qemu.
 * drive_add/drive_del: For newer qemu which supports drive_add.
 * com_redhat_drive_add/com_redhat_drive_del: For RHEL only.

With these interfaces, test cases writer doesn't need to care
about the verison of qemu.

Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
virttest.qemu_monitor: Verify hmp cmd in qmp as well

Some QMP's interface will fallback to HMP if there is no
match QMP command, this patch checks HMP before calling
HMP cmd in QMP, to avoid some unexpected failure.

Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
virttest.qemu_vm: Add APIs for pci hotplug

This patch brings some interfaces for hotplug in qemu_vm
module, so that user doesn't need to care about monitor
protocol and qemu version.

Changes from v1:
 * Update methods argument type as review comments.

Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
Qemu Test: pci_hotplug: Update this test with new interface

Changes from v1:
 * Update device_add/drive_add API arguments type.

Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
qemu_vm: Log the original traceback when VM.create() failes

* when self.make_create_command() raises an exception in VM.create()
  it's catched and reraised. The problem is that the information about
  actual failed line is lost. This patch logs the original traceback
  and raise VMStartError instead.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
Object representation of qemu devices

This is a first part of new way for creating VM. When it's complete
it should create device representation which allows deeper analysis
of current VM state including additionally hotplugged devices.

Current implementation only takes care of usb buses, usb devices and
block devices (disk, cdrom, floppy) and uses the old way of VM handling.
Each added device only extends the old qemu_cmd variable.

For correct PCI address assignement it inserts dummy string devices for
many devices, which are not yet covered by new classes. They don't
affect the qemu_cmd.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
FIX: use weakrefs on qdev object

Those references prevented garbage collector from removing qdev
object, which resulted in hanging VM and lots of nasty related
hangs.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_vm: Use only qdev for VM creation

This patch removes the old way of device definition. This way we
can't compare the outputs, but we get closer to the speed of which
qdev will work in reality.

It still generates huge output of all devices and buses. It's
there for you to compare, whether the theoretical information
match the actual VM. In the future this might be compared
automatically (similar to qemu_qtree.py but for every device).

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>

Conflicts:
	virttest/qemu_vm.py
virttest.qemu_devices: Add support for compasion

Support qdev comparsion using qdev1 == qdev2 and qdev1 != qdev2.

It uses cmdline, hotplug, unplug and readconfig outputs of all devices
and compares the results. It doesn't require the same names, only same
commands.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Add dirty state of qdev

Add 'dirty' counter for operations, which might invalidate the
VM/qdev state. When the qdev.dirty is non-zero, qdev state
will be ignored and VM automatically recreated.

This is eg. for hotplug operations:
1) qdev.dirty.up()  # signal that nasty operation is in progress
2) vm.hotplug()
3) validate, that everything went OK
4) qdev.insert()  # update the qdev representation
5) qdev.dirty.down()  # VM and qdev are synchronized now

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Use OrderedDict for device params

The order of cmdline depends on the order of the device's params.
By using OrderedDict we can simplify the device's __eq__ comparsion.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
REMOVEME: testing qemu.tests.qdev_example_test

This is example test for hotplug purposes.

Currently it has 4 variants = 4 phases:
1) env_process creates one standard VM and in test it hotplugs
   a stg disk (disk params are taken from params)
2) this test needs VM with stg disk. Env_process compares old
   VM with new params and discovers, that old VM already has
   stg disk and they matches, so it continue executing the test.
3) This test also uses additional disk, but the id doesn't match.
   env_process recreates the VM.
4) In this test env_process also recreates VM as the filenames of
   the additional disk doesn't match.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Add list of hmp/qmp commands

Supported hotplug commands should be known prior to qemu lunch
in order to use the right device class.

There are few versions of qemu which fails when qmp monitor is used
directly after qemu lunch which might negatively impact the list
of supported devices.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Modify ThreadSafeCounter to work with py2.4

Python 2.4 doesn't support with.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Add support for hotplug

Basic idea is that user will use vm.devices.hotplug(device, monitor)
which takes care of everything:
1) marks the VM as invalid
2) tries to add device into qdev representation
3) executes the right monitor command (qmp/hmp)
4) if possible verifies the status
5) if it verifies, that VM is OK marks the VM as valid

If verification fails/is missing the VM state is invalid after hotplug.
It's upto user to call vm.devices.hotplug_verified() which marks
the VM as valid again. If VM is invalid, postprocess shoots the VM down.

The verification will be shown in following patch with device_add.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_devices: Modify QDrive/QDevice's hotplug

This patch shows how devices should be built if more classes exists. The
qdev subsystem should map the correct class in order to work with
the current qemu. There should be supported override eg. for pci_add
version of images since there are cases where we need this version
even when __com.redhat_drive_add is supported.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.qdev_example_test: Hotplug support

modify this test to support hotplug.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>