From patchwork Sun Aug 9 16:33:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 40271 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n79GVgxP000562 for ; Sun, 9 Aug 2009 16:31:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751993AbZHIQbg (ORCPT ); Sun, 9 Aug 2009 12:31:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751926AbZHIQbg (ORCPT ); Sun, 9 Aug 2009 12:31:36 -0400 Received: from mx2.redhat.com ([66.187.237.31]:35281 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751945AbZHIQb2 (ORCPT ); Sun, 9 Aug 2009 12:31:28 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n79GVSGi021955; Sun, 9 Aug 2009 12:31:28 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n79GVRKZ030032; Sun, 9 Aug 2009 12:31:28 -0400 Received: from localhost.localdomain (dhcp-1-31.tlv.redhat.com [10.35.1.31]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n79GVGYI020666; Sun, 9 Aug 2009 12:31:26 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 6/6] KVM test: allow the user to specify the paths of the qemu and qemu-img binaries Date: Sun, 9 Aug 2009 19:33:58 +0300 Message-Id: <031e8250adce7feeafe752eabd1d3482c6effdfa.1249835043.git.mgoldish@redhat.com> In-Reply-To: <65e956e30f642969df50865e46ba70983fd101e5.1249835043.git.mgoldish@redhat.com> References: <1249835638-18153-1-git-send-email-mgoldish@redhat.com> <836c405266cd58509071052cc25072d52e84f9a7.1249835043.git.mgoldish@redhat.com> <1872f2f7ac12ca9fa788f5f14ae2f8afc9f26db7.1249835043.git.mgoldish@redhat.com> <65e956e30f642969df50865e46ba70983fd101e5.1249835043.git.mgoldish@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- 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