From a0146de611c966cbed63cbe880a63925213dc4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Wed, 5 Jun 2019 19:57:30 +0200 Subject: [PATCH] Minor formatting and fix tests --- plugins/minio/tutorminio/plugin.py | 5 ++--- tests/test_plugins.py | 5 +++++ tutor/commands/local.py | 16 ++++++++++++---- tutor/config.py | 1 + tutor/env.py | 1 + tutor/scripts.py | 5 ++++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/plugins/minio/tutorminio/plugin.py b/plugins/minio/tutorminio/plugin.py index 2918c48..e8d47f7 100644 --- a/plugins/minio/tutorminio/plugin.py +++ b/plugins/minio/tutorminio/plugin.py @@ -21,9 +21,8 @@ config = { templates = os.path.join(HERE, "templates") -scripts = { - "init": ["minio-client"] -} +scripts = {"init": ["minio-client"]} + def patches(): all_patches = {} diff --git a/tests/test_plugins.py b/tests/test_plugins.py index b582307..2472091 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -66,6 +66,7 @@ class PluginsTests(unittest.TestCase): def test_configure(self): config = {"ID": "id"} defaults = {} + class plugin1: config = { "add": {"PARAM1": "value1", "PARAM2": "value2"}, @@ -104,6 +105,7 @@ class PluginsTests(unittest.TestCase): def test_configure_set_random_string(self): config = {} + class plugin1: config = {"set": {"PARAM1": "{{ 128|random_string }}"}} @@ -116,8 +118,10 @@ class PluginsTests(unittest.TestCase): def test_configure_default_value_with_previous_definition(self): config = {} defaults = {"PARAM1": "value"} + class plugin1: config = {"defaults": {"PARAM2": "{{ PARAM1 }}"}} + with unittest.mock.patch.object( plugins, "iter_enabled", return_value=[("plugin1", plugin1)] ): @@ -127,6 +131,7 @@ class PluginsTests(unittest.TestCase): def test_scripts(self): class plugin1: scripts = {"init": ["myclient"]} + with unittest.mock.patch.object( plugins, "iter_enabled", return_value=[("plugin1", plugin1)] ): diff --git a/tutor/commands/local.py b/tutor/commands/local.py index 8b12973..eee911b 100644 --- a/tutor/commands/local.py +++ b/tutor/commands/local.py @@ -122,7 +122,7 @@ def run(root, entrypoint, service, command, args): run_command = ["run", "--rm"] if entrypoint: run_command += ["--entrypoint", entrypoint] - run_command.append(service) + run_command.append(service) if command: run_command.append(command) if args: @@ -176,8 +176,7 @@ def https_create(root): fmt.echo_info("HTTPS is not activated: certificate generation skipped") return - # TODO this is not going to work anymore - script = runner.render("certbot", "create") + script = runner.render("scripts", "certbot", "create") if config["WEB_PROXY"]: fmt.echo_info( @@ -305,7 +304,16 @@ def portainer(root, port): class ScriptRunner(scripts.BaseRunner): def exec(self, service, command): - docker_compose(self.root, self.config, "run", "--rm", "--entrypoint", "sh -e -c", service, command) + docker_compose( + self.root, + self.config, + "run", + "--rm", + "--entrypoint", + "sh -e -c", + service, + command, + ) def docker_compose(root, config, *command): diff --git a/tutor/config.py b/tutor/config.py index 345ece0..e72d8ea 100644 --- a/tutor/config.py +++ b/tutor/config.py @@ -111,6 +111,7 @@ def load_required(config, defaults): if key not in config: config[key] = env.render_unknown(config, defaults[key]) + def load_plugins(config, defaults): """ Add, override and set new defaults from plugins. diff --git a/tutor/env.py b/tutor/env.py index 3511766..d2ff781 100644 --- a/tutor/env.py +++ b/tutor/env.py @@ -160,6 +160,7 @@ def render_unknown(config, value): return render_str(config, value) return value + def render_str(config, text): """ Args: diff --git a/tutor/scripts.py b/tutor/scripts.py index 37e9770..fafc0d3 100644 --- a/tutor/scripts.py +++ b/tutor/scripts.py @@ -10,9 +10,12 @@ class BaseRunner: self.config = config def run(self, service, *path): - command = env.render_file(self.config, *path).strip() + command = self.render(*path) self.exec(service, command) + def render(self, *path): + return env.render_file(self.config, *path).strip() + def exec(self, service, command): raise NotImplementedError