From 98349ae2f05551764e778070204e35b15111f398 Mon Sep 17 00:00:00 2001 From: Julen Landa Alustiza Date: Sep 25 2018 06:37:41 +0000 Subject: Allow to specify config file from cmdline --- diff --git a/libtaskotron/config.py b/libtaskotron/config.py index 603b0bb..6ee2e23 100644 --- a/libtaskotron/config.py +++ b/libtaskotron/config.py @@ -34,6 +34,8 @@ CONF_FILE = 'taskotron.yaml' NS_CONF_FILE = 'namespaces.yaml' '''the name of result namespaces configuration file''' +CMD_CONF_FILE = None + PROFILE_VAR = 'TASKOTRON_PROFILE' '''environment variable name for setting config profile''' @@ -91,11 +93,13 @@ def _load(): return config # load config files - filename = _search_dirs(CONF_DIRS, CONF_FILE) - if not filename: - log.warning( - 'No config file %s found in dirs: %s' % (CONF_FILE, CONF_DIRS)) - return config + if CMD_CONF_FILE: + filename = CMD_CONF_FILE + else: + filename = _search_dirs(CONF_DIRS, CONF_FILE) + if not filename: + log.warning('No config file %s found in dirs: %s' % (CONF_FILE, CONF_DIRS)) + return config log.debug('Using config file: %s', filename) file_config = _load_file(filename) diff --git a/libtaskotron/main.py b/libtaskotron/main.py index 999d873..f940c19 100644 --- a/libtaskotron/main.py +++ b/libtaskotron/main.py @@ -102,6 +102,8 @@ def get_argparser(): help="path to private key for remote connections over ssh") parser.add_argument("--no-destroy", action="store_true", help="do not destroy disposable client at the end of task execution") + parser.add_argument('--config', metavar="", + help="alternative taskotron.yaml config file") return parser @@ -122,6 +124,9 @@ def check_args(parser, args): if '@' not in args['ssh']: parser.error("SSH connection info not in format 'user@machine' or 'user@machine:port'") + if args['config']: + if not os.path.isfile(args['config']): + parser.error('Option --config-file must have an existing file as argument') def process_args(raw_args): """ Processes raw input args and converts them into specific data types that @@ -137,6 +142,9 @@ def process_args(raw_args): # store the original unprocessed args for later use when passing it to the minion args['_orig_args'] = raw_args + if args['config']: + config.CMD_CONF_FILE = args['config'] + # process item + type if args['type'] in check.ReportType.list(): args[args['type']] = args['item']