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 | |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 14 | def check_iso(url, destination, hash): |
| 15 | """ |
| 16 | Verifies if ISO that can be find on url is on destination with right hash. |
| 17 | |
| 18 | This function will verify the SHA1 hash of the ISO image. If the file |
| 19 | turns out to be missing or corrupted, let the user know we can download it. |
| 20 | |
| 21 | @param url: URL where the ISO file can be found. |
| 22 | @param destination: Directory in local disk where we'd like the iso to be. |
| 23 | @param hash: SHA1 hash for the ISO image. |
| 24 | """ |
| 25 | logging.info("Verifying iso %s", os.path.basename(url)) |
| 26 | if not destination: |
| 27 | os.makedirs(destination) |
| 28 | iso_path = os.path.join(destination, os.path.basename(url)) |
| 29 | if not os.path.isfile(iso_path) or ( |
| 30 | utils.hash_file(iso_path, method="sha1") != hash): |
| 31 | logging.warning("%s not found or corrupted", iso_path) |
| 32 | logging.warning("Would you like to download it? (y/n)") |
| 33 | iso_download = raw_input() |
| 34 | if iso_download == 'y': |
| 35 | utils.unmap_url_cache(destination, url, hash, method="sha1") |
| 36 | else: |
| 37 | logging.warning("Missing file %s. Please download it", iso_path) |
| 38 | else: |
| 39 | logging.debug("%s present, with proper checksum", iso_path) |
| 40 | |
| 41 | |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 42 | if __name__ == "__main__": |
| 43 | logging_manager.configure_logging(kvm_utils.KvmLoggingConfig(), |
| 44 | verbose=True) |
| 45 | logging.info("KVM test config helper") |
| 46 | |
| 47 | logging.info("1 - Verifying directories (check if the directory structure " |
| 48 | "expected by the default test config is there)") |
| 49 | base_dir = "/tmp/kvm_autotest_root" |
| 50 | sub_dir_list = ["images", "isos", "steps_data"] |
| 51 | for sub_dir in sub_dir_list: |
| 52 | sub_dir_path = os.path.join(base_dir, sub_dir) |
| 53 | if not os.path.isdir(sub_dir_path): |
| 54 | logging.debug("Creating %s", sub_dir_path) |
| 55 | os.makedirs(sub_dir_path) |
| 56 | else: |
| 57 | logging.debug("Dir %s exists, not creating" % |
| 58 | sub_dir_path) |
| 59 | logging.info("Do you want to setup NFS mounts for some of those " |
| 60 | "dirs? (y/n)") |
| 61 | setup_nfs = raw_input() |
| 62 | if setup_nfs == 'y': |
| 63 | logging.info("Exiting the script so you can setup the NFS mounts. " |
| 64 | "When you are done, re-run this script.") |
| 65 | sys.exit(0) |
| 66 | |
| 67 | logging.info("2 - Creating config files from samples (copy the default " |
| 68 | "config samples to actual config files)") |
| 69 | kvm_test_dir = os.path.dirname(sys.modules[__name__].__file__) |
| 70 | kvm_test_dir = os.path.abspath(kvm_test_dir) |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 71 | config_file_list = ["build.cfg", "cdkeys.cfg", "tests_base.cfg", |
| 72 | "tests.cfg", "unittests.cfg"] |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 73 | for config_file in config_file_list: |
| 74 | src_file = os.path.join(kvm_test_dir, "%s.sample" % config_file) |
| 75 | dst_file = os.path.join(kvm_test_dir, config_file) |
| 76 | if not os.path.isfile(dst_file): |
| 77 | logging.debug("Creating config file %s from sample", dst_file) |
| 78 | shutil.copyfile(src_file, dst_file) |
| 79 | else: |
| 80 | logging.debug("Config file %s exists, not touching" % dst_file) |
| 81 | |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 82 | logging.info("3 - Verifying iso (make sure we have the OS ISO needed for " |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 83 | "the default test set)") |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 84 | |
Eric Li | 7edb304 | 2011-01-06 17:57:17 -0800 | [diff] [blame^] | 85 | iso_name = "Fedora-14-x86_64-DVD.iso" |
| 86 | fedora_dir = "pub/fedora/linux/releases/14/Fedora/x86_64/iso" |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 87 | url = os.path.join("http://download.fedoraproject.org/", fedora_dir, |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 88 | iso_name) |
Eric Li | 7edb304 | 2011-01-06 17:57:17 -0800 | [diff] [blame^] | 89 | hash = "38a4078011bac74493db7ecc53c9d9fbc96dbbd5" |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 90 | destination = os.path.join(base_dir, 'isos', 'linux') |
| 91 | check_iso(url, destination, hash) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 92 | |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 93 | logging.info("4 - Verifying winutils.iso (make sure we have the utility " |
| 94 | "ISO needed for Windows testing)") |
| 95 | |
| 96 | logging.info("In order to run the KVM autotests in Windows guests, we " |
| 97 | "provide you an ISO that this script can download") |
| 98 | |
| 99 | url = "http://people.redhat.com/mrodrigu/kvm/winutils.iso" |
lmr | ecd3cfe | 2010-07-27 17:12:15 +0000 | [diff] [blame] | 100 | hash = "02930224756510e383c44c49bffb760e35d6f892" |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 101 | destination = os.path.join(base_dir, 'isos', 'windows') |
| 102 | check_iso(url, destination, hash) |
| 103 | |
| 104 | logging.info("5 - Checking if qemu is installed (certify qemu and qemu-kvm " |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 105 | "are in the place the default config expects)") |
| 106 | qemu_default_paths = ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img'] |
| 107 | for qemu_path in qemu_default_paths: |
| 108 | if not os.path.isfile(qemu_path): |
lmr | 67e907c | 2010-02-04 18:08:05 +0000 | [diff] [blame] | 109 | logging.warning("No %s found. You might need to install qemu-kvm.", |
| 110 | qemu_path) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 111 | else: |
lmr | 67e907c | 2010-02-04 18:08:05 +0000 | [diff] [blame] | 112 | logging.debug("%s present", qemu_path) |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 113 | |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 114 | logging.info("6 - Checking for the KVM module (make sure kvm is loaded " |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 115 | "to accelerate qemu-kvm)") |
| 116 | if not utils.module_is_loaded("kvm"): |
| 117 | logging.warning("KVM module is not loaded. You might want to load it") |
| 118 | else: |
| 119 | logging.debug("KVM module loaded") |
| 120 | |
lmr | 5af11f1 | 2010-05-04 16:14:56 +0000 | [diff] [blame] | 121 | logging.info("7 - Verify needed packages to get started") |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 122 | logging.info("Please take a look at the online documentation " |
| 123 | "http://www.linux-kvm.org/page/KVM-Autotest/Client_Install " |
| 124 | "(session 'Install Prerequisite packages')") |
| 125 | |
| 126 | client_dir = os.path.abspath(os.path.join(kvm_test_dir, "..", "..")) |
| 127 | autotest_bin = os.path.join(client_dir, 'bin', 'autotest') |
| 128 | control_file = os.path.join(kvm_test_dir, 'control') |
| 129 | logging.info("When you are done fixing eventual warnings found, " |
lmr | d7f8585 | 2010-02-04 12:33:08 +0000 | [diff] [blame] | 130 | "you can run the kvm test using the command line AS ROOT:") |
lmr | a29d1f8 | 2010-02-03 18:43:16 +0000 | [diff] [blame] | 131 | logging.info("%s --verbose %s", autotest_bin, control_file) |
| 132 | logging.info("You can also edit the test config files (see output of " |
| 133 | "step 2 for a list)") |