This will be used in list_pools action for accessing dictionary with available pools.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Controller/SlavePool.py | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py index e825998..02715ed 100644 --- a/lnst/Controller/SlavePool.py +++ b/lnst/Controller/SlavePool.py @@ -57,6 +57,9 @@ class SlavePool: self._mapper.set_pools(self._pools) logging.info("Finished loading pools.")
+ def get_pools(self): + return self._pools + def add_dir(self, pool_name, dir_path): logging.info("Processing pool '%s', directory '%s'" % (pool_name, dir_path))
This patch extends warning message printed when pool directory does not contain any machines. Now it contains name of the pool and path to the directory.
This will be used in list_pools implementation, where without this info the message would not make sense as user wouldn't know which pool is empty.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Controller/SlavePool.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py index 02715ed..638d6d7 100644 --- a/lnst/Controller/SlavePool.py +++ b/lnst/Controller/SlavePool.py @@ -72,7 +72,9 @@ class SlavePool: pool[m_id] = m
if len(pool) == 0: - logging.warn("No machines found in this pool") + logging.warn("No machines found in pool '%s', directory '%s'" % + (pool_name, + dir_path))
max_len = 0 for m_id in pool.keys():
This patch adds method for unsetting Formatter from display_handler in LoggingCtl.
It will be used in list_pools implementation where formatted logging output is not desirable.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Common/Logs.py | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/lnst/Common/Logs.py b/lnst/Common/Logs.py index 80bedf3..59a9a7f 100644 --- a/lnst/Common/Logs.py +++ b/lnst/Common/Logs.py @@ -138,6 +138,9 @@ class LoggingCtl: logger.setLevel(logging.NOTSET) logger.addHandler(self.display_handler)
+ def unset_formatter(self): + self.display_handler.setFormatter(None) + def set_recipe(self, recipe_path, clean=True, expand=""): recipe_name = os.path.splitext(os.path.split(recipe_path)[1])[0] if expand != "":
This patch adds new action called list_pools. It has two modes of execution, non-verbose and verbose. Non verbose, executed just with "lnst-ctl list_pools" command, prints out pool names and their paths in pool_name=/path/to/pool format.
For verbose mode, option -v or --verbose must be entered. It prints pool names and their paths and in addition, it lists through all slave machine config files in pool directories and prints their contents in more human readable format.
Pools are acquired from all the configs lnst-ctl would use in normal run.
list_pools action can be combined with --pools argument in both verbose and nonverbose mode so you can filter the output as you wish.
list_pools action replaces --dump-pools option
changes in v6: * mentioned that list_pools action replaces --dump-pools option * used SlavePool object with new get method for getting pools instead of calling private methods * reorganized patchset so adding get_pools is first * added spaces before and after + sign * renamed network to label to be constistent with XMLs * when directory is empty, print more info to user * unset formatter when using list_pools action and set debug level to INFO so it shows warning messages, unformatted
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst-ctl | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-)
diff --git a/lnst-ctl b/lnst-ctl index f3c2eb2..a9979b4 100755 --- a/lnst-ctl +++ b/lnst-ctl @@ -24,6 +24,7 @@ from lnst.Common.Utils import mkdir_p from lnst.Controller.NetTestController import NetTestController, NetTestError from lnst.Controller.NetTestController import NoMatchError from lnst.Controller.NetTestResultSerializer import NetTestResultSerializer +from lnst.Controller.SlavePool import SlavePool from lnst.Controller.XmlProcessing import XmlProcessingError
RETVAL_PASS = 0 @@ -35,7 +36,8 @@ def usage(retval=0): """ print "Usage: %s [OPTIONS...] ACTION [RECIPES...]" % sys.argv[0] print "" - print "ACTION = [ run | config_only | deconfigure | match_setup ]" + print "ACTION = [ run | config_only | deconfigure | match_setup | " \ + "list_pools]" print "" print "OPTIONS" print " -A, --override-alias name=value define top-level alias that " \ @@ -47,6 +49,8 @@ def usage(retval=0): "configuration files on stdout and exits" print " --dump-pools dumps the available machine " \ "pools and exits" + print " -v, --verbose verbose version of list_pools " \ + "command" print " -h, --help print this message" print " -m, --no-colours disable coloured terminal output" print " -o, --disable-pool-checks don't check the availability of " \ @@ -67,6 +71,52 @@ def usage(retval=0): print " -x, --result=FILE file to write xml_result" sys.exit(retval)
+def list_pools(restrict_pools, verbose): + conf_pools = lnst_config.get_pools() + pools = {} + if len(restrict_pools) > 0: + for pool_name in restrict_pools: + if pool_name in conf_pools: + pools[pool_name] = conf_pools[pool_name] + elif len(restrict_pools) == 1 and os.path.isdir(pool_name): + pools = {"cmd_line_pool": pool_name} + else: + raise NetTestError("Pool %s does not exist!" % pool_name) + else: + pools = conf_pools + + sp = SlavePool(pools, pool_checks=False) + + out = "" + # iterate over all pools + sp_pools = sp.get_pools() + for pool_name, pool_content in sp_pools.iteritems(): + out += "Pool: %s (%s)\n" % (pool_name, pools[pool_name]) + # verbose output + if verbose: + # iterate over all slave machine cfgs + for filename, pool in pool_content.iteritems(): + # print in human-readable format + out += 3*" " + filename + ".xml\n" + out += 5*" " + "params:\n" + for key in pool['params']: + out += 7*" " + key + " : " + pool['params'][key] + "\n" + if pool['interfaces']: + out += 5*" " + "interfaces:\n" + for key in sorted(pool['interfaces']): + out += 7*" " + "id : " + key + "\tlabel : " +\ + pool['interfaces'][key]['network'] + "\n" + for param in pool['interfaces'][key]['params']: + out += 9*" " + param + " : " +\ + pool['interfaces'][key]['params'][param] + "\n" + out += "\n" + # print wihout newlines on the end of string + if verbose: + print out[:-2] + else: + print out[:-1] + + def store_alias(alias_def, aliases_dict): try: name, value = alias_def.split("=") @@ -190,7 +240,7 @@ def main(): try: opts, args = getopt.getopt( sys.argv[1:], - "A:a:c:dhmoprs:t:ux:", + "A:a:c:dhmoprs:t:ux:v", [ "override_alias=", "define_alias=", @@ -208,6 +258,7 @@ def main(): "result=", "pools=", "dump-pools" + "verbose" ] ) except getopt.GetoptError as err: @@ -248,6 +299,7 @@ def main(): multi_match = False dump_config = False dump_pools = False + verbose = False pools = [] for opt, arg in opts: if opt in ("-d", "--debug"): @@ -286,6 +338,8 @@ def main(): pools.extend(arg.split(",")) elif opt in ("--dump-pools"): dump_pools = True + elif opt in ("-v", "--verbose"): + verbose= True
if xslt_url != None: lnst_config.set_option("environment", "xslt_url", xslt_url) @@ -316,12 +370,18 @@ def main():
action = args[0] recipes = args[1:] - if not action in ['run', 'config_only', 'deconfigure', 'match_setup']: + if not action in ['run', 'config_only', 'deconfigure', 'match_setup', + 'list_pools']: logging.error("Action '%s' not recognised" % action) usage(RETVAL_ERR) if action == 'deconfigure': NetTestController.remove_saved_machine_config() return 0 + elif action == 'list_pools': + log_ctl.unset_formatter() + logging.disable(logging.INFO) + list_pools(pools, verbose) + return RETVAL_PASS
if recipes == []: logging.error("No recipe specified!")
updates bash autocompletion file with list_pools action and verbose option
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- install/lnst-ctl.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/install/lnst-ctl.bash b/install/lnst-ctl.bash index 05a9b6d..62aab66 100644 --- a/install/lnst-ctl.bash +++ b/install/lnst-ctl.bash @@ -14,15 +14,15 @@ _list_has_item()
_lnst_ctl() { - local SHORT_OPTS="-a -A -c -d -h -m -o -p -x" + local SHORT_OPTS="-a -A -c -d -h -m -o -p -x -v" local LONG_OPTS="--define-alias --override-alias --config --debug \ --help --no-colours --disable-pool-checks \ - --packet-capture --result" + --packet-capture --result --verbose" local REQUIRE_ARG="-a --define-alias \ -A --override-alias \ -c --config \ -x --result" - local ACTIONS="config_only match_setup run" + local ACTIONS="config_only match_setup run list_pools"
local cur=${COMP_WORDS[COMP_CWORD]} local prev=${COMP_WORDS[COMP_CWORD-1]}
updates lnst-ctl man pages, removing --dump-pools option and adding list_pools action along with verbose option
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- install/lnst-ctl.1.in | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/install/lnst-ctl.1.in b/install/lnst-ctl.1.in index 77d9bb8..28c80b6 100644 --- a/install/lnst-ctl.1.in +++ b/install/lnst-ctl.1.in @@ -45,9 +45,6 @@ Toggle emitting debugging messages. .B --dump-config Dumps the join of all loaded configuration files on stdout and exits .TP -.B --dump-pools -Dumps the available machine pools and exits -.TP .B -h, --help Display usage of this command. .TP @@ -86,6 +83,9 @@ Run each recipe with every pool match possible .BI "-x, --result" =file Write results in XML format to the specified .IR file . +.TP +.B -v, --verbose +Extends output of list_pools action .PP .I RECIPE can be either a LNST recipe file or a directory containing recipe files. @@ -99,8 +99,9 @@ bellow). can be one of .BR "run", .BR "config_only", -.BR "deconfigure" ", and" -.BR "match_setup". +.BR "deconfigure" ", +.BR "match_setup",\ and +.BR "list_pools".
When it is set to .BR "run", @@ -122,6 +123,17 @@ the configuration from a previous config_only run will be removed, including dynamically created devices on virtual machines. There is no need to specify a recipe for this action.
+In case of +.BR "list_pools", +lnst-ctl looks up all the pools entered in configs and dumps info about them. +When used without +.B -v +or +.B --verbose +option, only pool names and paths are printed. +With verbose option, all viable slave machine configs are printed in more +human readable format. + At last, when the .I ACTION is set to
This option is replaced with list_pools action.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst-ctl | 11 ----------- 1 file changed, 11 deletions(-)
diff --git a/lnst-ctl b/lnst-ctl index a9979b4..20c2064 100755 --- a/lnst-ctl +++ b/lnst-ctl @@ -47,8 +47,6 @@ def usage(retval=0): print " -d, --debug emit debugging messages" print " --dump-config dumps the join of all loaded " \ "configuration files on stdout and exits" - print " --dump-pools dumps the available machine " \ - "pools and exits" print " -v, --verbose verbose version of list_pools " \ "command" print " -h, --help print this message" @@ -257,7 +255,6 @@ def main(): "multi-match", "result=", "pools=", - "dump-pools" "verbose" ] ) @@ -298,7 +295,6 @@ def main(): reduce_sync = False multi_match = False dump_config = False - dump_pools = False verbose = False pools = [] for opt, arg in opts: @@ -336,8 +332,6 @@ def main(): dump_config = True elif opt in ("--pools"): pools.extend(arg.split(",")) - elif opt in ("--dump-pools"): - dump_pools = True elif opt in ("-v", "--verbose"): verbose= True
@@ -348,11 +342,6 @@ def main(): print lnst_config.dump_config() return RETVAL_PASS
- if dump_pools: - for pool_name, pool_path in lnst_config.get_pools().items(): - print pool_name + ' = ' + pool_path - return RETVAL_PASS - if coloured_output: coloured_output = not lnst_config.get_option("colours", "disable_colours")
On Mon, May 23, 2016 at 02:16:41PM +0200, Jiri Prochazka wrote:
This will be used in list_pools action for accessing dictionary with available pools.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
ack to set Acked-by: Ondrej Lichtner olichtne@redhat.com
lnst-developers@lists.fedorahosted.org