blob: 6fa6b5fd457b184903e5a7c837ce83ed5ca5aaa9 [file] [log] [blame]
lmra29d1f82010-02-03 18:43:16 +00001#!/usr/bin/python
2"""
3Program to help setup kvm test environment
4
5@copyright: Red Hat 2010
6"""
7
8import os, sys, optparse, logging, shutil
9import common, kvm_utils
10from autotest_lib.client.common_lib import logging_manager
11from autotest_lib.client.bin import utils, os_dep
12
13
lmr5af11f12010-05-04 16:14:56 +000014def 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
lmra29d1f82010-02-03 18:43:16 +000042if __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 Lie0493a42010-11-15 13:05:43 -080071 config_file_list = ["build.cfg", "cdkeys.cfg", "tests_base.cfg",
72 "tests.cfg", "unittests.cfg"]
lmra29d1f82010-02-03 18:43:16 +000073 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
lmr5af11f12010-05-04 16:14:56 +000082 logging.info("3 - Verifying iso (make sure we have the OS ISO needed for "
lmra29d1f82010-02-03 18:43:16 +000083 "the default test set)")
lmr5af11f12010-05-04 16:14:56 +000084
lmr70a65fe2010-05-31 23:57:37 +000085 iso_name = "Fedora-13-x86_64-DVD.iso"
86 fedora_dir = "pub/fedora/linux/releases/13/Fedora/x86_64/iso"
lmra29d1f82010-02-03 18:43:16 +000087 url = os.path.join("http://download.fedoraproject.org/", fedora_dir,
lmr5af11f12010-05-04 16:14:56 +000088 iso_name)
lmr70a65fe2010-05-31 23:57:37 +000089 hash = "65c7f1aad3feb888ae3daadaf45d4a2a32b8773a"
lmr5af11f12010-05-04 16:14:56 +000090 destination = os.path.join(base_dir, 'isos', 'linux')
91 check_iso(url, destination, hash)
lmra29d1f82010-02-03 18:43:16 +000092
lmr5af11f12010-05-04 16:14:56 +000093 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"
lmrecd3cfe2010-07-27 17:12:15 +0000100 hash = "02930224756510e383c44c49bffb760e35d6f892"
lmr5af11f12010-05-04 16:14:56 +0000101 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 "
lmra29d1f82010-02-03 18:43:16 +0000105 "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):
lmr67e907c2010-02-04 18:08:05 +0000109 logging.warning("No %s found. You might need to install qemu-kvm.",
110 qemu_path)
lmra29d1f82010-02-03 18:43:16 +0000111 else:
lmr67e907c2010-02-04 18:08:05 +0000112 logging.debug("%s present", qemu_path)
lmra29d1f82010-02-03 18:43:16 +0000113
lmr5af11f12010-05-04 16:14:56 +0000114 logging.info("6 - Checking for the KVM module (make sure kvm is loaded "
lmra29d1f82010-02-03 18:43:16 +0000115 "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
lmr5af11f12010-05-04 16:14:56 +0000121 logging.info("7 - Verify needed packages to get started")
lmra29d1f82010-02-03 18:43:16 +0000122 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, "
lmrd7f85852010-02-04 12:33:08 +0000130 "you can run the kvm test using the command line AS ROOT:")
lmra29d1f82010-02-03 18:43:16 +0000131 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)")