qemu.tests.virtio_console: Fix variable overwriting

err value was overwritten by thread return number which resulted in
incorrectly reported failed tests as pass.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_virtio_port: Allow to reload loss idx from outside the thread

Usually the index of lost characters is reloaded while reconnection.
This patch creates a function, which can be called from outside of this
thread in case we want to reload this index elswhere. Additionally booth
(debug and normal) threads use the same code now.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
shared.scripts.virtio_console_guest: Remove sleeps from reconnect loopback

virtio_console is now able to handle the reconnection without any sleep
thus we can use busy wait and use the console immediatelly when it's
created.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.virtio_console: Harden the interrupted_loopback setting

Tweak the config to maximize interrupted_loopback test
* short interruption is 0s
* short test_time is 0.1s
* tweak the acceptable_loss
* increase the number of acceptable test_time repetition

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_virtio_port: Prevent infinite loop

Temove the infinite loop from send and receiver threads.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.virtio_console: Prevent infinite loop in some test on failure

Some tests were voulnurable to infinite loop due of not finished
background thread. Use funcatexit to register function, which sets
the exit_event and causes the background threads to finish.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.virtio_console: Reorder interrupted_loopback and fix 80 chars

No actual change, only put the interrupted_loopback initialization
before the thread initialization (in case of failure it's quicker)
and fix the 80 characters line width.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.virtio_console: New interrupted loopback mode

Currently qemu dies when we try to remove and plug the port couple of
times without delay.

This modification allows to execute x (virtio_console_micro_repeates)
interuptions, where we don't check anything, only do them as fast as
possible. After that we execute normal loop where the transfer is
checked after each interruption.

As the port might not be openable for some time, the guest_worker
supports multiple attemps to open the port. Don't forget to remove
the old /tmp/virtio_console_guest.py* files in order to use the new one.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.virtio_console: Fix multi_open test to suit latest kernels

Current kernels report Error 16 Device or resource busy: ... instead
of Error 24 Access is denied. Accept all kind of failures as success
in this particular test.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
qemu.tests.virtio_console: Reconnect guest worker in migrate test

Before we can cleanup after migrate test the guest worker has to
reconnect to the current VM. The session itself works fine
as the VM was migrated, but the VM object is different and reports
non-living VM, which results in impropper cleanup.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
virttest.qemu_virtio_port: Check the guest script size

In order to check if the guest_worker's script hadn't changed
check the file size instead just the file presense.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
shared.scripts.virtio_console_guest: PEP8 fixes

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