From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 04/11] Moving get_started code to client.virt.virt_utils
Date: Tue, 11 Oct 2011 18:07:10 -0300 [thread overview]
Message-ID: <1318367237-26081-5-git-send-email-lmr@redhat.com> (raw)
In-Reply-To: <1318367237-26081-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 962e2c3..b76e087 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
@@ -3287,3 +3288,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.6.4
next prev parent reply other threads:[~2011-10-11 21:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-11 21:07 [PATCH 00/11] [RFC] Libvirt test v2 Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 02/11] virt: Introducing virt_test.virt_test class Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 03/11] Moving unattended_install test from kvm test to common virt location Lucas Meneghel Rodrigues
2011-10-11 21:07 ` Lucas Meneghel Rodrigues [this message]
2011-10-11 21:07 ` [PATCH 05/11] virt: Introducing libvirt VM class Lucas Meneghel Rodrigues
2011-10-12 6:51 ` [Autotest] " Amos Kong
2011-10-12 8:14 ` Daniel P. Berrange
2011-10-13 17:26 ` Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 06/11] virt: Introducing libvirt monitor Lucas Meneghel Rodrigues
2011-10-12 7:48 ` [Autotest] " Amos Kong
2011-10-13 17:12 ` Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 07/11] virt.virt_env_process: Add libvirt vm handling Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 08/11] client.tests: Introducing libvirt test Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 09/11] Virt: builtin HTTP server for unattended installs Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 10/11] Virt: support XEN via libvirt and auto url installer Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 11/11] Virt: add support for XEN via libvirt installs and auto url 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=1318367237-26081-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).