def execute(self, args, extra_args, cli_args, logging_handler, no_docker=False): cli_args["harpoon"]["config"] = cli_args["harpoon"]["config"]() cli_args["harpoon"]["extra"] = extra_args if not no_docker: cli_args["harpoon"]["docker_context"] = docker_context() cli_args["harpoon"]["docker_context_maker"] = docker_context for key in ('bash', 'command'): if cli_args[key] is None: cli_args[key] = NotSpecified collector = Collector() collector.prepare(cli_args["harpoon"]["config"].name, cli_args) if "term_colors" in collector.configuration: self.setup_logging_theme( logging_handler, colors=collector.configuration["term_colors"]) collector.configuration["task_runner"]( collector.configuration["harpoon"].chosen_task)
def run(self, collector, image, available_actions, tasks, **extras): """Run this task""" task_func = available_actions[self.action] configuration = collector.configuration.wrapped() if self.options: if image: configuration.update({"images": {image: self.options}}) else: configuration.update(self.options) # args like --port and the like should override what's in the options # But themselves be overridden by the overrides configuration.update(configuration["args_dict"].as_dict(), source="<args_dict>") if self.overrides: overrides = {} for key, val in self.overrides.items(): overrides[key] = val if isinstance(val, MergedOptions): overrides[key] = dict(val.items()) configuration.update(overrides) if task_func.needs_image: self.find_image(image, configuration) image = configuration["images"][image] image.find_missing_env() from harpoon.collector import Collector new_collector = Collector() new_collector.configuration = configuration new_collector.configuration_file = collector.configuration_file artifact = configuration["harpoon"].artifact return task_func(new_collector, image=image, tasks=tasks, artifact=artifact, **extras)
def execute(self, args_obj, args_dict, extra_args, logging_handler, no_docker=False): args_dict["harpoon"]["config"] = args_dict["harpoon"]["config"]( optional=True) or NotSpecified args_dict["harpoon"]["extra"] = extra_args config_name = None if args_dict["harpoon"]["config"] is not NotSpecified: config_name = args_dict["harpoon"]["config"].name if not no_docker: args_dict["harpoon"]["docker_context"] = docker_context() args_dict["harpoon"]["docker_context_maker"] = docker_context collector = Collector() collector.prepare(config_name, args_dict) if "term_colors" in collector.configuration: self.setup_logging_theme( logging_handler, colors=collector.configuration["term_colors"]) collector.configuration["task_runner"]( collector.configuration["harpoon"].chosen_task)
def run(self, collector, image, available_actions, tasks, **extras): """Run this task""" task_func = available_actions[self.action] configuration = collector.configuration.wrapped() if self.options: if image: configuration.update({"images": {image: self.options}}) else: configuration.update(self.options) # Cli args like --port and the like should override what's in the options # But themselves be overridden by the overrides configuration.update(configuration["cli_args"].as_dict(), source="<cli_args>") if self.overrides: overrides = {} for key, val in self.overrides.items(): overrides[key] = val if isinstance(val, MergedOptions): overrides[key] = dict(val.items()) configuration.update(overrides) if task_func.needs_image: self.find_image(image, configuration) image = configuration["images"][image] image.find_missing_env() from harpoon.collector import Collector new_collector = Collector() new_collector.configuration = configuration new_collector.configuration_file = collector.configuration_file return task_func(new_collector, image=image, tasks=tasks, **extras)
def execute(self, args_obj, args_dict, extra_args, logging_handler, no_docker=False): args_dict["harpoon"]["config"] = args_dict["harpoon"]["config"]() args_dict["harpoon"]["extra"] = extra_args if not no_docker: args_dict["harpoon"]["docker_context"] = docker_context() args_dict["harpoon"]["docker_context_maker"] = docker_context collector = Collector() collector.prepare(args_dict["harpoon"]["config"].name, args_dict) if "term_colors" in collector.configuration: self.setup_logging_theme(logging_handler, colors=collector.configuration["term_colors"]) collector.configuration["task_runner"](collector.configuration["harpoon"].chosen_task)
def execute(self, args, extra_args, cli_args, logging_handler, no_docker=False): cli_args["harpoon"]["config"] = cli_args["harpoon"]["config"]() cli_args["harpoon"]["extra"] = extra_args if not no_docker: cli_args["harpoon"]["docker_context"] = docker_context() cli_args["harpoon"]["docker_context_maker"] = docker_context for key in ('bash', 'command'): if cli_args[key] is None: cli_args[key] = NotSpecified collector = Collector() collector.prepare(cli_args["harpoon"]["config"].name, cli_args) if "term_colors" in collector.configuration: self.setup_logging_theme(logging_handler, colors=collector.configuration["term_colors"]) collector.configuration["task_runner"](collector.configuration["harpoon"].chosen_task)
it "finds tasks attached to images": configuration = { "images": { "blah": { "commands": "FROM ubuntu:14.04" , "tasks": {"one": {}} } , "stuff": { "commands": "FROM ubuntu:14.04" , "tasks": {"two": {"description": "not much"}} } , "other": { "commands": "FROM ubuntu:14.04" } } } with self.a_temp_file(json.dumps(configuration)) as filename: default_tasks = mock.Mock(name="default_tasks", return_value={}) collector = Collector() collector.prepare(filename, {"harpoon": {}, "bash": None, "command": None, "assume_role": None}) task_finder = TaskFinder(collector) with mock.patch.object(task_finder, "default_tasks", default_tasks): tasks = task_finder.find_tasks({}) self.assertEqual(sorted(list(tasks.keys())), sorted(["one", "two"])) self.assertEqual(tasks["one"].image, "blah") self.assertEqual(tasks["two"].image, "stuff")
from input_algorithms import spec_base as sb from input_algorithms.dictobj import dictobj from delfick_app import command_output from option_merge import MergedOptions from textwrap import dedent from getpass import getpass import mock import json import os describe HarpoonCase, "Collector": describe "clone": it "has a new harpoon object": configuration = {"images": {"blah": {"commands": "FROM ubuntu:14.04"}}} with self.a_temp_file(json.dumps(configuration)) as filename: collector = Collector() collector.prepare(filename, {"harpoon": {"chosen_image": "blah"}, "bash": None, "command": None, "assume_role": None}) collector2 = collector.clone({"harpoon": {"chosen_image": "other"}}) self.assertNotEqual(collector.configuration["harpoon"], collector2.configuration["harpoon"]) self.assertEqual(collector.configuration["harpoon"].chosen_image, "blah") self.assertEqual(collector2.configuration["harpoon"].chosen_image, "other") describe "prepare": it "adds some items to the configuration from the args_dict": bash = "bash command" extra = "extra commands after the --" command = "Command command" args_dict = {"harpoon": {}} configuration = {"images": {"blah": {"commands": "FROM ubuntu:14.04"}}}
from input_algorithms.dictobj import dictobj from delfick_app import command_output from option_merge import MergedOptions from textwrap import dedent from getpass import getpass import mock import json import os describe HarpoonCase, "Collector": describe "clone": it "has a new harpoon object": configuration = {"harpoon": {"chosen_image": "blah"}, "images": {"blah": {"commands": "FROM ubuntu:14.04"}}} with self.a_temp_file(json.dumps(configuration)) as filename: collector = Collector() collector.prepare(filename, {"harpoon": {}, "bash": None, "command": None}) collector2 = collector.clone({"chosen_image": "other"}) self.assertNotEqual(collector.configuration["harpoon"], collector2.configuration["harpoon"]) self.assertEqual(collector.configuration["harpoon"].chosen_image, "blah") self.assertEqual(collector2.configuration["harpoon"].chosen_image, "other") describe "prepare": it "complains if there is no images": configuration = {} with self.a_temp_file(json.dumps(configuration)) as filename: with self.fuzzyAssertRaisesError(Collector.BadConfigurationErrorKls, "Didn't find any images in the configuration"): Collector().prepare(filename, {}) it "adds some items to the configuration from the cli_args":