From 50bd5ea7e395acf154396d3e7f416eece415e1f5 Mon Sep 17 00:00:00 2001 From: costimuraru Date: Tue, 20 Aug 2019 23:30:18 +0300 Subject: [PATCH] [FIX] Minor himl fixes --- src/ops/cli/helmfile.py | 13 ++-- src/ops/cli/terraform.py | 2 +- .../composition_config_generator.py | 61 ++++++++++--------- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/ops/cli/helmfile.py b/src/ops/cli/helmfile.py index 9ff0ddd8..849808b2 100644 --- a/src/ops/cli/helmfile.py +++ b/src/ops/cli/helmfile.py @@ -9,8 +9,9 @@ # governing permissions and limitations under the License. -import os import logging +import os + from ops.cli.parser import SubParserConfig from ops.hierarchical.composition_config_generator import CompositionConfigGenerator @@ -92,11 +93,11 @@ def get_tmp_file(): def generate_helmfile_config(self, path, args): output_file = args.helmfile_path + "/hiera-generated.yaml" logger.info('Generating helmfiles config %s', output_file) - return self.generator.process(path=path, - filters=["helm", "account", "region", "cluster"], - output_format="yaml", - output_file=output_file, - print_data=True) + return self.config_generator.generate_config(config_path=path, + filters=["helm", "account", "region", "cluster"], + output_format="yaml", + output_file=output_file, + print_data=True) def get_helmfile_command(self, args): cmd = ' '.join(args.extra_args + [args.subcommand]) diff --git a/src/ops/cli/terraform.py b/src/ops/cli/terraform.py index a5c4ea5a..67fb9c96 100644 --- a/src/ops/cli/terraform.py +++ b/src/ops/cli/terraform.py @@ -176,7 +176,7 @@ def run_v2_integration(self, args): reverse_order = "destroy" == args.subcommand compositions = tf_config_generator.get_sorted_compositions(config_path, reverse=reverse_order) if len(compositions) == 0: - raise Exception("No terraform compositions were detected for it in %s.", self, config_path) + raise Exception("No terraform compositions were detected in {}.".format(config_path)) return self.run_v2_compositions(args, config_path, tf_config_generator, terraform_path, compositions) diff --git a/src/ops/hierarchical/composition_config_generator.py b/src/ops/hierarchical/composition_config_generator.py index 893f593b..a73ddf05 100644 --- a/src/ops/hierarchical/composition_config_generator.py +++ b/src/ops/hierarchical/composition_config_generator.py @@ -21,7 +21,7 @@ class CompositionConfigGenerator: def __init__(self, composition_order): self.composition_sorter = CompositionSorter(composition_order) - self.generator = ConfigProcessor() + self.config_generator = HierarchicalConfigGenerator() def get_sorted_compositions(self, path, reverse=False): all_compositions = self.discover_all_compositions(path) @@ -86,11 +86,11 @@ def generate_files(self, config_path, composition_path, composition): def generate_provider_config(self, config_path, composition_path): output_file = "{}provider.tf.json".format(composition_path) logger.info('Generating terraform config %s', output_file) - self.generate_config(config_path=config_path, - filters=["provider", "terraform"], - output_format="json", - output_file=output_file, - print_data=True) + self.config_generator.generate_config(config_path=config_path, + filters=["provider", "terraform"], + output_format="json", + output_file=output_file, + print_data=True) def generate_variables_config(self, config_path, composition_path): output_file = "{}variables.tfvars.json".format(composition_path) @@ -100,25 +100,39 @@ def generate_variables_config(self, config_path, composition_path): if "composition=account" in config_path: excluded_keys.append("remote_states") - self.generate_config(config_path=config_path, - exclude_keys=excluded_keys, - enclosing_key="config", - output_format="json", - output_file=output_file, - print_data=True) + self.config_generator.generate_config(config_path=config_path, + exclude_keys=excluded_keys, + enclosing_key="config", + output_format="json", + output_file=output_file, + print_data=True) + + +class CompositionSorter(object): + def __init__(self, composition_order): + self.composition_order = composition_order + + def get_sorted_compositions(self, compositions, reverse=False): + result = filter(lambda x: x in compositions, self.composition_order) + return tuple(reversed(result)) if reverse else result + + +class HierarchicalConfigGenerator(object): + def __init__(self): + self.config_processor = ConfigProcessor() def generate_config(self, config_path, filters=(), exclude_keys=(), enclosing_key=None, output_format="yaml", print_data=False, output_file=None): cmd = self.get_sh_command(config_path, filters, exclude_keys, enclosing_key, output_format, print_data, output_file) display(cmd, color="yellow") - self.generator.process(path=config_path, - filters=filters, - exclude_keys=exclude_keys, - enclosing_key=enclosing_key, - output_format=output_format, - output_file=output_file, - print_data=print_data) + return self.config_processor.process(path=config_path, + filters=filters, + exclude_keys=exclude_keys, + enclosing_key=enclosing_key, + output_format=output_format, + output_file=output_file, + print_data=print_data) @staticmethod def get_sh_command(config_path, filters=(), exclude_keys=(), enclosing_key=None, output_format="yaml", @@ -136,12 +150,3 @@ def get_sh_command(config_path, filters=(), exclude_keys=(), enclosing_key=None, command += " --print-data" return command - - -class CompositionSorter(object): - def __init__(self, composition_order): - self.composition_order = composition_order - - def get_sorted_compositions(self, compositions, reverse=False): - result = filter(lambda x: x in compositions, self.composition_order) - return tuple(reversed(result)) if reverse else result