test suite reviews and discussions
 help / color / mirror / Atom feed
From: "Jiajia, Sun" <sunx.jiajia@intel.com>
To: dts@dpdk.org
Subject: [dts] [PATCH v2 09/19] Change and add some functions to support virtual test
Date: Fri, 22 May 2015 17:04:02 +0800	[thread overview]
Message-ID: <1432285452-14286-10-git-send-email-sunx.jiajia@intel.com> (raw)
In-Reply-To: <1432285452-14286-1-git-send-email-sunx.jiajia@intel.com>

From: sjiajiax <sunx.jiajia@intel.com>

Signed-off-by: sjiajiax <sunx.jiajia@intel.com>
---
 framework/config.py | 170 +++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 135 insertions(+), 35 deletions(-)
 mode change 100755 => 100644 framework/config.py

diff --git a/framework/config.py b/framework/config.py
old mode 100755
new mode 100644
index d2548e8..7e2436a
--- a/framework/config.py
+++ b/framework/config.py
@@ -37,45 +37,133 @@ import re
 import ConfigParser  # config parse module
 import argparse      # prase arguments module
 
-portconf = "conf/ports.cfg"
-crbconf = "conf/crbs.cfg"
+PORTCONF = "conf/ports.cfg"
+CRBCONF = "conf/crbs.cfg"
+VIRTCONF = "conf/virt_global.cfg"
 
 
 class UserConf():
 
-    def __init__(self, port_conf=portconf, crb_conf=crbconf):
-        self.port_config = port_conf
-        self.crb_config = crb_conf
+    def __init__(self, config):
+        self.conf = ConfigParser.SafeConfigParser()
+        load_files = self.conf.read(config)
+        if load_files == []:
+            print "FAILED LOADING %s!!!" % config
+            self.conf = None
+            raise
+
+    def get_sections(self):
+        if self.conf is None:
+            return None
+
+        return self.conf.sections()
+
+    def load_section(self, section):
+        if self.conf is None:
+            return None
+
+        items = None
+        for conf_sect in self.conf.sections():
+            if conf_sect == section:
+                items = self.conf.items(section)
+
+        return items
+
+    def load_config(self, item):
+        confs = [conf.strip() for conf in item.split(';')]
+        if '' in confs:
+            confs.remove('')
+        return confs
+
+    def load_param(self, conf):
+        paramDict = dict()
+
+        for param in conf.split(','):
+            (key, _, value) = param.partition('=')
+            paramDict[key] = value
+        return paramDict
+
+
+class VirtConf(UserConf):
+
+    def __init__(self, virt_conf=VIRTCONF):
+        self.config_file = virt_conf
+        self.virt_cfg = {}
+        try:
+            self.virt_conf = UserConf(self.config_file)
+        except Exception as e:
+            print "FAILED LOADING VIRT CONFIG!!!"
+            self.virt_conf = None
+
+    def load_virt_config(self, name):
+        self.virt_cfgs = []
+
+        try:
+            virt_confs = self.virt_conf.load_section(name)
+        except:
+            print "FAILED FIND SECTION %s!!!" % name
+            return
+
+        for virt_conf in virt_confs:
+            virt_cfg = {}
+            virt_params = []
+            key, config = virt_conf
+            confs = self.virt_conf.load_config(config)
+            for config in confs:
+                virt_params.append(self.load_virt_param(config))
+            virt_cfg[key] = virt_params
+            self.virt_cfgs.append(virt_cfg)
+
+    def get_virt_config(self):
+        return self.virt_cfgs
+
+    def load_virt_param(self, config):
+        cfg_params = self.virt_conf.load_param(config)
+        return cfg_params
+
+
+class PortConf(UserConf):
+
+    def __init__(self, port_conf=PORTCONF):
+        self.config_file = port_conf
         self.ports_cfg = {}
         self.pci_regex = "([\da-f]{2}:[\da-f]{2}.\d{1})$"
         try:
-            self.port_conf = ConfigParser.SafeConfigParser()
-            self.port_conf.read(self.port_config)
+            self.port_conf = UserConf(self.config_file)
         except Exception as e:
             print "FAILED LOADING PORT CONFIG!!!"
+            self.port_conf = None
 
     def load_ports_config(self, crbIP):
-        ports = []
-        for crb in self.port_conf.sections():
-            if crb != crbIP:
-                continue
-            ports = [port.strip()
-                     for port in self.port_conf.get(crb, 'ports').split(';')]
+        self.ports_cfg = {}
+        if self.port_conf is None:
+            return
+
+        ports = self.port_conf.load_section(crbIP)
+        if ports is None:
+            return
+        key, config = ports[0]
+        confs = self.port_conf.load_config(config)
+
+        for config in confs:
+            port_param = self.port_conf.load_param(config)
 
-        for port in ports:
-            port_cfg = self.__parse_port_param(port)
             # check pci BDF validity
-            if 'pci' not in port_cfg:
+            if 'pci' not in port_param:
                 print "NOT FOUND CONFIG FOR NO PCI ADDRESS!!!"
                 continue
-            m = re.match(self.pci_regex, port_cfg['pci'])
+            m = re.match(self.pci_regex, port_param['pci'])
             if m is None:
                 print "INVALID CONFIG FOR NO PCI ADDRESS!!!"
                 continue
 
-            keys = port_cfg.keys()
+            keys = port_param.keys()
             keys.remove('pci')
-            self.ports_cfg[port_cfg['pci']] = {key: port_cfg[key] for key in keys}
+            self.ports_cfg[port_param['pci']] = {
+                key: port_param[key] for key in keys}
+            if 'numa' in self.ports_cfg[port_param['pci']]:
+                numa_str = self.ports_cfg[port_param['pci']]['numa']
+                self.ports_cfg[port_param['pci']]['numa'] = int(numa_str)
 
     def get_ports_config(self):
         return self.ports_cfg
@@ -86,23 +174,35 @@ class UserConf():
         else:
             return False
 
-    def __parse_port_param(self, port):
-        portDict = dict()
-
-        for param in port.split(','):
-            (key, _, value) = param.partition('=')
-            if key == 'numa':
-                portDict[key] = int(value)
-            else:
-                portDict[key] = value
-        return portDict
 
 
 if __name__ == '__main__':
-    parser = argparse.ArgumentParser(description="Load DTS configuration files")
-    parser.add_argument("-p", "--portconf", default=portconf)
-    parser.add_argument("-c", "--crbconf", default=crbconf)
+    parser = argparse.ArgumentParser(
+        description="Load DTS configuration files")
+    parser.add_argument("-p", "--portconf", default=PORTCONF)
+    parser.add_argument("-c", "--crbconf", default=CRBCONF)
+    parser.add_argument("-v", "--virtconf", default=VIRTCONF)
     args = parser.parse_args()
-    conf = UserConf()
-    conf.load_ports_config('192.168.1.1')
-    conf.check_port_available('0000:86:00.0')
+
+    # not existed configuration file
+    VirtConf('/tmp/not-existed.cfg')
+
+    # example for basic use configuration file
+    conf = UserConf(PORTCONF)
+    for section in conf.get_sections():
+        items = conf.load_section(section)
+        key, value = items[0]
+        confs = conf.load_config(value)
+        for config in confs:
+            conf.load_param(config)
+
+    # example for port configuration file
+    portconf = PortConf(PORTCONF)
+    portconf.load_ports_config('DUT IP')
+    print portconf.get_ports_config()
+    portconf.check_port_available('86:00.0')
+
+    # example for global virtualization configuration file
+    virtconf = VirtConf(VIRTCONF)
+    virtconf.load_virt_config('LIBVIRT')
+    print virtconf.get_virt_config()
-- 
1.9.3

  parent reply	other threads:[~2015-05-22  9:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22  9:03 [dts] [PATCH v2 00/19] *** Enable virtualization test for dts framework *** Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 01/19] Abstract the NIC device as the single class NetDevice Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 02/19] Add a base module for virtual test Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 03/19] Add QEMU KVM module based on virt_base module for KVM test cases Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 04/19] Add a module to manage the host resource Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 05/19] Add a module to instantiate the VM Jiajia, Sun
2015-05-25  6:10   ` Qiu, Michael
2015-05-25  9:14     ` Jiajia, SunX
2015-05-26  9:07       ` Qiu, Michael
2015-05-27  1:36         ` Jiajia, SunX
2015-05-22  9:03 ` [dts] [PATCH v2 06/19] Add a third-party module of qemu-guest-agent to manage VM Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 07/19] Move some general functions from dts.py to utils.py and settings.py Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 08/19] Add and move some functions because of the virtual tests and network device instantiation Jiajia, Sun
2015-05-22  9:04 ` Jiajia, Sun [this message]
2015-05-22  9:04 ` [dts] [PATCH v2 10/19] add some exceptions to support framwork to handle virtual test exceptions Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 11/19] Add some codes to support virtual test log Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 12/19] Add some codes to make session to support virtual test Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 13/19] Add some base functions to get the device info in the testpmd Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 14/19] Change some codes to support network device instantiation and virtualization test Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 15/19] Add some codes to support network instantiation in the tester module Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 16/19] Make test_case know its suite name Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 17/19] Add a global virtualization config and a config related to SRIOV KVM suite Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 18/19] Add a test plan of how to test SRIOV on the KVM ENV Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 19/19] Add a test suite to verify the SRIOV feature " Jiajia, Sun

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=1432285452-14286-10-git-send-email-sunx.jiajia@intel.com \
    --to=sunx.jiajia@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).