blob: 617acaf0be8b235c746f62a625e26c8958e71b10 [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
14if __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"
61 iso_dir = os.path.join(base_dir, 'images', 'linux')
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 (
lmra71f1a02010-02-04 12:17:49 +000066 utils.hash_file(iso_path, method="md5") != md5sum):
lmra29d1f82010-02-03 18:43:16 +000067 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':
lmra71f1a02010-02-04 12:17:49 +000071 utils.unmap_url_cache(iso_dir, url, md5sum)
lmra29d1f82010-02-03 18:43:16 +000072 else:
73 logging.warning("Missing file %s. Please download it" % iso_path)
74 else:
75 logging.debug("%s present, with proper checksum")
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):
82 logging.warning("No %s found. You might need to install qemu-kvm.")
83 else:
84 logging.debug("%s present" % qemu_path)
85
86 logging.info("5 - Checking for the KVM module (make sure kvm is loaded "
87 "to accelerate qemu-kvm)")
88 if not utils.module_is_loaded("kvm"):
89 logging.warning("KVM module is not loaded. You might want to load it")
90 else:
91 logging.debug("KVM module loaded")
92
93 logging.info("6 - Verify needed packages to get started")
94 logging.info("Please take a look at the online documentation "
95 "http://www.linux-kvm.org/page/KVM-Autotest/Client_Install "
96 "(session 'Install Prerequisite packages')")
97
98 client_dir = os.path.abspath(os.path.join(kvm_test_dir, "..", ".."))
99 autotest_bin = os.path.join(client_dir, 'bin', 'autotest')
100 control_file = os.path.join(kvm_test_dir, 'control')
101 logging.info("When you are done fixing eventual warnings found, "
lmrd7f85852010-02-04 12:33:08 +0000102 "you can run the kvm test using the command line AS ROOT:")
lmra29d1f82010-02-03 18:43:16 +0000103 logging.info("%s --verbose %s", autotest_bin, control_file)
104 logging.info("You can also edit the test config files (see output of "
105 "step 2 for a list)")