libvirt: Add virsh net-info command test

New testcase: virsh_net_info.py/cfg
virttest.virsh: virsh net-info function
net_info(network, extra="", **dargs)
libvirt-tests: Fix some emulatorpin errors

* Backup vm's xml for restoration. or the vm xml will change for
  set_emulatorpin cases.

* Move the test process into a try/finally block to ensure environment
  is cleaned up even if exception raised.

* Fix typo in cfg file causing duplicated test name: s/config/live

Signed-off-by: Hao Liu <hliu@redhat.com>
virsh.schedinfo_qemu_posix: update the way we get the cgroup path

Now we have a new way how to obtain the correct cgroup path for
specific cgroup controller for a guest.

Let's use the new way also for the "schedinfo_qemu_posix" test.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
staging.utils_cgroup: change the regexp for finding correct cgroup path

The current approach will not properly find the path for "cpu"
controller. I've updated the regexp to match the correct "cpu".

In the "get_cgroup_mountpoint" we are searching the system
cgroup mountpoint from "/proc/mounts" where there could be right
now two types of mounts:

    cgroup on /sys/fs/cgroup/cpuset type cgroup (...)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (...)

The second one makes thinks a little bit harder and we have to check
if the path ends with comma or space.

In the "resolve_task_cgroup_path" the situation is similar. We are
searching the exact path of specified controller for some guest
and there are also two types of records:

    4:cpuacct,cpu:/machine/guest.libvirt-qemu/emulator
    3:cpuset:/machine/guest.libvirt-qemu/emulator

There are thins even harder then the previous case. We need to get
only the 3th part of the record with the path. For the "cpuacct"
we have to consume also the "cpu" and that's why I'm using lookahead
in the regexp instead of the simple match to be able consume always
the remaining controller part until the colon.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
virsh_snapshot_create_as: Adjustments from review

A review comment/suggestion from @liyangfnst after pull request #1174
was merged to master was to make the entire test use try/finally type
logic so as to only run the xml_recover from one place...

This change implements that concept.
virsh_snapshot_edit: Resolve test errors

Test was failing because the 're.search()' wasn't stripping off the
newline character from the after_xml, thus not allowing the match check
to determine if the <description> changed. Changed the error processing
to list the 15 or so relevant lines from the snapshot dump xml that
could be different if the re.search() fails.

Remove the extraneous .strip() from the after_xml creation since it's
repeated in the snap_xml_compare() method when doing the comparison
with the pre_xml. Also changed the logic on error path to just print
some different lines rather than printing both whole pre/after xml
and forcing an eyeball comparison for why the test failed.
virttest.qemu_devices: Use qid for hotplug verification

Proper identification in qemu_devices is object.get_qid().

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.virtio_console: Update test_hotplug_virtio_pci

Fix the problem with duplicated IDs caused by early device_del execution.
Monitor returns no output but internally waits for OS ACPI respone. This
message, in case kernel is not yet initialized, never occurs.

This version resends the device_del in the first round until it succeeds,
than it just waits until the device disappears.

Additionally the test was rewritten to use qemu_devices to handle the
hotplug/unplug and the test cfg was tweaked to be more intensive.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
Merge pull request #1206 from ldoktor/virtio_console

qemu.tests.virtio_console: Update test_hotplug_virtio_pci
PEP8 mass auto fix

Catching up with some problems found w.r.t. coding style

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

PEP8 mass auto fix
Fix a wrong logical judgment in get_target_id()

  * Wrong using 'elif' instead of 'if', then it will never judge if this target using
    the emulated image name.
  * Delete the duplicated judgment when cleanup.

Signed-off-by: Yanbing Du <ydu@redhat.com>
libirt: Add test for virsh find-storage-pool-sources-as

Signed-off-by: Yanbing Du <ydu@redhat.com>
virsh_start: Need to ensure stopped before run

When run after virsh.shutdown, the first virsh.start was failing with
because the domain was already started.  Adjusted the .cfg file to
ensure setting of the 'kill_vm_before_test' in the status_error_no
variant.

Also, changed the error returned from using 'stdout' to 'stderr' so that
"Domain is already active" would be displayed.
virttest.env_process: Remove restart_vm option

The restart_vm option, that will restart a vm at the beginning
of postprocessing, is unnecessary, given that you could
simply shut down all the VMs at the end of each test,
forcing new vms to be started.

So get rid of this option, and replace --restart-vm
in ./run to use kill_vm = yes instead.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
Merge pull request #1214 from autotest/restart-vm

virttest.env_process: Remove restart_vm option
virttest: Fix network xml sync with state unchanged

When using original sync of NetworkXML class to restore a backup
network, it is redefined and started, leaving autostart disabled.
This is not the default setting (all true for active/persistent/
autostart) for the network.

In this modification, we set the default behavior of sync to
set all state to true. With the help of an optional "state" dict
parameter, we can restore the network to any state you like, or
in practical, to the state we backed up.

To facilitate this backup & restore process, I also added a helper
function state_dict() to retrieve a active/persistent/autostart
dict for backing up current vm state.

The unittest for these network manipulators is given in a new file
instead of libvirt_xml_unittest.py to separate manipulator tests
from XML base test.

Furthermore, The net_state_dict function use an outdated way to get
the persistent property for the network, which is already changed
by a patch (commit 895913d) in libvirt-0.10.2. The persistent status
can be retrieved from net_list directly. So I add a condition to
ensure it can be backported for older libvirt while avoiding
redundant call of net_autostart when testing on new libvirt.

This backport can be removed if old libvirt no longer maintained.

Signed-off-by: Hao Liu <hliu@redhat.com>
virt-libvirt: VirshPersistent Noise reduction

This class was logging a debug event every time it successfully
reused an aexpect session.  Since aexpect always loggs the command
being run anyway, this extra detail is mostly redundant.  If there's
a problem, an exception will be thrown anyway.

Signed-off-by: Chris Evich <cevich@redhat.com>
qemu.tests.migration: Don't close remote sessions

As the pre processing code already takes care of that
anyway.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
qemu.tests.migration: Shut down VM if killing migration bg cmd times out

Sometimes, post migration run, we can run into a condition
where tcpdump or the VM hangs at migration cleanup stage.
After analyzing test logs, including VM logs, there's nothing
that points out to any guest OS crash or similar condition.

With that in mind, it is admissible to be more lenient
when trying to kill the migration background command, and
if a timeout happens when trying to kill it, be safe and
try to shut down the vm gracefully.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>