qemu_monitor.py: increase default timeouts

Based on experience and advice we are increasing the default
timeouts. We have seen non intended failures with the timeouts
as they are. Increasing them makes legit tests (migration ones
in our experience) not fail anymore.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
run: Fix error message displayed when -v is not specified

This is a solution for issue #184.

Create the utility function _restore_stdout, so we
don't need to resort to standalone_utils.print_stdout
on error paths, changing all error paths to use it.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
virt: repair step editor.

Signed-off-by: Jiří Župka <jzupka@redhat.com>
qemu_vm: Making qemu creation module honor cpu_model unconditionally

When we introduced qemu CPU model configuration, we opted
for robustness, so we wouldn't add a cpu_model to the
command line in case it was not showing on qemu -cpu help
text. This is bad because:

1) It was all done very silently
2) This makes negative cpu model testing unfeasible

So let's honor the setting, and print a error message,
so people have a better idea of what's going on. In
such cases, the bad param will be passed to qemu, it
will fail and a VMCreateError will be thrown.

CC: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
qemu_vm: Update testdev option, add -isa-debug-exit option

For qemu upstream, in order to run the kvm-unit-tests suite,
there are new test devices, that differ in syntax from the
ones present in qemu-kvm:

* pc-testdev
* isa-debug-exit

Add them both to the qemu VM class, and make things
backwards compatible (ie, if an older qemu-kvm is being
tested, it'll handle the correct syntaxes as well).

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
qemu: unittests - Handle running on qemu upstream new testdevs

The implementation of the devices needed for KVM unit
testing changed a bit on qemu:

1) There's no need for a testlog anymore (as kvm-unit-tests
   now writes to the standard serial port)
2) Now there's a shared new device, called isa-debug-exit,
   that when written to, causes qemu to exit
3) Due to the new behavior of the isa-debug-exit device,
   the new known good behavior for qemu at the end of the
   unit test is to return 1.

Take that all into account, while still keeping backwards
compatibility. Also, document how one can run the unittests
with the new virt-tests runner both in the config file
and the wiki.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
qemu_vm: Fix enable/disable_kvm option

When we set disable_kvm to 'yes', we obviously don't want
-enable-kvm set regardless of the value of enable_kvm.

So let's fix that. Now you can just set

disable_kvm = yes

And everything else will be taken care of.

CC: Eduardo Habkost <ehabkost@redhat.com>
CC: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
multi_disk: Fix incorrect params

* max_disk must not have any usbs, otherwise there are not enough
  slots in PCI
* default image_boot = yes which generates in multi_disk test
  multiple disks with index = 1 and test failure. By forcing default
  value stg_image_boot = 'no' we can keep the default value (and index
  of image1) and let the other disk to have their own indexes.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virt: Improve DHCP RFC compatibility

Client can suggest IP address which he wants to have.
Autotest check if IP address is accessible, thanks to
it there is no problem with changing of guest network.
Additionally it helps with windows DHCP compatibility.

Signed-off-by: Jiří Župka <jzupka@redhat.com>
qemu_storage: Fix location of the qemu binary

qemu_img can be found on a different location than the
images, in case qemu was compiled from source, so let's
fix the reference to the right path when setting the
binary.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
virt_vm: Change vm.get_cpu_count() to use self.wait_for_login()

Allow calling vm.get_cpu_count() before guest ssh
running. In this case, calling simply vm.login()
would fail.

Signed-off-by: Xiaoqing Wei <xwei@redhat.com>
qemu_vm: Support maxcpus sub option

maxcpus is a sub-option of -smp, so need a Regex to match

Signed-off-by: Xiaoqing Wei <xwei@redhat.com>
virt.virttest.storage: Change the cmp method of the sorted function

Currently, function sorted inside the python was not suitable for
storage, for example, if ls -1d /dev/sd* gets result like this
after split('\n'):
['/dev/sda', '/dev/sda1', '/dev/sda2', '/dev/sda3',
 '/dev/sdaa', '/dev/sdab','/dev/sdac', '/dev/sdad', '/dev/sdae',
 '/dev/sdaf', '/dev/sdag', '/dev/sdah', '/dev/sdai', '/dev/sdaj',
 '/dev/sdak', '/dev/sdal', '/dev/sdam', '/dev/sdan', '/dev/sdao',
 '/dev/sdap', '/dev/sdaq', '/dev/sdar', '/dev/sdas', '/dev/sdb',
 '/dev/sdb1', '/dev/sdb2', '/dev/sdb3', '/dev/sdc', '/dev/sdd',
 '/dev/sde', '/dev/sdf', '/dev/sdg', '/dev/sdg1', '/dev/sdg2',
 '/dev/sdg3', '/dev/sdh', '/dev/sdh1', '/dev/sdh2', '/dev/sdh3',
 '/dev/sdi', '/dev/sdj', '/dev/sdk', '/dev/sdl', '/dev/sdm',
 '/dev/sdn', '/dev/sdo', '/dev/sdp', '/dev/sdq', '/dev/sdr',
 '/dev/sds', '/dev/sdt', '/dev/sdu', '/dev/sdv', '/dev/sdw',
 '/dev/sdx', '/dev/sdy', '/dev/sdz']

it will make no any change if just use sorted. As the default,
it will choose last 9 disk:
['/dev/sdr', '/dev/sds', '/dev/sdt', '/dev/sdu', '/dev/sdv', '/dev/sdw',
 '/dev/sdx', '/dev/sdy', '/dev/sdz']

Sometimes this is very dangerous, for lots of them may be the disk contains
lots of important data. Actually, maybe you just use scsi_debug just create:
['/dev/sdak','/dev/sdal', '/dev/sdam', '/dev/sdan', '/dev/sdao',
 '/dev/sdap', '/dev/sdaq', '/dev/sdar', '/dev/sdas']

But select the wrong disks as mentioned above.

To solve this problem, add param cmp to sorted and get the right order.

Signed-off-by: Mike Qiu <qiudayu@linux.vnet.ibm.com>
virt.shared.cfg.base:Avoid to add more disk in blacklist

Currently, autotest use such as /dev/sda.* to get the disk of
the blacklist, but this will raise an error if the disk 'sdaa'
or some name like this, it's not correct as we just want to add
sda or name like sda1-9 to the blacklist.

change the pattern to /dev/sda[\d]* can avoid this.

Signed-off-by: Mike Qiu<qiudayu@linux.vnet.ibm.com>
virt.virttest.storage:avoid the wrong to raise an error

Currently, it will rase and error when '/dev/sdaa' match the pattern
of the blacklist. This should not be happen as we just want sda sda1
and so on to be in the blacklist.

add one more check to avoid this error.

Signed-off-by: Mike Qiu<qiudayu@linux.vnet.ibm.com>
qemu_vm: Robust but safe method for cpu_model

Iterate over all allowed cpu_models and in case none is supported,
force the last one.

This should suit negative testing and also it should be safer when
using auto_cpu_model.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virt: Implement subdirectory flattening classes

* data_dir.SubdirList class returns a flat-list of all non-hidden
  subdirectories beneath a base directory (inclusive).

* data_dir.SubdirGlobList class returns flat-list of all files
  matching a glob pattern, within all non-hidden subdirectories
  beneath a base directory (inclusive).

Signed-off-by: Chris Evich <cevich@redhat.com>
virt: Support test module arbitrary organization

Signed-off-by: Chris Evich <cevich@redhat.com>
virt: Support test config. arbitrary orginization

Signed-off-by: Chris Evich <cevich@redhat.com>
virt: Some minor style/pylint cleanup

Signed-off-by: Chris Evich <cevich@redhat.com>