From patchwork Wed Jul 29 03:40:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 38055 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 n6T3ejCo001791 for ; Wed, 29 Jul 2009 03:40:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755177AbZG2Dkl (ORCPT ); Tue, 28 Jul 2009 23:40:41 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754729AbZG2Dkl (ORCPT ); Tue, 28 Jul 2009 23:40:41 -0400 Received: from mx2.redhat.com ([66.187.237.31]:33113 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754499AbZG2Dkk (ORCPT ); Tue, 28 Jul 2009 23:40:40 -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 n6T3ec76024670; Tue, 28 Jul 2009 23:40:38 -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 n6T3ebbk013562; Tue, 28 Jul 2009 23:40:37 -0400 Received: from localhost.localdomain (vpn-10-56.bos.redhat.com [10.16.10.56]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6T3eWUB024642; Tue, 28 Jul 2009 23:40:35 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, ldoktor@redhat.com, ryanh@us.ibm.com, mgoldish@redhat.com, Lucas Meneghel Rodrigues Subject: [KVM AUTOTEST PATCH] [RFC] KVM test: keep record of supported qemu options Date: Wed, 29 Jul 2009 00:40:29 -0300 Message-Id: <1248838829-7804-2-git-send-email-lmr@redhat.com> In-Reply-To: <1248838829-7804-1-git-send-email-lmr@redhat.com> References: <1248838829-7804-1-git-send-email-lmr@redhat.com> 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 In order to make it easier to figure out problems and also to avoid aborting tests prematurely due to incompatible qemu options, keep record of supported qemu options, and if extra options are passed to qemu, verify if they are amongst the supported options. Also, try to replace known misspelings on options in case something goes wrong, and be generous logging any problems. This first version of the patch gets supported flags from the output of qemu --help. I thought this would be good enough for a first start. I am asking for input on whether this is needed, and if yes, if the approach looks good. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm_vm.py | 79 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 77 insertions(+), 2 deletions(-) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index eba9b84..0dd34c2 100644 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -121,6 +121,7 @@ class VM: self.qemu_path = qemu_path self.image_dir = image_dir self.iso_dir = iso_dir + self.qemu_supported_flags = self.get_qemu_supported_flags() # Find available monitor filename @@ -258,7 +259,7 @@ class VM: extra_params = params.get("extra_params") if extra_params: - qemu_cmd += " %s" % extra_params + qemu_cmd += " %s" % self.process_qemu_extra_params(extra_params) for redir_name in kvm_utils.get_sub_dict_names(params, "redirs"): redir_params = kvm_utils.get_sub_dict(params, redir_name) @@ -751,7 +752,7 @@ class VM: else: self.send_key(char) - + def get_uuid(self): """ Catch UUID of the VM. @@ -762,3 +763,77 @@ class VM: return self.uuid else: return self.params.get("uuid", None) + + + def get_qemu_supported_flags(self): + """ + Gets all supported qemu options from qemu-help. This is a useful + procedure to quickly spot problems with incompatible qemu flags. + """ + cmd = self.qemu_path + ' --help' + (status, output) = kvm_subprocess.run_fg(cmd) + supported_flags = [] + + if status: + logging.error('Process qemu --help ended with exit code !=0. ' + 'No supported qemu flags will be recorded.') + return supported_flags + + for line in output.split('\n'): + if line and line.startswith('-'): + flag = line.split()[0] + if flag not in supported_flags: + supported_flags.append(flag) + + return supported_flags + + + def process_qemu_extra_params(self, extra_params): + """ + Verifies an extra param passed to qemu to see if it's supported by the + current qemu version. If it's not supported, try to find an appropriate + replacement on a list of known option misspellings. + + @param extra_params: String with a qemu command line option. + """ + flag = extra_params.split()[0] + + if flag not in self.qemu_supported_flags: + logging.error("Flag %s does not seem to be supported by the " + "current qemu version. Looking for a replacement...", + flag) + supported_flag = self.get_qemu_flag_replacement(flag) + if supported_flag: + logging.debug("Replacing flag %s with %s", flag, + supported_flag) + extra_params = extra_params.replace(flag, supported_flag) + else: + logging.error("No valid replacement was found for flag %s.", + flag) + + return extra_params + + + def get_qemu_flag_replacement(self, option): + """ + Searches on a list of known misspellings for qemu options and returns + a replacement. If no replacement can be found, return None. + + @param option: String representing qemu option (such as -mem). + + @return: Option replacement, or None, if none found. + """ + list_mispellings = [['-mem-path', '-mempath'],] + replacement = None + + for mispellings in list_mispellings: + if option in mispellings: + option_position = mispellings.index(option) + replacement = mispellings[1 - option_position] + + if replacement not in self.qemu_supported_flags: + logging.error("Replacement %s also does not seem to be a valid " + "qemu flag, aborting replacement.", replacement) + return None + + return replacement