From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4FDDCA04FD; Wed, 22 Jun 2022 14:15:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5ED3542B70; Wed, 22 Jun 2022 14:15:03 +0200 (CEST) Received: from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20]) by mails.dpdk.org (Postfix) with ESMTP id B46C942824 for ; Wed, 22 Jun 2022 14:14:59 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lb.pantheon.sk (Postfix) with ESMTP id DEB563146C; Wed, 22 Jun 2022 14:14:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at siecit.sk Received: from lb.pantheon.sk ([127.0.0.1]) by localhost (lb.pantheon.sk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xoLynyyGKIld; Wed, 22 Jun 2022 14:14:57 +0200 (CEST) Received: from entguard.lab.pantheon.local (unknown [46.229.239.141]) by lb.pantheon.sk (Postfix) with ESMTP id 575363146F; Wed, 22 Jun 2022 14:14:52 +0200 (CEST) From: =?UTF-8?q?Juraj=20Linke=C5=A1?= To: thomas@monjalon.net, david.marchand@redhat.com, jerinjacobk@gmail.com, ronan.randles@intel.com, Honnappa.Nagarahalli@arm.com, ohilyard@iol.unh.edu, lijuan.tu@intel.com Cc: dev@dpdk.org, =?UTF-8?q?Juraj=20Linke=C5=A1?= Subject: [PATCH v1 6/8] dts: add config parser module Date: Wed, 22 Jun 2022 12:14:46 +0000 Message-Id: <20220622121448.3304251-7-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220622121448.3304251-1-juraj.linkes@pantheon.tech> References: <20220622121448.3304251-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The module uses Python's configparser module, which supports an ini-like format with sections. The configuration is split into two parts, one defining the parameters of the test run and the other defining the topology to be used. Signed-off-by: Juraj Linkeš --- dts/conf/topology.cfg | 9 +++++ dts/execution.cfg | 2 + dts/framework/config.py | 81 ++++++++++++++++++++++++++++++++++++++ dts/framework/exception.py | 13 ++++++ dts/framework/settings.py | 34 ++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 dts/conf/topology.cfg create mode 100644 dts/execution.cfg create mode 100644 dts/framework/config.py diff --git a/dts/conf/topology.cfg b/dts/conf/topology.cfg new file mode 100644 index 0000000000..f5406cc6b9 --- /dev/null +++ b/dts/conf/topology.cfg @@ -0,0 +1,9 @@ +#Topology Configuration +#[SUT IP] +# sut_ip: SUT ip address +# sut_user: SUT username +# sut_passwd: SUT password +[SUT IP1] +sut_ip=xxx.xxx.xxx.xxx +sut_user=root +sut_passwd= diff --git a/dts/execution.cfg b/dts/execution.cfg new file mode 100644 index 0000000000..ef671aa394 --- /dev/null +++ b/dts/execution.cfg @@ -0,0 +1,2 @@ +[Execution1] +sut= diff --git a/dts/framework/config.py b/dts/framework/config.py new file mode 100644 index 0000000000..765132a2a0 --- /dev/null +++ b/dts/framework/config.py @@ -0,0 +1,81 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2010-2021 Intel Corporation +# + +""" +Generic port and topology nodes configuration file load function +""" +import configparser # config parse module + +from .exception import ConfigParseException +from .settings import CONFIG_ROOT_PATH + +TOPOCONF = "%s/topology.cfg" % CONFIG_ROOT_PATH + + +class UserConf: + def __init__(self, config): + self.conf = configparser.SafeConfigParser() + load_files = self.conf.read(config) + if load_files == []: + self.conf = None + raise ConfigParseException(config) + + def get_sections(self): + if self.conf is None: + return [] + + 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 + + +class TopologyConf(UserConf): + TOPO_DEFAULTS = { + "IP": "", + "user": "", + "pass": "", + } + + def __init__(self, topo_conf=TOPOCONF): + self.config_file = topo_conf + self.nodes = [] + try: + self.topo_conf = UserConf(self.config_file) + except ConfigParseException: + self.topo_conf = None + raise ConfigParseException + + def load_topo_config(self): + sections = self.topo_conf.get_sections() + if not sections: + return self.nodes + + for node_name in sections: + node = self.TOPO_DEFAULTS.copy() + node["section"] = node_name + node_conf = self.topo_conf.load_section(node_name) + if not node_conf: + continue + + # convert file configuration to dts node configuration + for key, value in node_conf: + if key == "sut_ip": + node["IP"] = value + elif key == "sut_user": + node["user"] = value + elif key == "sut_passwd": + node["pass"] = value + + self.nodes.append(node) + return self.nodes + diff --git a/dts/framework/exception.py b/dts/framework/exception.py index a109dd1fb8..a094fcce78 100644 --- a/dts/framework/exception.py +++ b/dts/framework/exception.py @@ -46,3 +46,16 @@ def __init__(self, host): def __str__(self): return "SSH session with %s has been dead" % self.host + + +class ConfigParseException(Exception): + + """ + Configuration file parse failure exception. + """ + + def __init__(self, conf_file): + self.config = conf_file + + def __str__(self): + return "Failed to parse config file [%s]" % (self.config) diff --git a/dts/framework/settings.py b/dts/framework/settings.py index d62083969e..c033a77fec 100644 --- a/dts/framework/settings.py +++ b/dts/framework/settings.py @@ -2,7 +2,41 @@ # Copyright(c) 2010-2021 Intel Corporation # +import os +import re + """ Default session timeout. """ TIMEOUT = 15 + +""" +DTS global environment variables +""" +DTS_ENV_PAT = r"DTS_*" +DTS_CFG_FOLDER = "DTS_CFG_FOLDER" + + +def load_global_setting(key): + """ + Load DTS global setting + """ + if re.match(DTS_ENV_PAT, key): + env_key = key + else: + env_key = "DTS_" + key + + if env_key in list(os.environ.keys()): + return os.environ[env_key] + else: + return "" + + +""" +The root path of framework configs. +""" +dts_cfg_folder = load_global_setting(DTS_CFG_FOLDER) +if dts_cfg_folder != "": + CONFIG_ROOT_PATH = dts_cfg_folder +else: + CONFIG_ROOT_PATH = "./conf" -- 2.20.1