avocado.virt.qemu.machine: VM -> Introduce 'verbose' param to method .qmp()

Repetitive execution of QMP commands on things such as
a VM screendump thread would pollute the test logs and
make them hard to understand. So, allow people to suppress
QMP command/response logging in places where that's
justifiable, by introducing a 'verbose' param to the
.qmp() method.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Add screendump() method to the Machine() class

Add a screendump method, that will prompt the qemu instance
to dump the VM screen at a path specified by the parameter
filename. This will be necessary to implement a screendump
thread that will go on while a VM is active.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Add logdir param to Machine() constructor

We need a base log directory for output on each VM instance,
so we can output things like VM screendumps to the proper
log directories inside the avocado directory structure.

Add a logdir param to the Machine() class, that will be
assigned to the attribute logdir upon construction.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Generalize .short_id parameter

The shorter version of the id will be necessary in other
locations. Therefore, make it part of the class structure.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
Add avocado.virt.utils namespace

To add the utility functions of the virt testing code.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
Add image library to the avocado.virt.utils namespace

Add an image library, that will be used to put utility
classes and functions related to image format manipulation.
That sort of functions come up when handling VM screenshots,
usually.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.test: Use '-vga std' as the default for QEMU processes

That will allow videos of the VMs to be actually generated,
as 'vga -none' will not output any video.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.devices: Add .add_nodefaults() method

Include a method to add the '-nodefaults' flag to the
QEMU command line.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.devices: Add .add_vnc() to Machine() class

Add a utility method .add_vnc() to the Machine() class,
used to append '-vnc :[port]' into the QEMU command line.

This patch also adds a port management system inside the
Devices() class, meaning that we will not use a port that
is either allocated or occupied.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Use short_id for serial console filename

We are using short_id to identify vms now, so it makes
sense to name the serial console file accordingly.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Add screendump thread to VMs

Create a screendump thread on every VM (optional,
customizable through avocado.args.run.screendump_thread.enable).
This is a departure from previous efforts (virt-test), where
the thread was not under class control.

So at the QEMU process init stage, start the thread, when
the VM is shut down, stop it. This way, we have a visual record
of what was going on in the VM during the test process.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Add uuid as a Machine() constructor param

Migration is a process by which VM state is transferred
to another instance of the virtualization system transparently,
and with virtually no downtime. This motivated us to model
the .migrate() method of the Machine() class preserving the
instantiated object (for all intents and purposes, it is
the 'same' virtual machine).

Therefore, it makes sense to have videos of a vm being migrated
as a single entity. Make uuid as one of the Machine class
constructor params, so that we have the option of making
migrated vms to keep the same uuid, and have them to behave
as a single entity for the purposes of vm video generation.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Move migration port management to Devices

We're still a long way from a sane port management, but
this patch improves on the current status quo. By moving
the assignment of the -incoming tcp port to the Devices
class, management becomes uniform, more fool proof and
elegant.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.defaults: Add default params for video encoding
avocado.virt.utils: Introduce video library

Add a video library to the avocado-virt libraries.
It contains a video encoder, that consists on a port of
the original virt-test code, written by Cleber, to gobject
introspection and gstreamer 1.0.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado-virt.spec: Add avocado-virt-video subpackage

Turn the video library into a subpackage, that will
let users to install the video functionality if they
want so.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Encode videos upon VM object termination

As soon as the machine is powered off, let's create a
video from the screenshots generated by the screendump
thread. In order to not encode videos unnecessarily
during migration, pass a migrate param to encode videos
and power off/screendump thread end methods to skip
video encoding in such ocasions.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado-virt: Add --take-screendumps and --record-videos options to plugin

Make both the screendump feature and the record video feature
optional, and turn them into avocado command line options.
This way people have flexibility to use the features, while
keeping avocado simple and fast.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Close serial console after power_off()

Close serial console after VM powers off, otherwise Avocado will leave
the process 'nc' running at the end of the execution.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
avocado.virt.qemu.machine: Improve logging with QEMU VM PID

Start to keep track of the VM PID and show it in the
VM log header. This way it'll be easier to understand
what happens during a migration (class UUID keeps the
same, but the QEMU instance - PID - changes as we
move from src to dst). Example:

QEMU VM (621efc41 PID: 6391) Migration successful
QEMU VM (621efc41 PID: 6391) Shut down (migration src)
QEMU VM (621efc41 PID: 6408) Login (Remote) -> (hostname=192.168.0.103, username=root, password=123456, port=5007)

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