From patchwork Wed Jun 10 12:36:30 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 29289 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 n5ACbdvk027905 for ; Wed, 10 Jun 2009 12:37:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759285AbZFJMgd (ORCPT ); Wed, 10 Jun 2009 08:36:33 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759708AbZFJMgc (ORCPT ); Wed, 10 Jun 2009 08:36:32 -0400 Received: from mx1.redhat.com ([66.187.233.31]:44168 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759676AbZFJMgb (ORCPT ); Wed, 10 Jun 2009 08:36:31 -0400 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n5ACaWhV030842; Wed, 10 Jun 2009 08:36:32 -0400 Received: from mail05.corp.redhat.com (zmail05.collab.prod.int.phx2.redhat.com [10.5.5.46]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5ACaVOa024912; Wed, 10 Jun 2009 08:36:31 -0400 Date: Wed, 10 Jun 2009 08:36:30 -0400 (EDT) From: Michael Goldish To: Lucas Meneghel Rodrigues Cc: kvm@vger.kernel.org, autotest@test.kernel.org Message-ID: <1612655821.1664961244637390865.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> In-Reply-To: <1687074683.1663751244636480061.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> Subject: Re: [Autotest] [KVM-AUTOTEST PATCH 2/4] Make kvm_config.py to use internal/standard exeptions MIME-Version: 1.0 X-Originating-IP: [10.5.5.72] X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org One more thing: maybe we shouldn't test if the file exists and raise IOError ourselves -- python does this automatically anyway when we call open() for a file that doesn't exist. ----- Original Message ----- From: "Michael Goldish" To: "Lucas Meneghel Rodrigues" Cc: kvm@vger.kernel.org, autotest@test.kernel.org Sent: Wednesday, June 10, 2009 3:21:20 PM (GMT+0200) Auto-Detected Subject: Re: [Autotest] [KVM-AUTOTEST PATCH 2/4] Make kvm_config.py to use internal/standard exeptions Looks fine to me. BTW, I think debug_print() should be prefixed by a single underscore, not two. A double underscore should be used only when name mangling is required -- at least that's what I understood from PEP 8. Let me know what you think. Thanks, Michael ----- Original Message ----- From: "Lucas Meneghel Rodrigues" To: autotest@test.kernel.org Cc: kvm@vger.kernel.org Sent: Tuesday, June 9, 2009 7:33:27 PM (GMT+0200) Auto-Detected Subject: [Autotest] [KVM-AUTOTEST PATCH 2/4] Make kvm_config.py to use internal/standard exeptions Instead of resorting to internal autotest exception types, use either python standard exceptions or an internally defined ConfigError exception. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm_config.py | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py index a3467a0..cce931a 100755 --- a/client/tests/kvm/kvm_config.py +++ b/client/tests/kvm/kvm_config.py @@ -8,6 +8,11 @@ KVM configuration file utility functions. @copyright: Red Hat 2008-2009 """ + +class ConfigError(Exception): + pass + + class config: """ Parse an input file or string that follows the KVM Test Config File format @@ -47,7 +52,7 @@ class config: @param filename: Path of the configuration file. """ if not os.path.exists(filename): - raise Exception, "File %s not found" % filename + raise IOError("File %s not found" % filename) self.filename = filename file = open(filename, "r") self.list = self.parse(file, self.list) @@ -357,7 +362,7 @@ class config: # (inside an exception or inside subvariants) if restricted: e_msg = "Using variants in this context is not allowed" - raise error.AutotestError() + raise ConfigError(e_msg) if self.debug and not restricted: self.__debug_print(indented_line, "Entering variants block (%d dicts in" @@ -402,7 +407,7 @@ class config: words[1]) if not os.path.exists(filename): e_msg = "Cannot include %s -- file not found" % filename - raise error.AutotestError(e_msg) + raise ConfigError(e_msg) new_file = open(filename, "r") list = self.parse(new_file, list, restricted) new_file.close() @@ -410,7 +415,7 @@ class config: self.__debug_print("", "Leaving file %s" % words[1]) else: e_msg = "Cannot include anything because no file is open" - raise error.AutotestError(e_msg) + raise ConfigError(e_msg) # Parse multi-line exceptions # (the block is parsed for each dict separately)