lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | Program to help setup kvm test environment |
| 4 | |
| 5 | @copyright: Red Hat 2010 |
| 6 | """ |
| 7 | |
| 8 | import os, sys, optparse, logging, shutil |
| 9 | import common, kvm_utils |
| 10 | from autotest_lib.client.common_lib import logging_manager |
| 11 | from autotest_lib.client.bin import utils, os_dep |
| 12 | |
| 13 | |
| 14 | if __name__ == "__main__": |
| 15 | logging_manager.configure_logging(kvm_utils.KvmLoggingConfig(), |
| 16 | verbose=True) |
| 17 | logging.info("KVM test config helper") |
| 18 | |
| 19 | logging.info("1 - Verifying directories (check if the directory structure " |
| 20 | "expected by the default test config is there)") |
| 21 | base_dir = "/tmp/kvm_autotest_root" |
| 22 | sub_dir_list = ["images", "isos", "steps_data"] |
| 23 | for sub_dir in sub_dir_list: |
| 24 | sub_dir_path = os.path.join(base_dir, sub_dir) |
| 25 | if not os.path.isdir(sub_dir_path): |
| 26 | logging.debug("Creating %s", sub_dir_path) |
| 27 | os.makedirs(sub_dir_path) |
| 28 | else: |
| 29 | logging.debug("Dir %s exists, not creating" % |
| 30 | sub_dir_path) |
| 31 | logging.info("Do you want to setup NFS mounts for some of those " |
| 32 | "dirs? (y/n)") |
| 33 | setup_nfs = raw_input() |
| 34 | if setup_nfs == 'y': |
| 35 | logging.info("Exiting the script so you can setup the NFS mounts. " |
| 36 | "When you are done, re-run this script.") |
| 37 | sys.exit(0) |
| 38 | |
| 39 | logging.info("2 - Creating config files from samples (copy the default " |
| 40 | "config samples to actual config files)") |
| 41 | kvm_test_dir = os.path.dirname(sys.modules[__name__].__file__) |
| 42 | kvm_test_dir = os.path.abspath(kvm_test_dir) |
| 43 | config_file_list = ["address_pools.cfg", "build.cfg", "cdkeys.cfg", |
| 44 | "tests_base.cfg", "tests.cfg"] |
| 45 | for config_file in config_file_list: |
| 46 | src_file = os.path.join(kvm_test_dir, "%s.sample" % config_file) |
| 47 | dst_file = os.path.join(kvm_test_dir, config_file) |
| 48 | if not os.path.isfile(dst_file): |
| 49 | logging.debug("Creating config file %s from sample", dst_file) |
| 50 | shutil.copyfile(src_file, dst_file) |
| 51 | else: |
| 52 | logging.debug("Config file %s exists, not touching" % dst_file) |
| 53 | |
| 54 | logging.info("3 - Verifying iso (make sure we have the OS iso needed for " |
| 55 | "the default test set)") |
| 56 | base_iso_name = "Fedora-12-x86_64-DVD.iso" |
| 57 | fedora_dir = "pub/fedora/linux/releases/12/Fedora/x86_64/iso" |
| 58 | url = os.path.join("http://download.fedoraproject.org/", fedora_dir, |
| 59 | base_iso_name) |
| 60 | md5sum = "6dd31e292cc2eb1140544e9b1ba61c56" |
lmr | 3fa4bd0 | 2010-02-04 18:04:18 +0000 | [diff] [blame] | 61 | iso_dir = os.path.join(base_dir, 'isos', 'linux') |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 62 | if not iso_dir: |
| 63 | os.makedirs(iso_dir) |
| 64 | iso_path = os.path.join(iso_dir, base_iso_name) |
| 65 | if not os.path.isfile(iso_path) or ( |
lmr | a71f1a0 | 2010-02-04 12:17:49 +0000 | [diff] [blame] | 66 | utils.hash_file(iso_path, method="md5") != md5sum): |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 67 | logging.warning("%s not found or corrupted", iso_path) |
| 68 | logging.warning("Would you like to download it? (y/n)") |
| 69 | iso_download = raw_input() |
| 70 | if iso_download == 'y': |
lmr | a71f1a0 | 2010-02-04 12:17:49 +0000 | [diff] [blame] | 71 | utils.unmap_url_cache(iso_dir, url, md5sum) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 72 | else: |
lmr | 67e907c | 2010-02-04 18:08:05 +0000 | [diff] [blame^] | 73 | logging.warning("Missing file %s. Please download it", iso_path) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 74 | else: |
lmr | 67e907c | 2010-02-04 18:08:05 +0000 | [diff] [blame^] | 75 | logging.debug("%s present, with proper checksum", iso_path) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 76 | |
| 77 | logging.info("4 - Checking if qemu is installed (certify qemu and qemu-kvm " |
| 78 | "are in the place the default config expects)") |
| 79 | qemu_default_paths = ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img'] |
| 80 | for qemu_path in qemu_default_paths: |
| 81 | if not os.path.isfile(qemu_path): |
lmr | 67e907c | 2010-02-04 18:08:05 +0000 | [diff] [blame^] | 82 | logging.warning("No %s found. You might need to install qemu-kvm.", |
| 83 | qemu_path) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 84 | else: |
lmr | 67e907c | 2010-02-04 18:08:05 +0000 | [diff] [blame^] | 85 | logging.debug("%s present", qemu_path) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 86 | |
| 87 | logging.info("5 - Checking for the KVM module (make sure kvm is loaded " |
| 88 | "to accelerate qemu-kvm)") |
| 89 | if not utils.module_is_loaded("kvm"): |
| 90 | logging.warning("KVM module is not loaded. You might want to load it") |
| 91 | else: |
| 92 | logging.debug("KVM module loaded") |
| 93 | |
| 94 | logging.info("6 - Verify needed packages to get started") |
| 95 | logging.info("Please take a look at the online documentation " |
| 96 | "http://www.linux-kvm.org/page/KVM-Autotest/Client_Install " |
| 97 | "(session 'Install Prerequisite packages')") |
| 98 | |
| 99 | client_dir = os.path.abspath(os.path.join(kvm_test_dir, "..", "..")) |
| 100 | autotest_bin = os.path.join(client_dir, 'bin', 'autotest') |
| 101 | control_file = os.path.join(kvm_test_dir, 'control') |
| 102 | logging.info("When you are done fixing eventual warnings found, " |
lmr | d7f8585 | 2010-02-04 12:33:08 +0000 | [diff] [blame] | 103 | "you can run the kvm test using the command line AS ROOT:") |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 104 | logging.info("%s --verbose %s", autotest_bin, control_file) |
| 105 | logging.info("You can also edit the test config files (see output of " |
| 106 | "step 2 for a list)") |