Currently, qemu and qemu-img are accessed via symlinks that must be present in test.bindir (the KVM test dir). This patch adds new parameters qemu_binary and qemu_img_binary, which specify the paths of the qemu and qemu-img binaries. They may be absolute paths or relative to test.bindir (the KVM test dir). In kvm_tests.cfg.sample they are set to 'qemu' and 'qemu-img', which means the binaries are expected to be found in test.bindir, which is the current behavior. Adding these parameters results in slightly cleaner code, but also allows for some more flexibility in defining tests. For example, the user can 'variant' on the parameter qemu_binary, i.e. define several variants of a test set that differ only in this parameter. This will make the test set run several times, each time using a different pre-installed version of qemu. The parameters also make it possible to use pre-installed qemu and qemu-img that reside somewhere outside the Autotest dir, e.g. in /usr/bin. Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx> --- client/tests/kvm/kvm_preprocessing.py | 18 +++++++----------- client/tests/kvm/kvm_tests.cfg.sample | 2 ++ client/tests/kvm/kvm_vm.py | 33 ++++++++++----------------------- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 17a82f4..7c16305 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -12,7 +12,6 @@ def preprocess_image(test, params): @param params: A dict containing image preprocessing parameters. @note: Currently this function just creates an image if requested. """ - qemu_img_path = os.path.join(test.bindir, "qemu-img") image_filename = kvm_vm.get_image_filename(params, test.bindir) create_image = False @@ -20,13 +19,13 @@ def preprocess_image(test, params): if params.get("force_create_image") == "yes": logging.debug("'force_create_image' specified; creating image...") create_image = True - elif params.get("create_image") == "yes" and not \ - os.path.exists(image_filename): + elif (params.get("create_image") == "yes" and not + os.path.exists(image_filename)): logging.debug("Creating image...") create_image = True if create_image: - if not kvm_vm.create_image(params, qemu_img_path, test.bindir): + if not kvm_vm.create_image(params, test.bindir): message = "Could not create image" logging.error(message) raise error.TestError(message) @@ -42,16 +41,13 @@ def preprocess_vm(test, params, env, name): @param env: The environment (a dict-like object). @param name: The name of the VM object. """ - qemu_path = os.path.join(test.bindir, "qemu") - logging.debug("Preprocessing VM '%s'..." % name) vm = kvm_utils.env_get_vm(env, name) if vm: logging.debug("VM object found in environment") else: logging.debug("VM object does not exist; creating it") - vm = kvm_vm.VM(name, params, qemu_path, test.bindir, - env.get("address_cache")) + vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache")) kvm_utils.env_register_vm(env, name, vm) start_vm = False @@ -70,14 +66,13 @@ def preprocess_vm(test, params, env, name): logging.debug("VM is not alive; starting it...") start_vm = True elif vm.make_qemu_command() != vm.make_qemu_command(name, params, - qemu_path, test.bindir): logging.debug("VM's qemu command differs from requested one; " "restarting it...") start_vm = True if start_vm: - if not vm.create(name, params, qemu_path, test.bindir, for_migration): + if not vm.create(name, params, test.bindir, for_migration): message = "Could not start VM" logging.error(message) raise error.TestError(message) @@ -247,7 +242,8 @@ def preprocess(test, params, env): # Get the KVM userspace version and write it as a keyval logging.debug("Fetching KVM userspace version...") - qemu_path = os.path.join(test.bindir, "qemu") + qemu_path = kvm_utils.get_path(test.bindir, params.get("qemu_binary", + "qemu")) version_line = commands.getoutput("%s -help | head -n 1" % qemu_path) exp = re.compile("[Vv]ersion .*?,") match = exp.search(version_line) diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample index baebd64..74901a6 100644 --- a/client/tests/kvm/kvm_tests.cfg.sample +++ b/client/tests/kvm/kvm_tests.cfg.sample @@ -15,6 +15,8 @@ kill_vm = no kill_vm_gracefully = yes # Some default VM params +qemu_binary = qemu +qemu_img_binary = qemu-img mem = 512 image_size = 10G shell_port = 22 diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index b2f0345..9016ed3 100644 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -27,12 +27,11 @@ def get_image_filename(params, root_dir): return image_filename -def create_image(params, qemu_img_path, root_dir): +def create_image(params, root_dir): """ Create an image using qemu_image. @param params: Dictionary containing the test parameters. - @param qemu_img_path: The path of the qemu-img binary @param root_dir: Base directory for relative filenames. @note: params should contain: @@ -41,7 +40,8 @@ def create_image(params, qemu_img_path, root_dir): image_size -- the requested size of the image (a string qemu-img can understand, such as '10G') """ - qemu_img_cmd = qemu_img_path + qemu_img_cmd = kvm_utils.get_path(root_dir, params.get("qemu_img_binary", + "qemu-img")) qemu_img_cmd += " create" format = params.get("image_format", "qcow2") @@ -100,14 +100,13 @@ class VM: This class handles all basic VM operations. """ - def __init__(self, name, params, qemu_path, root_dir, address_cache): + def __init__(self, name, params, root_dir, address_cache): """ Initialize the object and set a few attributes. @param name: The name of the object @param params: A dict containing VM params (see method make_qemu_command for a full description) - @param qemu_path: The path of the qemu binary @param root_dir: Base directory for relative filenames @param address_cache: A dict that maps MAC addresses to IP addresses """ @@ -118,7 +117,6 @@ class VM: self.name = name self.params = params - self.qemu_path = qemu_path self.root_dir = root_dir self.address_cache = address_cache @@ -133,8 +131,7 @@ class VM: break - def clone(self, name=None, params=None, qemu_path=None, root_dir=None, - address_cache=None): + def clone(self, name=None, params=None, root_dir=None, address_cache=None): """ Return a clone of the VM object with optionally modified parameters. The clone is initially not alive and needs to be started using create(). @@ -143,7 +140,6 @@ class VM: @param name: Optional new VM name @param params: Optional new VM creation parameters - @param qemu_path: Optional new path to qemu @param root_dir: Optional new base directory for relative filenames @param address_cache: A dict that maps MAC addresses to IP addresses """ @@ -151,17 +147,14 @@ class VM: name = self.name if params == None: params = self.params.copy() - if qemu_path == None: - qemu_path = self.qemu_path if root_dir == None: root_dir = self.root_dir if address_cache == None: address_cache = self.address_cache - return VM(name, params, qemu_path, root_dir, address_cache) + return VM(name, params, root_dir, address_cache) - def make_qemu_command(self, name=None, params=None, qemu_path=None, - root_dir=None): + def make_qemu_command(self, name=None, params=None, root_dir=None): """ Generate a qemu command line. All parameters are optional. If a parameter is not supplied, the corresponding value stored in the @@ -169,7 +162,6 @@ class VM: @param name: The name of the object @param params: A dict containing VM params - @param qemu_path: The path of the qemu binary @param root_dir: Base directory for relative filenames @note: The params dict should contain: @@ -202,8 +194,6 @@ class VM: name = self.name if params == None: params = self.params - if qemu_path == None: - qemu_path = self.qemu_path if root_dir == None: root_dir = self.root_dir @@ -213,7 +203,8 @@ class VM: if params.get("x11_display"): qemu_cmd += "DISPLAY=%s " % params.get("x11_display") # Add the qemu binary - qemu_cmd += qemu_path + qemu_cmd += kvm_utils.get_path(root_dir, params.get("qemu_binary", + "qemu")) # Add the VM's name qemu_cmd += " -name '%s'" % name # Add the monitor socket parameter @@ -295,7 +286,7 @@ class VM: return qemu_cmd - def create(self, name=None, params=None, qemu_path=None, root_dir=None, + def create(self, name=None, params=None, root_dir=None, for_migration=False, timeout=5.0): """ Start the VM by running a qemu command. @@ -306,7 +297,6 @@ class VM: @param name: The name of the object @param params: A dict containing VM params - @param qemu_path: The path of the qemu binary @param root_dir: Base directory for relative filenames @param for_migration: If True, start the VM with the -incoming option @@ -317,13 +307,10 @@ class VM: self.name = name if params != None: self.params = params - if qemu_path != None: - self.qemu_path = qemu_path if root_dir != None: self.root_dir = root_dir name = self.name params = self.params - qemu_path = self.qemu_path root_dir = self.root_dir # Verify the md5sum of the ISO image -- 1.5.4.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html