virt-test: Bootstrap using other OS images. Upstream-Status: Accepted Signed-off-by: Petre Pircalabu --- a/run +++ b/run @@ -10,6 +10,7 @@ import traceback import signal import optparse import logging +import virttest.defaults class StreamProxy(object): @@ -173,9 +174,8 @@ class VirtTestRunParser(optparse.OptionP def __init__(self): optparse.OptionParser.__init__(self, usage='Usage: %prog [options]') from virttest import data_dir - from virttest import bootstrap - jeos_info = bootstrap.get_jeos_info() - self.default_guest_os = jeos_info['variant'] + os_info = virttest.defaults.get_default_guest_os_info() + self.default_guest_os = os_info['variant'] try: qemu_bin_path = _find_default_qemu_paths()[0] @@ -267,7 +267,7 @@ class VirtTestRunParser(optparse.OptionP help=("Machine type under test. " "If -c is provided, this will be ignored. " "Default: all for the chosen guests, %s if " - "--guest-os not given." % DEFAULT_MACHINE_TYPE)) + "--guest-os not given." % virttest.defaults.DEFAULT_MACHINE_TYPE)) general.add_option("--tests", action="store", dest="tests", default="", help=('List of space separated tests to be ' @@ -415,7 +415,6 @@ def variant_only_file(filename): return ", ".join(result) -DEFAULT_MACHINE_TYPE = "i440fx" QEMU_DEFAULT_SET = "migrate..tcp, migrate..unix, migrate..exec, migrate..fd" LIBVIRT_DEFAULT_SET = variant_only_file('backends/libvirt/cfg/default_tests') LVSB_DEFAULT_SET = ("lvsb_date") @@ -546,7 +545,7 @@ class VirtTestApp(object): # TODO: this is x86-specific, instead we can get the default # arch from qemu binary and run on all supported machine types if self.options.arch is None and self.options.guest_os is None: - self.cartesian_parser.only_filter(DEFAULT_MACHINE_TYPE) + self.cartesian_parser.only_filter(virttest.defaults.DEFAULT_MACHINE_TYPE) else: self.cartesian_parser.only_filter(self.options.machine_type) else: @@ -827,7 +826,9 @@ class VirtTestApp(object): selinux=self.options.selinux_setup, restore_image=keep_image, verbose=self.options.verbose, - update_providers=self.options.update_providers) + update_providers=self.options.update_providers, + guest_os=(self.options.guest_os or + self.option_parser.default_guest_os)) sys.exit(0) if self.options.type: --- a/virttest/bootstrap.py +++ b/virttest/bootstrap.py @@ -9,6 +9,7 @@ import data_dir import asset import cartesian_config import utils_selinux +import defaults basic_program_requirements = ['tcpdump', 'nc', 'ip', 'arping'] @@ -53,15 +54,30 @@ last_subtest = {'qemu': ['shutdown'], test_filter = ['__init__', 'cfg', 'dropin.py'] -def get_jeos_info(): +def get_guest_os_info_list(test_name, guest_os): """ - Gets the correct asset and variant information depending on host OS. + Returns a list of matching assets compatible with the specified test name + and guest OS """ - jeos_info = {'asset': 'jeos-19-64', 'variant': 'JeOS.19'} - issue_contents = utils.read_file('/etc/issue') - if 'Fedora' in issue_contents and '20' in issue_contents: - jeos_info = {'asset': 'jeos-20-64', 'variant': 'JeOS.20'} - return jeos_info + + os_info_list = [] + + cartesian_parser = cartesian_config.Parser() + cartesian_parser.parse_file(data_dir.get_backend_cfg_path(test_name, 'guest-os.cfg')) + cartesian_parser.only_filter(guest_os) + dicts = cartesian_parser.get_dicts(); + + for params in dicts: + image_name = params.get('image_name', 'image').split('/')[-1] + shortname = params.get('shortname', guest_os) + os_info_list.append({'asset': image_name, 'variant': shortname}) + + if not os_info_list: + logging.error("Could not find any assets compatible with %s for %s", + guest_os, test_name) + raise ValueError("Missing compatible assets for %s", guest_os) + + return os_info_list def _get_config_filter(): @@ -704,7 +720,8 @@ def verify_selinux(datadir, imagesdir, i def bootstrap(test_name, test_dir, base_dir, default_userspace_paths, check_modules, online_docs_url, restore_image=False, download_image=True, interactive=True, selinux=False, - verbose=False, update_providers=False): + verbose=False, update_providers=False, + guest_os=defaults.DEFAULT_GUEST_OS): """ Common virt test assistant module. @@ -723,6 +740,8 @@ def bootstrap(test_name, test_dir, base_ :param selinux: Whether setup SELinux contexts for shared/data. :param update_providers: Whether to update test providers if they are already downloaded. + :param guest_os: Specify the guest image used for bootstrapping. By default + the JeOS image is used. :raise error.CmdError: If JeOS image failed to uncompress :raise ValueError: If 7za was not found @@ -790,10 +809,10 @@ def bootstrap(test_name, test_dir, base_ step += 2 logging.info("%s - Verifying (and possibly downloading) guest image", step) - jeos_info = get_jeos_info() - jeos_asset = jeos_info['asset'] - asset.download_asset(jeos_asset, interactive=interactive, - restore_image=restore_image) + for os_info in get_guest_os_info_list(test_name, guest_os): + os_asset = os_info['asset'] + asset.download_asset(os_asset, interactive=interactive, + restore_image=restore_image) if check_modules: logging.info("") --- /dev/null +++ b/virttest/defaults.py @@ -0,0 +1,18 @@ +DEFAULT_MACHINE_TYPE = "i440fx" +DEFAULT_GUEST_OS = "JeOS.19" + + +def get_default_guest_os_info(): + """ + Gets the default asset and variant information depending on host OS + """ + os_info = {'asset': 'jeos-19-64', 'variant': DEFAULT_GUEST_OS} + + from autotest.client import utils + + issue_contents = utils.read_file('/etc/issue') + + if 'Fedora' in issue_contents and '20' in issue_contents: + os_info = {'asset': 'jeos-20-64', 'variant': 'JeOS.20'} + + return os_info --- a/virttest/standalone_test.py +++ b/virttest/standalone_test.py @@ -24,6 +24,7 @@ import arch import funcatexit import version import qemu_vm +import defaults global GUEST_NAME_LIST GUEST_NAME_LIST = None @@ -226,7 +227,7 @@ class Test(object): % error_message) except Exception, e: - if (not t_type is None): + if (t_type is not None): error_message = funcatexit.run_exitfuncs(env, t_type) if error_message: logging.error(error_message) @@ -306,7 +307,7 @@ class Bcolors(object): allowed_terms = ['linux', 'xterm', 'xterm-256color', 'vt100', 'screen', 'screen-256color'] term = os.environ.get("TERM") - if (not os.isatty(1)) or (not term in allowed_terms): + if (not os.isatty(1)) or (term not in allowed_terms): self.disable() def disable(self): @@ -392,7 +393,7 @@ def print_fail(t_elapsed, open_fd=False) bcolors.ENDC + " (%.2f s)" % t_elapsed) fd_fail_msg = (bcolors.FAIL + "FAIL" + bcolors.ENDC + " (%.2f s) (%s fd)" % - (t_elapsed, utils_misc.get_virt_test_open_fds())) + (t_elapsed, utils_misc.get_virt_test_open_fds())) if open_fd: msg = fd_fail_msg else: @@ -667,6 +668,8 @@ def bootstrap_tests(options): else: restore_image = False + os_info = defaults.get_default_guest_os_info() + kwargs = {'test_name': options.type, 'test_dir': test_dir, 'base_dir': data_dir.get_data_dir(), @@ -677,7 +680,8 @@ def bootstrap_tests(options): 'selinux': options.selinux_setup, 'restore_image': restore_image, 'interactive': False, - 'update_providers': options.update_providers} + 'update_providers': options.update_providers, + 'guest_os': options.guest_os or os_info['variant']} # Tolerance we have without printing a message for the user to wait (3 s) tolerance = 3 @@ -909,7 +913,7 @@ def run_tests(parser, options): dependencies_satisfied = True for dep in dct.get("dep"): for test_name in status_dct.keys(): - if not dep in test_name: + if dep not in test_name: continue if not status_dct[test_name]: