From 23af9aa638e2500f880244b7d27da326088afc6e Mon Sep 17 00:00:00 2001 From: jem Date: Tue, 3 Mar 2020 18:30:17 +0100 Subject: [PATCH] debugged --- build.py | 2 +- src/main/python/ddadevops/aws_mixin.py | 11 ++++++----- src/main/python/ddadevops/dda_pallet_mixin.py | 4 ++++ src/main/python/ddadevops/devops_build.py | 15 +++++---------- .../python/ddadevops/devops_terraform_build.py | 18 ++++++++++-------- src/main/python/ddadevops/hetzner_mixin.py | 2 +- src/main/python/ddadevops/python_util.py | 5 ++++- 7 files changed, 31 insertions(+), 26 deletions(-) diff --git a/build.py b/build.py index 41d8403..708d604 100644 --- a/build.py +++ b/build.py @@ -27,7 +27,7 @@ use_plugin("python.distutils") default_task = "publish" name = "ddadevops" -version = "0.4.0.dev2" +version = "0.4.0.dev8" summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud" description = __doc__ authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")] diff --git a/src/main/python/ddadevops/aws_mixin.py b/src/main/python/ddadevops/aws_mixin.py index 222e479..5dea461 100644 --- a/src/main/python/ddadevops/aws_mixin.py +++ b/src/main/python/ddadevops/aws_mixin.py @@ -11,7 +11,7 @@ def add_aws_mixin_config(config, account_name): class AwsMixin(DevopsTerraformBuild): - def __init__(project, config): + def __init__(self, project, config): super().__init__(project, config) aws_mixin_config = config['AwsMixin'] self.account_name = aws_mixin_config['account_name'] @@ -21,11 +21,12 @@ class AwsMixin(DevopsTerraformBuild): def project_vars(self): ret = super().project_vars() - return ret.update({'account_name': self.account_name}) + ret.update({'account_name': self.account_name}) + return ret def init_client(self): tf = Terraform(working_dir=self.build_path()) - tf.init(backend_config=self.backend_config) + tf.init(backend_config=self.backend_config()) try: tf.workspace('select', slef.stage) except: @@ -34,5 +35,5 @@ class AwsMixin(DevopsTerraformBuild): def plan(self): tf = self.init_client() - tf.plan(capture_output=False, var=self.project_vars, - var_file=self.backend_config) + tf.plan(capture_output=False, var=self.project_vars(), + var_file=self.backend_config()) diff --git a/src/main/python/ddadevops/dda_pallet_mixin.py b/src/main/python/ddadevops/dda_pallet_mixin.py index baa7141..1b40e83 100644 --- a/src/main/python/ddadevops/dda_pallet_mixin.py +++ b/src/main/python/ddadevops/dda_pallet_mixin.py @@ -32,6 +32,10 @@ class DdaPalletMixin(DevopsBuild): self.target_template = Template( dda_pallet_mixin_config['target_template']) + def initialize_build_dir(self): + super().initialize_build_dir() + run('cp *.edn ' + self.build_path(), shell=True) + def dda_write_target(self, node_name, ipv4): with open(self.build_path() + self.target_edn_name, "w") as output_file: output_file.write( diff --git a/src/main/python/ddadevops/devops_build.py b/src/main/python/ddadevops/devops_build.py index 32f86bf..4ca917c 100644 --- a/src/main/python/ddadevops/devops_build.py +++ b/src/main/python/ddadevops/devops_build.py @@ -1,4 +1,5 @@ from subprocess import run +from .python_util import filter_none def create_devops_build_config(stage, project_root_path, build_commons_path, module): @@ -8,7 +9,6 @@ def create_devops_build_config(stage, project_root_path, build_commons_path, mod 'module': module, 'build_dir_name': 'target'} - class DevopsBuild: def __init__(self, project, config): @@ -24,16 +24,11 @@ class DevopsBuild: return self.project.get_property('name') def build_path(self): - return self.project_root_path + self.build_dir_name + '/' + self.module + '/' + mylist = [self.project_root_path, + self.build_dir_name, + self.module] + return '/'.join(filter_none(mylist)) def initialize_build_dir(self): run('rm -rf ' + self.build_path(), shell=True) run('mkdir -p ' + self.build_path(), shell=True) - - -def tf_import_name(project): - return project.get_property('tf_import_name') - - -def tf_import_resource(project): - return project.get_property('tf_import_resource') diff --git a/src/main/python/ddadevops/devops_terraform_build.py b/src/main/python/ddadevops/devops_terraform_build.py index 61f2b0b..7e35237 100644 --- a/src/main/python/ddadevops/devops_terraform_build.py +++ b/src/main/python/ddadevops/devops_terraform_build.py @@ -2,6 +2,7 @@ from os import path from json import load from subprocess import run from python_terraform import * +from .python_util import filter_none from .devops_build import DevopsBuild, create_devops_build_config @@ -29,7 +30,9 @@ class DevopsTerraformBuild(DevopsBuild): self.output_json_name = config['output_json_name'] def terraform_build_commons_path(self): - return self.build_commons_path() + '/' + self.terraform_build_commons_dir_name + mylist = [self.build_commons_path, + self.terraform_build_commons_dir_name] + return '/'.join(filter_none(mylist)) def project_vars(self): ret = {'stage': self.stage} @@ -41,12 +44,11 @@ class DevopsTerraformBuild(DevopsBuild): def initialize_build_dir(self): super().initialize_build_dir() - run('cp -f ' + self.terraform_build_commons_path + - '* ' + self.build_path, shell=True) - run('cp *.tf ' + self.build_path, shell=True) - run('cp *.properties ' + self.build_path, shell=True) - run('cp *.tfars ' + self.build_path, shell=True) - run('cp *.edn ' + self.build_path, shell=True) + run('cp -f ' + self.terraform_build_commons_path() + + '* ' + self.build_path(), shell=True) + run('cp *.tf ' + self.build_path(), shell=True) + run('cp *.properties ' + self.build_path(), shell=True) + run('cp *.tfars ' + self.build_path(), shell=True) def init_client(self): tf = Terraform(working_dir=self.build_path()) @@ -68,7 +70,7 @@ class DevopsTerraformBuild(DevopsBuild): def plan(self): tf = self.init_client() - tf.plan(capture_output=False, var=self.project_vars) + tf.plan(capture_output=False, var=self.project_vars()) def apply(self, p_auto_approve=False): tf = self.init_client() diff --git a/src/main/python/ddadevops/hetzner_mixin.py b/src/main/python/ddadevops/hetzner_mixin.py index dc142e2..d7d43c3 100644 --- a/src/main/python/ddadevops/hetzner_mixin.py +++ b/src/main/python/ddadevops/hetzner_mixin.py @@ -17,7 +17,7 @@ class HetznerMixin(DevopsTerraformBuild): hetzner_mixin_config['HETZNER_API_KEY_PATH_ENVIRONMENT']) def project_vars(self): - ret = super().project_vars + ret = super().project_vars() if self.hetzner_api_key: ret['hetzner_api_key'] = self.hetzner_api_key return ret diff --git a/src/main/python/ddadevops/python_util.py b/src/main/python/ddadevops/python_util.py index 5f7e110..1256342 100644 --- a/src/main/python/ddadevops/python_util.py +++ b/src/main/python/ddadevops/python_util.py @@ -6,4 +6,7 @@ def execute(cmd): output = check_output(cmd, encoding='UTF-8') else: output = check_output(cmd) - return output \ No newline at end of file + return output + +def filter_none(list): + return [x for x in list if x is not None]