bootstrap: Introduce post download SHA1 check

Sometimes we might be on a flaky internet connection and
our JeOS download might end up corrupted. Let's do a SHA1
check after the image is downloaded. If running in
interactive mode, offer the user to download it again,
otherwise, just log that the file is corrupted and
proceed.

This way when the subsequent 7zip command fails, it's
apparent why it has failed (corrupted file).

CC: Ademar Reis <areis@redhat.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
env_process: Fix regression with non qemu test types

All the fixes required for auto_cpu_model ended up
requiring that we interact with qemu directly on
pre/postprocessing code. However, there was no
restriction put on which vm_type the auto config
should happen.

Therefore, restrict the auto_cpu_model feature to
qemu vms and fix the problem.

CC: Chris Evich <cevich@redhat.com>
CC: Yu Mingfei <yumingfei@cn.fujitsu.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
libvirt_xml and xml_utils unittests: Fix tools/run_unittests.py

Our unittest runner imports the unittest modules and
runs them. Due to the fact that currently our xml modules
rely on the fact they will ever be imported on a scope
where they are visible, this causes the tests executed
under the test runner to fail, even when they pass fine
executed stand alone.

To make the matters worse, we ship a fork of ElementTree,
because we have to support python 2.4. Oh, the joys of
supporting RHEL5...

So we have to handle the different import scenarios
in a way where both the stand alone tests and running
under the test runner pass. Specifically, we *must*
import our specific ElementTree fork.

With this patch, all unit tests run fine both stand
alone and with the test runner. I'm not sure if this
introduces some subtle problems in the running code,
so I kindly ask Chris or Yu to take a look and run the
actual test code just to double check if this is OK.

CC: Yu Mingfei <yumingfei@cn.fujitsu.com>
CC: Chris Evich <cevich@redhat.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
standalone_test.py: screen also supports colors

Add screen and screen-256color to the terminal whitelist for color
support on standalone_test.py.

Maybe the code should be changed later to use terminfo to find out how
and if it can display colors.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
virt-libvirt: add configuration for virsh vncdisplay

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
virt-libvirt: add virsh function for virsh vncdisplay

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
virt-libvirt: add test module for virsh vncdisplay

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
virt-libvirt: add configuration for virsh dominfo

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
virt-libvirt: modify virsh function for virsh dominfo

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
virt-libvirt: modify libvirt_vm where use virsh.dominfo

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
virt-libvirt: add test module for virsh dominfo

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
standalone_test: unset log level on root logger when

Other modules may have messed with the root logger already, so if we
don't reset the root logger log level, messages go through the logger
even after we add the console and file handlers later.

This problem wasn't visible before because an autotest module was
unconditionally setting the root logger log level to DEBUG, but a recent
patch I sent to autotest removes that unconditional logging setup code.

This patch also renames configure_logging() to reset_logging(), as it
doesn't configure any handler, but just remove the existing logging
configuration).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
./run: make stdout redirect/restore API simpler

Today, if _restore_stdout() is called twice, stdout gets silenced again.
Instead of having API that requires the caller to remember what's the
internal state of the object to know what will happen, we can simply
have two separate methods to redirect and restore stdout.

The main problem with the current approach is that it makes it very
difficult to gradually disable the hack in various parts of the code[1],
as changing the moment we silence/restore stdout could break existing
parts of the code that calls the switch() method assuming stdout is
already silenced.

[1] In a perfect world we wouldn't need any stdout hacking at all, we
    would just need to ask the test runner and autotest to be more
    silent. But to achieve that, we need to do it gradually (e.g. trying
    to disable stdout/stderr only when actually running the tests, not
    when parsing configs or loading modules)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
bootstrap.py: fix log message formatting

The arguments for logging.info are the format string parameters
themselves, not a tuple. This was causing logging error tracebacks on my
tests.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
run: List all test types in --help output

Signed-off-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
./run: use imp module for AUTOTEST_PATH setup

Instead of hacking sys.path, just use the Python imp module to load the
module using the full path.

Also change the check for AUTOTEST_PATH to not rely on Exception
handling for flow control.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
./run: print clearer error message if AUTOTEST_PATH doesn't work

Error message before:

  $ ./run
  Traceback (most recent call last):
    File "./run", line 558, in <module>
      app = VirtTestApp()
    File "./run", line 271, in __init__
      self.option_parser = VirtTestRunParser()
    File "./run", line 151, in __init__
      _import_autotest_modules()
    File "./run", line 106, in _import_autotest_modules
      setup_modules_path)
  IOError: [Errno 2] No such file or directory
  $

Error message after:

  $ ./run
  Failed to import autotest modules from $AUTOTEST_PATH
  Could not load Python module /home/ehabkost/pessoal/proj/virt/autotestx/client/setup_modules.py
  $

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
./run: isolate initialization code that affects the whole process

The new system_setup() function will be used for the stuff that affects
the whole Python interpreter.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
./run: give AUTOTEST_PATH precedence over sys.path

If AUTOTEST_PATH is set, try to use it instead of the autotest modules
in sys.path.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
./run: try to import autotest modules at the very beginning

The _import_autotest_modules() function doesn't need to be called
multiple times, and calling it as early as possible will allow us to use
some autotest modules very early.

This also adds a workaround to an Autotest bug in some versions where it
enables debug logging as soon as the modules are imported.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>