test suite reviews and discussions
 help / color / mirror / Atom feed
From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dts] [PATCH v3 2/4] framework config: support suite&case level configuration
Date: Wed, 26 Jul 2017 21:07:51 -0400	[thread overview]
Message-ID: <1501117673-47762-3-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1501117673-47762-1-git-send-email-yong.liu@intel.com>

Suite level configuration will be shared with all cases belonged to the
suite. Case level configuration will be used just in the case. Case
level configuration will overlap those suite level configurations.

Few types of data are supported in suite&case level configuration.
They are "value_int", "value_hex", "list_int", "list_str" and default
string type. For more details, please reference to
conf/suite_sample.cfg.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/config.py b/framework/config.py
index 8d44bfe..9e514a7 100644
--- a/framework/config.py
+++ b/framework/config.py
@@ -32,17 +32,19 @@
 """
 Generic port and crbs configuration file load function
 """
-
+import os
 import re
 import ConfigParser  # config parse module
 import argparse      # prase arguments module
-from settings import IXIA
-from exception import ConfigParseException, VirtConfigParseException
+from settings import IXIA, CONFIG_ROOT_PATH, SUITE_SECTION_NAME
+from settings import load_global_setting, DTS_CFG_FOLDER
+from exception import ConfigParseException, VirtConfigParseException, PortConfigParseException
 
-PORTCONF = "conf/ports.cfg"
-CRBCONF = "conf/crbs.cfg"
-VIRTCONF = "conf/virt_global.cfg"
-IXIACONF = "conf/ixia.cfg"
+PORTCONF = "%s/ports.cfg" % CONFIG_ROOT_PATH
+CRBCONF = "%s/crbs.cfg" % CONFIG_ROOT_PATH
+VIRTCONF = "%s/virt_global.cfg" % CONFIG_ROOT_PATH
+IXIACONF = "%s/ixia.cfg" % CONFIG_ROOT_PATH
+SUITECONF_SAMPLE = "%s/suite_sample.cfg" % CONFIG_ROOT_PATH
 
 
 class UserConf():
@@ -51,7 +53,6 @@ class UserConf():
         self.conf = ConfigParser.SafeConfigParser()
         load_files = self.conf.read(config)
         if load_files == []:
-            print "FAILED LOADING %s!!!" % config
             self.conf = None
             raise ConfigParseException(config)
 
@@ -87,6 +88,55 @@ class UserConf():
         return paramDict
 
 
+class SuiteConf(UserConf):
+    def __init__(self, suite_name=""):
+        self.config_file = CONFIG_ROOT_PATH + os.sep + suite_name + ".cfg"
+        self.suite_cfg = {}
+        try:
+            self.suite_conf = UserConf(self.config_file)
+        except ConfigParseException:
+            self.suite_conf = None
+
+        # load default suite configuration
+        self.suite_cfg = self.load_case_config(SUITE_SECTION_NAME)
+
+    def load_case_config(self, case_name=""):
+        case_cfg = self.suite_cfg.copy()
+        if self.suite_conf is None:
+            return case_cfg
+
+        try:
+            case_confs = self.suite_conf.load_section(case_name)
+        except:
+            print "FAILED FIND CASE[%s] CONFIG!!!" % case_name
+            return case_cfg
+
+        if case_confs is None:
+            return case_cfg
+
+        conf = dict(case_confs)
+        for key, data_string in conf.items():
+            if data_string.startswith("value_int:"):
+                value = data_string[len("value_int:"):]
+                case_cfg[key] = int(value)
+            elif data_string.startswith("value_hex:"):
+                value = data_string[len("value_hex:"):]
+                case_cfg[key] = int(value, 16)
+            elif data_string.startswith("list_int:"):
+                value = data_string[len("list_int:"):]
+                datas = value.split(',')
+                int_list = map(lambda x: int(x), datas)
+                case_cfg[key] = int_list
+            elif data_string.startswith("list_str:"):
+                value = data_string[len("list_str:"):]
+                str_list = value.split(',')
+                case_cfg[key] = str_list
+            else:
+                case_cfg[key] = data_string
+
+        return case_cfg
+
+
 class VirtConf(UserConf):
 
     def __init__(self, virt_conf=VIRTCONF):
@@ -344,3 +394,8 @@ if __name__ == '__main__':
     # example for ixia configuration file
     ixiaconf = IxiaConf(IXIACONF)
     print ixiaconf.load_ixia_config()
+
+    # example for suite configure file
+    suiteconf = SuiteConf(SUITECONF_SAMPLE)
+    print suiteconf.load_case_config("case1")
+    print suiteconf.load_case_config("case2")
-- 
1.9.3

  parent reply	other threads:[~2017-07-27  1:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26  8:16 [dts] [PATCH v1 0/4] support suite and case " Marvin Liu
2017-07-26  8:16 ` [dts] [PATCH v1 1/4] framework setting: support configuration file folder change Marvin Liu
2017-07-26  8:16 ` [dts] [PATCH v1 2/4] framework config: support suite&case level configuration Marvin Liu
2017-07-26  8:16 ` [dts] [PATCH v1 3/4] framework: enhance test case execution process Marvin Liu
2017-07-26  8:16 ` [dts] [PATCH v1 4/4] conf: add suite and case level configuration sample Marvin Liu
2017-07-26  9:20 ` [dts] [PATCH v2 0/4] support suite and case level configuration Marvin Liu
2017-07-26  9:20   ` [dts] [PATCH v2 1/4] framework setting: support configuration file folder change Marvin Liu
2017-07-26  9:20   ` [dts] [PATCH v2 2/4] framework config: support suite&case level configuration Marvin Liu
2017-07-26  9:20   ` [dts] [PATCH v2 3/4] framework: enhance test case execution process Marvin Liu
2017-07-26  9:21   ` [dts] [PATCH v2 4/4] conf: add suite and case level configuration sample Marvin Liu
2017-07-27  1:07   ` [dts] [PATCH v3 0/4] support suite and case level configuration Marvin Liu
2017-07-27  1:07     ` [dts] [PATCH v3 1/4] framework setting: support change configuration file folder Marvin Liu
2017-07-27  1:07     ` Marvin Liu [this message]
2017-07-27  1:07     ` [dts] [PATCH v3 3/4] framework: enhance test case execution process Marvin Liu
2017-07-27  1:07     ` [dts] [PATCH v3 4/4] conf: add suite and case level configuration sample Marvin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1501117673-47762-3-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).