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
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>
virttest.virsh: Add virsh filter group functions

Add five network filter functions under filter group

Signed-off-by: Wayne Sun <gsun@redhat.com>
virttest.libvirt_xml.devices.librarian: Add network filter types

Add multiple network filter protocol types into device list, use
the librarian module to load network filter specific protocol
type modules.

Signed-off-by: Wayne Sun <gsun@redhat.com>
virttest.libvirt_xml.devices: Add network filter rule protocol modules

Add 24 libvirt nwfilter protocols modules for supported types.

This is for cover nwfilter rule protocols in page:
http://libvirt.org/formatnwfilter.html#nwfelemsRulesProto

Note:
Total number of libvirt supported protocols is 25, only igmp-ipv6
(fail for define, need confirm bug) is not included in this commit.

Signed-off-by: Wayne Sun <gsun@redhat.com>
virttest.libvirt_xml: Add nwfilter xml module

Module simplifying manipulation of XML described at
http://libvirt.org/formatnwfilter.html

Signed-off-by: Wayne Sun <gsun@redhat.com>
libvirt.tests: Add virsh nwfilter define case

- Add virsh nwfilter define case
  The case support process multiple rules for define one filter xml.

  Only check whether the filter config xml exist or not after define
  and check the filter is in nwfilter-list command output.

  Why not strict check each attribue in xml:
    1. each attribute in xml might have default value if not set.
    2. if the attribute value is out of boundary (not valid value),
       define action will omit the attribute.
    3. protocols have different attributes which is a super big
       matrix to check each detail one

- Add virsh nwfilter define cfg
  25 positive cases including 1 update define case and 24 protocol
  type xml test.
  include 3 negative cases.

  The rule parameter in cfg should be like:
  for only 1 rule:
    rule = "rule_action=accept rule_direction=out protocol=mac EOL"
  each rule should end with string 'EOL' for split.

  Test Data:
    TESTS: 28
    CLEANUP: PASS (0.00 s)
    TOTAL TIME: 26.68 s
    TESTS PASSED: 28
    TESTS FAILED: 0
    SUCCESS RATE: 100.00 %

Signed-off-by: Wayne Sun <gsun@redhat.com>
libvirt.tests: Add virsh nwfilter-dumpxml test

v1:
Simply dump network filter xml with normal and error test.

v2:
Only accept filter name from cfg as filter uuid may differ on
different host.
For check the dumpxml result, extract uuid and name from output
and compare with nwfilter-list to confirm.

v3:
Add nwfilter dumpxml using filter uuid after using filter name
Only given filter name in cfg, run 2 time dumpxml to cover both
name and uuid option.

Signed-off-by: Wayne Sun <gsun@redhat.com>

add uuid test in dumpxml
libvirt.tests: add virsh nwfilter list test

The test simply list filters and check the filter cfg file exist
under network filter config path

Signed-off-by: Wayne Sun <gsun@redhat.com>
libvirt.tests: Add nwfilter-undefine test case

Undefine network filter using given filter name or uuid in cfg.
If the filter is valid, backup filter xml before undefine and
define the filter back after undefine succeed.

Signed-off-by: Wayne Sun <gsun@redhat.com>
libvirt.tests: Add nwfilter-edit test case

Add the case and cfg file for nwfilter-edit.
In the cfg file, 4 scenarios included, 2 for positive and 2 for
negative testing.

TODO: Cover test with readonly mode and update invalid value in xml
This two scenarios need shell interactive session to return false
when "Failed. Try again? [y,n,f,?]:" prompt.

Signed-off-by: Wayne Sun <gsun@redhat.com>