From: Ondrej Lichtner olichtne@redhat.com
The Config class now accepts an argument which specifies which configuration scheme should be used. Currently I added a scheme 'controller', which was used until now as the configuration for the controller, and 'slave' which will be used by the slave. The details of the slave scheme will be added later.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- Common/Config.py | 35 ++++++++++++++++++++++++++++++++--- nettestctl.py | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/Common/Config.py b/Common/Config.py index 297ebea..5376f35 100644 --- a/Common/Config.py +++ b/Common/Config.py @@ -23,10 +23,22 @@ class ConfigError(Exception):
class Config(): options = None + _scheme = None
- def __init__(self): + def __init__(self, scheme): self.options = dict()
+ self._scheme = scheme + if self._scheme == "controller": + self.init_controller() + elif self._scheme == "slave": + self.init_slave() + else: + msg = "Unknow scheme: '%s', can't set up configuration"\ + % self._scheme + raise ConfigError(msg) + + def init_controller(self): self.options['log'] = dict() self.options['log']['path'] = os.path.join( os.path.dirname(sys.argv[0]), './Logs') @@ -37,6 +49,9 @@ class Config(): self.options['environment']['rpcport'] = DefaultRPCPort self.options['environment']['pool_dirs'] = []
+ def init_slave(self): + pass + def get_config(self): return self.options
@@ -61,15 +76,29 @@ class Config(): parser.read(abs_path)
sections = parser._sections + + if self._scheme == "controller": + self.sectionsCntl(sections, abs_path) + elif self._scheme == "slave": + self.sectionsSlave(sections, abs_path) + else: + msg = "Unknow scheme: '%s', can't parse sections." \ + % self._scheme + raise ConfigError(msg) + + def sectionsCntl(self, sections, path): for section in sections: if section == "log": - self.sectionLogs(sections[section], abs_path) + self.sectionLogs(sections[section], path) elif section == "environment": - self.sectionEnvironment(sections[section], abs_path) + self.sectionEnvironment(sections[section], path) else: msg = "Unknown section: %s" % section raise ConfigError(msg)
+ def sectionsSlave(self, sections, path): + pass + def sectionLogs(self, config, cfg_path): section = self.options['log']
diff --git a/nettestctl.py b/nettestctl.py index d4178f4..6da53f2 100755 --- a/nettestctl.py +++ b/nettestctl.py @@ -99,7 +99,7 @@ def main(): usage() sys.exit()
- config = Config() + config = Config("controller") config.load_config('~/.lnst/lnst.conf')
debug = 0
From: Ondrej Lichtner olichtne@redhat.com
This patch changes the hierarchy by which we load configuration files to the following:
1. We check for the existence of a configuration file located in the same directory as the launched binary. This is for cases when the application is launched from the git version. This configuration file MUST NOT exist otherwise. This configuration file has the HIGHEST priority and if it exists other configuration files will not be loaded. This is to ensure that we can run the git version and have the packaged version installed at the same time without unnecessary conflicts.
2. We load the configuration file in /etc/ this should be the system-wide configuration. We need this file mostly because of the slave application which will be running as a daemon in the future. For convention purposes and to not confuse the users this file will exist even on the controller machines. This file should be heavily documented and explain the available options.
3. On the controller we load the configuration file located in the ~/.lnst directory. This can't be done on the slave machines as the slave application will be running as a daemon and it would make sense to put its configuration into the home directory of any user.
This patch also changes the names of the configuration files to: lnst-ctl.conf lnst-slave.conf to distinguish the different schemes used in these files.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- nettestctl.py | 8 +++++++- nettestslave.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/nettestctl.py b/nettestctl.py index 6da53f2..e97733c 100755 --- a/nettestctl.py +++ b/nettestctl.py @@ -100,7 +100,13 @@ def main(): sys.exit()
config = Config("controller") - config.load_config('~/.lnst/lnst.conf') + dirname = os.path.dirname(sys.argv[0]) + gitcfg = os.path.join(dirname, "lnst-ctl.conf") + if os.path.isfile(gitcfg): + config.load_config(gitcfg) + else: + config.load_config('/etc/lnst-ctl.conf') + config.load_config('~/.lnst/lnst-ctl.conf')
debug = 0 recipe_path = None diff --git a/nettestslave.py b/nettestslave.py index 29528ff..c9cb0c9 100755 --- a/nettestslave.py +++ b/nettestslave.py @@ -13,10 +13,12 @@ jpirko@redhat.com (Jiri Pirko)
import getopt import sys +import os import logging from NetTest.NetTestSlave import NetTestSlave from Common.Daemon import Daemon from Common.Logs import Logs +from Common.Config import Config
def usage(): """ @@ -46,6 +48,14 @@ def main(): usage() sys.exit()
+ config = Config("slave") + dirname = os.path.dirname(sys.argv[0]) + gitcfg = os.path.join(dirname, "lnst-slave.conf") + if os.path.isfile(gitcfg): + config.load_config(gitcfg) + else: + config.load_config('/etc/lnst-slave.conf') + debug = False daemon = False pidfile = "nettestslave.pid"
From: Ondrej Lichtner olichtne@redhat.com
This commit renames the lnst.conf.example file to lnst-ctl.conf also the file lnst-slave.conf has been added.
In the git tree these files will contain the default configuration values. They will also be used for configuration in case you are using the git version of the scripts.
The lnst-slave.conf is empty, options and values will be added later.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst-ctl.conf | 6 ++++++ lnst.conf.example | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 lnst-ctl.conf create mode 100644 lnst-slave.conf delete mode 100644 lnst.conf.example
diff --git a/lnst-ctl.conf b/lnst-ctl.conf new file mode 100644 index 0000000..422804c --- /dev/null +++ b/lnst-ctl.conf @@ -0,0 +1,6 @@ +[environment] +mac_pool_range = 52:54:01:00:00:01 52:54:01:FF:FF:FF +rpcport = 9999 +machine_pool_dirs = +[log] +path = ./ diff --git a/lnst-slave.conf b/lnst-slave.conf new file mode 100644 index 0000000..e69de29 diff --git a/lnst.conf.example b/lnst.conf.example deleted file mode 100644 index 422804c..0000000 --- a/lnst.conf.example +++ /dev/null @@ -1,6 +0,0 @@ -[environment] -mac_pool_range = 52:54:01:00:00:01 52:54:01:FF:FF:FF -rpcport = 9999 -machine_pool_dirs = -[log] -path = ./
From: Ondrej Lichtner olichtne@redhat.com
This patch adds 2 new options: 'test_module_dirs' which specifies a list of dirs where to look for Test*.py files 'test_tool_dirs' which specifies a list of dirs where to look for test_tool packages to be used by slaves
We agreed to use += for some options that work with lists. After this patch, options that specify a list of values can be used with both '=' and '+='.
To specify a new list replacing the list loaded from previous configuration files use '=', e.g. 'machine_pool_dirs = ~/.lnst/pool1/ ~/.lnst/pool2/'
To append to the values loaded from previous configuration files use '+=', e.g. 'machine_pool_dirs += ~/.lnst/pool/'
This patch also updates the lnst-ctl.conf file to the current format. The default values for the new options will be added later.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- Common/Config.py | 28 ++++++++++++++++++++++------ lnst-ctl.conf | 4 +++- 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/Common/Config.py b/Common/Config.py index 5376f35..889ac4e 100644 --- a/Common/Config.py +++ b/Common/Config.py @@ -48,6 +48,8 @@ class Config(): ['52:54:01:00:00:01', '52:54:01:FF:FF:FF'] self.options['environment']['rpcport'] = DefaultRPCPort self.options['environment']['pool_dirs'] = [] + self.options['environment']['tool_dirs'] = [] + self.options['environment']['module_dirs'] = []
def init_slave(self): pass @@ -120,7 +122,22 @@ class Config(): elif option == 'rpcport': section['rpcport'] = self.optionPort(config[option]) elif option == 'machine_pool_dirs': - section['pool_dirs'] = self.optionPoolDirs(config[option], + section['pool_dirs'] = self.optionDirList(config[option], + cfg_path) + elif re.match(r'^machine_pool_dirs\s++$', option): + section['pool_dirs'] += self.optionDirList(config[option], + cfg_path) + elif option == 'test_module_dirs': + section['module_dirs'] = self.optionDirList(config[option], + cfg_path) + elif re.match(r'^test_module_dirs\s++$', option): + section['module_dirs'] += self.optionDirList(config[option], + cfg_path) + elif option == 'test_tool_dirs': + section['tool_dirs'] = self.optionDirList(config[option], + cfg_path) + elif re.match(r'^test_tool_dirs\s++$', option): + section['tool_dirs'] += self.optionDirList(config[option], cfg_path) else: msg = "Unknown option: %s in section environment" % option @@ -154,17 +171,16 @@ class Config(): raise ConfigError(msg) return vals
- def optionPoolDirs(self, option, cfg_path): - env = self.get_section('environment') + def optionDirList(self, option, cfg_path): paths = re.split(r'(?<!\)\s', option)
- pool_dirs = env['pool_dirs'] + dirs = [] for path in paths: if path == '': continue exp_path = os.path.expanduser(path) abs_path = os.path.join(os.path.dirname(cfg_path), exp_path) norm_path = os.path.normpath(abs_path) - pool_dirs.append(norm_path) + dirs.append(norm_path)
- return pool_dirs + return dirs diff --git a/lnst-ctl.conf b/lnst-ctl.conf index 422804c..79451b3 100644 --- a/lnst-ctl.conf +++ b/lnst-ctl.conf @@ -2,5 +2,7 @@ mac_pool_range = 52:54:01:00:00:01 52:54:01:FF:FF:FF rpcport = 9999 machine_pool_dirs = +test_tool_dirs = +test_module_dirs = [log] -path = ./ +path = ./Logs
lnst-developers@lists.fedorahosted.org