From: "Liu, Yong" <yong.liu@intel.com>
To: "Qiu, Michael" <michael.qiu@intel.com>, "dts@dpdk.org" <dts@dpdk.org>
Subject: Re: [dts] [PATCH 1/4] framework: add new module for load port configuration file
Date: Wed, 4 Feb 2015 04:51:36 +0000 [thread overview]
Message-ID: <86228AFD5BCD8E4EBFD2B90117B5E81E10D6A416@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <533710CFB86FA344BFBF2D6802E60286CD42E1@SHSMSX101.ccr.corp.intel.com>
These codes were just sample code for config module and their purpose is just to show how to use this module.
> -----Original Message-----
> From: Qiu, Michael
> Sent: Wednesday, February 04, 2015 11:26 AM
> To: Liu, Yong; dts@dpdk.org
> Subject: Re: [dts] [PATCH 1/4] framework: add new module for load port
> configuration file
>
> On 1/23/2015 4:27 PM, Marvin Liu wrote:
> > From: Yong Liu <yong.liu@intel.com>
> >
> > Config module will load port configuration and parse port parameter.
> > Port configuration will be used in the process of setting up DUT.
> > User can assign port mac, numa or tester peer pci address of DUT port.
> >
> > Signed-off-by: Marvinliu <yong.liu@intel.com>
> > ---
> > conf/ports.cfg | 4 +++
> > framework/config.py | 93
> +++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 97 insertions(+)
> > create mode 100644 conf/ports.cfg
> > create mode 100755 framework/config.py
> >
> > diff --git a/conf/ports.cfg b/conf/ports.cfg
> > new file mode 100644
> > index 0000000..85c1998
> > --- /dev/null
> > +++ b/conf/ports.cfg
> > @@ -0,0 +1,4 @@
> > +[10.239.128.117]
> > +ports=
> > + pci=86:00.0,intf=p4p1;
> > + pci=86:00.1,mac=90:e2:ba:39:b7:69,peer=05:00.1,numa=0
> > diff --git a/framework/config.py b/framework/config.py
> > new file mode 100755
> > index 0000000..140c84b
> > --- /dev/null
> > +++ b/framework/config.py
> > @@ -0,0 +1,93 @@
> > +# BSD LICENSE
> > +#
> > +# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> > +# All rights reserved.
> > +#
> > +# Redistribution and use in source and binary forms, with or without
> > +# modification, are permitted provided that the following conditions
> > +# are met:
> > +#
> > +# * Redistributions of source code must retain the above copyright
> > +# notice, this list of conditions and the following disclaimer.
> > +# * Redistributions in binary form must reproduce the above copyright
> > +# notice, this list of conditions and the following disclaimer in
> > +# the documentation and/or other materials provided with the
> > +# distribution.
> > +# * Neither the name of Intel Corporation nor the names of its
> > +# contributors may be used to endorse or promote products derived
> > +# from this software without specific prior written permission.
> > +#
> > +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> > +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> > +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> > +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> > +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> > +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> > +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> > +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> > +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> > +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> > +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> > +
> > +"""
> > +Generic port and crbs configuration file load function
> > +"""
> > +
> > +import ConfigParser # config parse module
> > +import argparse # prase arguments module
> > +
> > +portconf = "../conf/ports.cfg"
> > +crbconf = "../conf/crbs.cfg"
> > +
> > +
> > +class UserConf():
> > +
> > + def __init__(self, port_conf=portconf, crb_conf=crbconf):
> > + self.port_config = port_conf
> > + self.crb_config = crb_conf
> > + self.ports_cfg = {}
> > + try:
> > + self.port_conf = ConfigParser.SafeConfigParser()
> > + self.port_conf.read(self.port_config)
> > + except Exception as e:
> > + print "FAILED LOADING PORT CONFIG!!!"
> > +
> > + 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(';')]
> > +
> > + for port in ports:
> > + port_cfg = self.parse_port_param(port)
> > + if 'pci' not in port_cfg:
> > + print "INVALID CONFIG FOR NO PCI ADDRESS!!!"
>
> Would you think this port is valid for this error?
>
> > + keys = port_cfg.keys()
> > + keys.remove('pci')
> > + self.ports_cfg[port_cfg['pci']] = {key: port_cfg[key] for
> key in keys}
> > +
> > + def check_port_available(self, pci_addr):
> > + if pci_addr in self.ports_cfg.keys():
> > + return True
> > + else:
> > + return False
> > +
> > + def parse_port_param(self, port):
> > + portDict = dict()
> > +
> > + for param in port.split(','):
> > + (key, _, value) = param.partition('=')
> > + 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)
> > + args = parser.parse_args()
> > + conf = UserConf()
> > + conf.load_ports_config('10.239.128.120')
> > + conf.check_port_available('0000:86:00.0')
>
> Why here show ip and PCI address?
>
> All those could inside cfg file, and parse it here, cfg file can be user
> defined, but the script should not be changed for different config.
>
> Thanks,
> Michael
next prev parent reply other threads:[~2015-02-04 4:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-23 8:26 [dts] [PATCH 0/4] Support additional " Marvin Liu
2015-01-23 8:26 ` [dts] [PATCH 1/4] framework: add new module for load " Marvin Liu
2015-02-04 3:26 ` Qiu, Michael
2015-02-04 4:51 ` Liu, Yong [this message]
2015-01-23 8:26 ` [dts] [PATCH 2/4] framework: execuction file support port config nic_type Marvin Liu
2015-02-04 3:57 ` Qiu, Michael
2015-01-23 8:26 ` [dts] [PATCH 3/4] framework: reorganize DUT and Tester port initialize sequence Marvin Liu
2015-02-04 3:56 ` Qiu, Michael
2015-02-04 5:24 ` Liu, Yong
2015-01-23 8:26 ` [dts] [PATCH 4/4] suites: remove nic type check from testsuites Marvin Liu
2015-02-04 3:57 ` Qiu, Michael
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=86228AFD5BCD8E4EBFD2B90117B5E81E10D6A416@SHSMSX103.ccr.corp.intel.com \
--to=yong.liu@intel.com \
--cc=dts@dpdk.org \
--cc=michael.qiu@intel.com \
/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).