From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 04/16] Moving get_started code to client.virt.virt_utils
Date: Thu, 3 Nov 2011 19:26:10 -0200 [thread overview]
Message-ID: <1320355582-4342-5-git-send-email-lmr@redhat.com> (raw)
In-Reply-To: <1320355582-4342-1-git-send-email-lmr@redhat.com>
As most of the get_started.py code could be very well
shared among virt tests, moved the bulk of the code
to virt_utils.py. Now we have the function
virt_test_assistant(), that is generic enough so other
tests can implement their variation of the assistant
script.
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
client/tests/kvm/get_started.py | 162 +++----------------------------------
client/virt/virt_utils.py | 171 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 181 insertions(+), 152 deletions(-)
diff --git a/client/tests/kvm/get_started.py b/client/tests/kvm/get_started.py
index 4a40925..830c2a9 100755
--- a/client/tests/kvm/get_started.py
+++ b/client/tests/kvm/get_started.py
@@ -4,159 +4,19 @@ Program to help setup kvm test environment
@copyright: Red Hat 2010
"""
-
-import os, sys, logging, shutil, glob
+import os, sys
import common
-from autotest_lib.client.common_lib import logging_manager
-from autotest_lib.client.bin import utils
from autotest_lib.client.virt import virt_utils
-
-def check_iso(url, destination, hash):
- """
- Verifies if ISO that can be find on url is on destination with right hash.
-
- This function will verify the SHA1 hash of the ISO image. If the file
- turns out to be missing or corrupted, let the user know we can download it.
-
- @param url: URL where the ISO file can be found.
- @param destination: Directory in local disk where we'd like the iso to be.
- @param hash: SHA1 hash for the ISO image.
- """
- file_ok = False
- if not destination:
- os.makedirs(destination)
- iso_path = os.path.join(destination, os.path.basename(url))
- if not os.path.isfile(iso_path):
- logging.warning("File %s not found", iso_path)
- logging.warning("Expected SHA1 sum: %s", hash)
- answer = utils.ask("Would you like to download it from %s?" % url)
- if answer == 'y':
- try:
- utils.unmap_url_cache(destination, url, hash, method="sha1")
- file_ok = True
- except EnvironmentError, e:
- logging.error(e)
- else:
- logging.warning("Missing file %s", iso_path)
- logging.warning("Please download it or put an exsiting copy on the "
- "appropriate location")
- return
- else:
- logging.info("Found %s", iso_path)
- logging.info("Expected SHA1 sum: %s", hash)
- answer = utils.ask("Would you like to check %s? It might take a while" %
- iso_path)
- if answer == 'y':
- try:
- utils.unmap_url_cache(destination, url, hash, method="sha1")
- file_ok = True
- except EnvironmentError, e:
- logging.error(e)
- else:
- logging.info("File %s present, but chose to not verify it",
- iso_path)
- return
-
- if file_ok:
- logging.info("%s present, with proper checksum", iso_path)
-
+test_name = "kvm"
+test_dir = os.path.dirname(sys.modules[__name__].__file__)
+test_dir = os.path.abspath(test_dir)
+base_dir = "/tmp/kvm_autotest_root"
+default_userspace_paths = ["/usr/bin/qemu-kvm", "/usr/bin/qemu-img"]
+check_modules = ["kvm", "kvm-%s" % virt_utils.get_cpu_vendor(verbose=False)]
+online_docs_url = "https://github.com/autotest/autotest/wiki/KVMAutotest-GetStartedClient"
if __name__ == "__main__":
- logging_manager.configure_logging(virt_utils.VirtLoggingConfig(),
- verbose=True)
- logging.info("KVM test config helper")
-
- logging.info("")
- logging.info("1 - Verifying directories (check if the directory structure "
- "expected by the default test config is there)")
- base_dir = "/tmp/kvm_autotest_root"
- sub_dir_list = ["images", "isos", "steps_data"]
- for sub_dir in sub_dir_list:
- sub_dir_path = os.path.join(base_dir, sub_dir)
- if not os.path.isdir(sub_dir_path):
- logging.debug("Creating %s", sub_dir_path)
- os.makedirs(sub_dir_path)
- else:
- logging.debug("Dir %s exists, not creating" %
- sub_dir_path)
- logging.info("")
- logging.info("2 - Creating config files from samples (copy the default "
- "config samples to actual config files)")
- kvm_test_dir = os.path.dirname(sys.modules[__name__].__file__)
- kvm_test_dir = os.path.abspath(kvm_test_dir)
- config_file_list = glob.glob(os.path.join(kvm_test_dir, "*.cfg.sample"))
- for config_file in config_file_list:
- src_file = config_file
- dst_file = config_file.rstrip(".sample")
- if not os.path.isfile(dst_file):
- logging.debug("Creating config file %s from sample", dst_file)
- shutil.copyfile(src_file, dst_file)
- else:
- logging.debug("Config file %s exists, not touching" % dst_file)
-
- logging.info("")
- logging.info("3 - Verifying iso (make sure we have the OS ISO needed for "
- "the default test set)")
-
- iso_name = "Fedora-15-x86_64-DVD.iso"
- fedora_dir = "pub/fedora/linux/releases/15/Fedora/x86_64/iso"
- url = os.path.join("http://download.fedoraproject.org/", fedora_dir,
- iso_name)
- hash = "61b3407f62bac22d3a3b2e919c7fc960116012d7"
- destination = os.path.join(base_dir, 'isos', 'linux')
- path = os.path.join(destination, iso_name)
- check_iso(url, destination, hash)
-
- logging.info("")
- logging.info("4 - Verifying winutils.iso (make sure we have the utility "
- "ISO needed for Windows testing)")
-
- logging.info("In order to run the KVM autotests in Windows guests, we "
- "provide you an ISO that this script can download")
-
- url = "http://people.redhat.com/mrodrigu/kvm/winutils.iso"
- hash = "02930224756510e383c44c49bffb760e35d6f892"
- destination = os.path.join(base_dir, 'isos', 'windows')
- path = os.path.join(destination, iso_name)
- check_iso(url, destination, hash)
-
- logging.info("")
- logging.info("5 - Checking if qemu is installed (certify qemu and qemu-kvm "
- "are in the place the default config expects)")
- qemu_default_paths = ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img']
- for qemu_path in qemu_default_paths:
- if not os.path.isfile(qemu_path):
- logging.warning("No %s found. You might need to install qemu-kvm.",
- qemu_path)
- else:
- logging.debug("%s present", qemu_path)
- logging.info("If you wish to change qemu-kvm to qemu or other binary path, "
- "you will have to modify tests.cfg")
-
- logging.info("")
- logging.info("6 - Checking for the KVM module (make sure kvm is loaded "
- "to accelerate qemu-kvm)")
- if not utils.module_is_loaded("kvm"):
- logging.warning("KVM module is not loaded. You might want to load it")
- else:
- logging.debug("KVM module loaded")
-
- logging.info("")
- logging.info("7 - Verify needed packages to get started")
- logging.info("Please take a look at the online documentation "
- "http://www.linux-kvm.org/page/KVM-Autotest/Client_Install "
- "(session 'Install Prerequisite packages')")
-
- client_dir = os.path.abspath(os.path.join(kvm_test_dir, "..", ".."))
- autotest_bin = os.path.join(client_dir, 'bin', 'autotest')
- control_file = os.path.join(kvm_test_dir, 'control')
-
- logging.info("")
- logging.info("When you are done fixing eventual warnings found, "
- "you can run the kvm test using the command line AS ROOT:")
- logging.info("%s %s", autotest_bin, control_file)
- logging.info("Autotest prints the results dir, so you can look at DEBUG "
- "logs if something went wrong")
- logging.info("You can also edit the test config files (see output of "
- "step 2 for a list)")
+ virt_utils.virt_test_assistant(test_name, test_dir, base_dir,
+ default_userspace_paths, check_modules,
+ online_docs_url)
diff --git a/client/virt/virt_utils.py b/client/virt/virt_utils.py
index 7b0cfb3..ba76979 100644
--- a/client/virt/virt_utils.py
+++ b/client/virt/virt_utils.py
@@ -6,9 +6,10 @@ KVM test utility functions.
import time, string, random, socket, os, signal, re, logging, commands, cPickle
import fcntl, shelve, ConfigParser, threading, sys, UserDict, inspect, tarfile
-import struct, shutil
+import struct, shutil, glob
from autotest_lib.client.bin import utils, os_dep
from autotest_lib.client.common_lib import error, logging_config
+from autotest_lib.client.common_lib import logging_manager
import rss_client, aexpect
try:
import koji
@@ -3389,3 +3390,171 @@ def if_set_macaddress(ifname, mac):
logging.info(e)
raise HwAddrSetError(ifname, mac)
ctrl_sock.close()
+
+
+def check_iso(url, destination, hash):
+ """
+ Verifies if ISO that can be find on url is on destination with right hash.
+
+ This function will verify the SHA1 hash of the ISO image. If the file
+ turns out to be missing or corrupted, let the user know we can download it.
+
+ @param url: URL where the ISO file can be found.
+ @param destination: Directory in local disk where we'd like the iso to be.
+ @param hash: SHA1 hash for the ISO image.
+ """
+ file_ok = False
+ if not destination:
+ os.makedirs(destination)
+ iso_path = os.path.join(destination, os.path.basename(url))
+ if not os.path.isfile(iso_path):
+ logging.warning("File %s not found", iso_path)
+ logging.warning("Expected SHA1 sum: %s", hash)
+ answer = utils.ask("Would you like to download it from %s?" % url)
+ if answer == 'y':
+ try:
+ utils.unmap_url_cache(destination, url, hash, method="sha1")
+ file_ok = True
+ except EnvironmentError, e:
+ logging.error(e)
+ else:
+ logging.warning("Missing file %s", iso_path)
+ logging.warning("Please download it or put an exsiting copy on the "
+ "appropriate location")
+ return
+ else:
+ logging.info("Found %s", iso_path)
+ logging.info("Expected SHA1 sum: %s", hash)
+ answer = utils.ask("Would you like to check %s? It might take a while" %
+ iso_path)
+ if answer == 'y':
+ try:
+ utils.unmap_url_cache(destination, url, hash, method="sha1")
+ file_ok = True
+ except EnvironmentError, e:
+ logging.error(e)
+ else:
+ logging.info("File %s present, but chose to not verify it",
+ iso_path)
+ return
+
+ if file_ok:
+ logging.info("%s present, with proper checksum", iso_path)
+
+
+def virt_test_assistant(test_name, test_dir, base_dir, default_userspace_paths,
+ check_modules, online_docs_url):
+ """
+ Common virt test assistant module.
+
+ @param test_name: Test name, such as "kvm".
+ @param test_dir: Path with the test directory.
+ @param base_dir: Base directory used to hold images and isos.
+ @param default_userspace_paths: Important programs for a successful test
+ execution.
+ @param check_modules: Whether we want to verify if a given list of modules
+ is loaded in the system.
+ @param online_docs_url: URL to an online documentation system, such as an
+ wiki page.
+ """
+ logging_manager.configure_logging(VirtLoggingConfig(), verbose=True)
+ logging.info("%s test config helper", test_name)
+ step = 0
+
+ logging.info("")
+ step += 1
+ logging.info("%d - Verifying directories (check if the directory structure "
+ "expected by the default test config is there)", step)
+ sub_dir_list = ["images", "isos", "steps_data"]
+ for sub_dir in sub_dir_list:
+ sub_dir_path = os.path.join(base_dir, sub_dir)
+ if not os.path.isdir(sub_dir_path):
+ logging.debug("Creating %s", sub_dir_path)
+ os.makedirs(sub_dir_path)
+ else:
+ logging.debug("Dir %s exists, not creating" %
+ sub_dir_path)
+ logging.info("")
+ step += 1
+ logging.info("%d - Creating config files from samples (copy the default "
+ "config samples to actual config files)", step)
+ config_file_list = glob.glob(os.path.join(test_dir, "*.cfg.sample"))
+ for config_file in config_file_list:
+ src_file = config_file
+ dst_file = config_file.rstrip(".sample")
+ if not os.path.isfile(dst_file):
+ logging.debug("Creating config file %s from sample", dst_file)
+ shutil.copyfile(src_file, dst_file)
+ else:
+ logging.debug("Config file %s exists, not touching" % dst_file)
+
+ logging.info("")
+ step += 1
+ logging.info("%s - Verifying iso (make sure we have the OS ISO needed for "
+ "the default test set)", step)
+
+ iso_name = "Fedora-15-x86_64-DVD.iso"
+ fedora_dir = "pub/fedora/linux/releases/15/Fedora/x86_64/iso"
+ url = os.path.join("http://download.fedoraproject.org/", fedora_dir,
+ iso_name)
+ hash = "61b3407f62bac22d3a3b2e919c7fc960116012d7"
+ destination = os.path.join(base_dir, 'isos', 'linux')
+ check_iso(url, destination, hash)
+
+ logging.info("")
+ step += 1
+ logging.info("%d - Verifying winutils.iso (make sure we have the utility "
+ "ISO needed for Windows testing)", step)
+
+ logging.info("In order to run the KVM autotests in Windows guests, we "
+ "provide you an ISO that this script can download")
+
+ url = "http://people.redhat.com/mrodrigu/kvm/winutils.iso"
+ hash = "02930224756510e383c44c49bffb760e35d6f892"
+ destination = os.path.join(base_dir, 'isos', 'windows')
+ path = os.path.join(destination, iso_name)
+ check_iso(url, destination, hash)
+
+ logging.info("")
+ step += 1
+ logging.info("%d - Checking if the appropriate userspace programs are "
+ "installed", step)
+ for path in default_userspace_paths:
+ if not os.path.isfile(path):
+ logging.warning("No %s found. You might need to install %s.",
+ path, os.path.basename(path))
+ else:
+ logging.debug("%s present", path)
+ logging.info("If you wish to change any userspace program path, "
+ "you will have to modify tests.cfg")
+
+ if check_modules:
+ logging.info("")
+ step += 1
+ logging.info("%d - Checking for modules %s", step,
+ ",".join(check_modules))
+ for module in check_modules:
+ if not utils.module_is_loaded(module):
+ logging.warning("Module %s is not loaded. You might want to "
+ "load it", module)
+ else:
+ logging.debug("Module %s loaded", module)
+
+ if online_docs_url:
+ logging.info("")
+ step += 1
+ logging.info("%d - Verify needed packages to get started", step)
+ logging.info("Please take a look at the online documentation: %s",
+ online_docs_url)
+
+ client_dir = os.path.abspath(os.path.join(test_dir, "..", ".."))
+ autotest_bin = os.path.join(client_dir, 'bin', 'autotest')
+ control_file = os.path.join(test_dir, 'control')
+
+ logging.info("")
+ logging.info("When you are done fixing eventual warnings found, "
+ "you can run the test using this command line AS ROOT:")
+ logging.info("%s %s", autotest_bin, control_file)
+ logging.info("Autotest prints the results dir, so you can look at DEBUG "
+ "logs if something went wrong")
+ logging.info("You can also edit the test config files")
--
1.7.7
next prev parent reply other threads:[~2011-11-03 21:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-03 21:26 [PATCH 00/16] Libvirt test v5 Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 02/16] virt: Introducing virt_test.virt_test class Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 03/16] Moving unattended_install test from kvm test to common virt location Lucas Meneghel Rodrigues
2011-11-03 21:26 ` Lucas Meneghel Rodrigues [this message]
2011-11-03 21:26 ` [PATCH 05/16] virt: Introducing libvirt VM class Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 06/16] virt: Introducing libvirt monitor Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 07/16] virt.virt_env_process: Add libvirt vm handling Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 08/16] client.tests: Introducing libvirt test Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 09/16] Virt: builtin HTTP server for unattended installs Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 10/16] Virt: support XEN via libvirt and auto url installer Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 11/16] Virt: add support for XEN via libvirt installs and auto url Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 12/16] Virt: small fixes related to libvirt unattended install when using " Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 13/16] Virt: pass verbatim hvm_or_pv option to virt_install Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 14/16] Virt: add sample configuration for XEN HVM domains Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 15/16] virt: Fix unattended install for libvirt case Lucas Meneghel Rodrigues
2011-11-03 21:26 ` [PATCH 16/16] Virt: adjust auto http servers (content/kickstart) ports to not overlap Lucas Meneghel Rodrigues
2011-11-04 3:57 ` [PATCH 00/16] Libvirt test v5 Lucas Meneghel Rodrigues
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1320355582-4342-5-git-send-email-lmr@redhat.com \
--to=lmr@redhat.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.