From a8becd00cf3eaa754fc76e73485768bded1186db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= <sybren@stuvel.eu> Date: Thu, 14 Dec 2017 14:23:54 +0100 Subject: [PATCH] Add --test CLI arg and override supported task types --- flamenco_worker/cli.py | 10 +++++++++- flamenco_worker/config.py | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/flamenco_worker/cli.py b/flamenco_worker/cli.py index d86f7734..85ebef54 100644 --- a/flamenco_worker/cli.py +++ b/flamenco_worker/cli.py @@ -27,6 +27,10 @@ def main(): help="Enables debug logging for Flamenco Worker's own log entries. " "Edit the logging config in flamenco-worker.cfg " "for more powerful options.") + parser.add_argument('-t', '--test', action='store_true', + help="Starts up in testing mode, in which only a handful of " + "test-specific task types are accepted. This overrides the task_types " + "in the configuration file.") args = parser.parse_args() if args.version: @@ -36,12 +40,16 @@ def main(): # Load configuration from . import config - confparser = config.load_config(args.config, args.verbose) + confparser = config.load_config(args.config, args.verbose, args.test) config.configure_logging(confparser, enable_debug=args.debug) log = logging.getLogger(__name__) log.debug('Starting, pid=%d', os.getpid()) + if args.test: + log.warning('Test mode enabled, overriding task_types=%r', + confparser.value('task_types')) + if args.reregister: log.warning('Erasing worker_id and worker_secret so we can attempt re-registration.') confparser.erase('worker_id') diff --git a/flamenco_worker/config.py b/flamenco_worker/config.py index bb809f56..06387711 100644 --- a/flamenco_worker/config.py +++ b/flamenco_worker/config.py @@ -28,6 +28,9 @@ DEFAULT_CONFIG = { ]) } +# Will be assigned to the config key 'task_types' when started with --test CLI arg. +TESTING_TASK_TYPES = 'test-blender-render' + log = logging.getLogger(__name__) @@ -74,7 +77,8 @@ def merge_with_home_config(new_conf: dict): def load_config(config_file: pathlib.Path = None, - show_effective_config: bool = False) -> ConfigParser: + show_effective_config: bool = False, + enable_test_mode=False) -> ConfigParser: """Loads one or more configuration files.""" # Logging and the default interpolation of configparser both use the @@ -102,6 +106,9 @@ def load_config(config_file: pathlib.Path = None, log.info('Succesfully loaded: %s', loaded) + if enable_test_mode: + confparser.setvalue('task_types', TESTING_TASK_TYPES) + if show_effective_config: import sys log.info('Effective configuration:') -- GitLab