libguestfs: Add testcases for error_test of guestfs_add.

Signed-off-by: Yu Mingfei <yumingfei@cn.fujitsu.com>
libguestfs.test: Fix guestfs_add for new libguestfs version.

In new libguestfs version, all disks will be recognised with /dev/sdx.
But virtio disks of vm will be /dev/vdx in vm.So change gotten
/dev/sdx in guestfish to /dev/vdx if it is necessary.

Signed-off-by: Yu Mingfei <yumingfei@cn.fujitsu.com>
device_bit_check.cfg: replace scsi_extra_params_hda with blk_extra_params

change the parameter name scsi_extra_params_hda to blk_extra_params.

Signed-off-by: Xiangmin Han <xhan@redhat.com>
libvirt: Fix setmaxmem from changing mem size

The test setmaxmem backup the vm's max memory and restore it by calling
`virsh setmaxmem` after test.

This will cause problem when test shinking the max memory. The current
memory will also shrink to adapt the max memory. After restore the max
memory, this shrinked current memory will remain.

* To ensure the fully restoration of guest, we change back to
  backup by new_from_inactive_dumpxml and sync after test.

* Use `try ... finally ...` to make sure restoration even bad thing
  happens.

* Fix some pylint complaints.

Signed-off-by: Hao Liu <hliu@redhat.com>
libvirt: Fix vcpupin XML change

Test vcpupin doesn't backup and restore vm XML, making the XML change
when using '--config' option.

This commit:
* Backup and restore VM's XML using new_from_inactive_dumpxml and sync.

* Close the test block in 'try ... finally ...' to ensure VM recover in
  any case.

Signed-off-by: Hao Liu <hliu@redhat.com>
virsh: Add options in virsh.restore() fucntion.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
libvirt-tests: Use tmp_file for virsh restore

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
virttest: Destory pre vm in env_process

Destory the pre vm in preprocess_vm. otherwise some strange error
will be produced as some vm object options is different.

Signed-off-by: Yiqiao Pu <ypu@redhat.com>
virt: Modify 'test_modules' to be a dictionary

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
libvirt: Fix attach-device itertools backports

Calling backported itertools using 'from ... import ...' will cause
following error.

ERROR| Traceback (most recent call last):
ERROR|   File "virttest/standalone_test.py", line 182, in run_once
ERROR|     test_modules[t_type] = imp.load_module(t_type, f, p, d)
ERROR|   File "libvirt/tests/src/virsh_cmd/domain/virsh_attach_device.py", line 14, in <module>
ERROR|     from virttest.staging.backports.itertools import product, islice, count
ERROR| ImportError: No module named itertools

Signed-off-by: Hao Liu <hliu@redhat.com>
Merge pull request #1277 from liyangfnst/virt_py

virt: Modify 'test_modules' to be a dictionary
Merge pull request #1266 from Hao-Liu/fix_vcpupin

libvirt: Fix vcpupin XML change
libvirt: Fix start uuid change

When calling vm_rename() the UUID will change, making the vm xml don't
consist with original one.

The patch use new_from_inactive_dumpxml and sync to backup and recover
test vm.

For testing empty or invalid vm name, we need another variable to store
the valid vm name for recovering.

This patch also fix a bug of VMXML.sync(). when the vm is no longer
exist, sync will raise an exception in the backup step. This is not a
right behavior because sync should recover vm even if it's undefined.

Signed-off-by: Hao Liu <hliu@redhat.com>
libvirt.tests.virsh_memtune: Replace incompatible py 2.4 construct

The keyword 'with' is valid only on py >= 2.5. We'll have
to wait a bit before those can be freely used.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
libvirt.virsh_schedinfo_qemu_posix: Remove py 2.4 incompatible construct

With is valid only on py >= 2.5. We'll have to wait
a bit until it can be used in virt-test code.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
virttest.utils_cgroup_unittest: Make it compatible with python 2.4

This unittest relied on a new param of the tempfile.NamedTemporaryFile
class: delete. Python 2.4 doesn't have such param, which means that
named temp files will always be deleted after they are closed.

So let's use the module only to give us a file path, that will then
be manually managed.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
Merge pull request #1289 from autotest/fix-py24-bugs

Fix py24 bugs
Merge pull request #1264 from Hao-Liu/fix_start

libvirt: Fix start uuid change
qemu.tests.virtual_nic_send_buffer: Update the way used to checkout md5 in guest

md5 command in guest may have different output format. It is a little difficult to
filter out the md5 value from the output. So just checkout whether correct md5 value
is in the output is enough.

Signed-off-by: Feng Yang <fyang@redhat.com>
qemu.tests: Bug fix about drift for timedrift_with_stop

kvm guests CLOCK_MONOTONIC not count when guest is paused,
so drift need to subtract stop_time.

starting from Win2012 Windows no longer relies on number of
injected RTC interrupts for time keeping, and the time drift
is seen because "stop" monitor command also stops PM timer,
so this is unsupported scenario from Win2012 and disabled this
case from Win2012.

changes from v1:
    add some comments for windows guest.
changes from v2:
    add check rtc_clock for windows
changes from v3:
    add new scenario rtc_clock = host and rtc_clock = vm for this case.

Signed-off-by: Shuping Cui <scui@redhat.com>