From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 7C6D7C450 for ; Thu, 18 Jun 2015 05:06:54 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 17 Jun 2015 20:06:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,636,1427785200"; d="scan'208";a="510123503" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by FMSMGA003.fm.intel.com with ESMTP; 17 Jun 2015 20:06:52 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t5I36oEg009033; Thu, 18 Jun 2015 11:06:50 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t5I36mOi016889; Thu, 18 Jun 2015 11:06:50 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t5I36mio016885; Thu, 18 Jun 2015 11:06:48 +0800 From: Yong Liu To: dts@dpdk.org Date: Thu, 18 Jun 2015 11:06:36 +0800 Message-Id: <1434596804-16846-2-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1434596804-16846-1-git-send-email-yong.liu@intel.com> References: <1434596804-16846-1-git-send-email-yong.liu@intel.com> Subject: [dts] [dts 1/9] Optimize config load module with proper execption raised X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jun 2015 03:06:54 -0000 From: Marvin Liu Signed-off-by: Marvin Liu diff --git a/framework/config.py b/framework/config.py index 7e2436a..5948edb 100644 --- a/framework/config.py +++ b/framework/config.py @@ -37,6 +37,8 @@ import re import ConfigParser # config parse module import argparse # prase arguments module +from exception import ConfigParseException, VirtConfigParseException + PORTCONF = "conf/ports.cfg" CRBCONF = "conf/crbs.cfg" VIRTCONF = "conf/virt_global.cfg" @@ -50,7 +52,7 @@ class UserConf(): if load_files == []: print "FAILED LOADING %s!!!" % config self.conf = None - raise + raise ConfigParseException(config) def get_sections(self): if self.conf is None: @@ -91,9 +93,9 @@ class VirtConf(UserConf): self.virt_cfg = {} try: self.virt_conf = UserConf(self.config_file) - except Exception as e: - print "FAILED LOADING VIRT CONFIG!!!" + except ConfigParseException: self.virt_conf = None + raise VirtConfigParseException def load_virt_config(self, name): self.virt_cfgs = [] @@ -130,9 +132,9 @@ class PortConf(UserConf): self.pci_regex = "([\da-f]{2}:[\da-f]{2}.\d{1})$" try: self.port_conf = UserConf(self.config_file) - except Exception as e: - print "FAILED LOADING PORT CONFIG!!!" + except ConfigParseException: self.port_conf = None + raise PortConfigParseException def load_ports_config(self, crbIP): self.ports_cfg = {} @@ -185,7 +187,10 @@ if __name__ == '__main__': args = parser.parse_args() # not existed configuration file - VirtConf('/tmp/not-existed.cfg') + try: + VirtConf('/tmp/not-existed.cfg') + except VirtConfigParseException: + print "Capture config parse failure" # example for basic use configuration file conf = UserConf(PORTCONF) diff --git a/framework/exception.py b/framework/exception.py index 6e112c8..facbeed 100644 --- a/framework/exception.py +++ b/framework/exception.py @@ -131,3 +131,9 @@ class VirtDutConnectException(Exception): class VirtDutInitException(Exception): def __init__(self, vm_dut): self.vm_dut = vm_dut + +class VirtDeviceCreateException(Exception): + pass + +class VirtVmOperationException(Exception): + pass -- 1.9.3