From 0273d3f7e80efa270aa5446707397b9de30733b6 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 20 Oct 2017 16:07:43 +0200 Subject: [PATCH] Simplifying deplay logic, Using simulate flag --- lib/webhooks/__init__.py | 2 +- lib/webhooks/base_app.py | 4 ++++ lib/webhooks/deploy.py | 44 ++++++---------------------------------- 3 files changed, 11 insertions(+), 39 deletions(-) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index b38e659..f18c805 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.6.1' +__version__ = '0.6.2' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index ec828d5..fadc306 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -660,6 +660,10 @@ class BaseHookApp(object): r=to_addresses, e=pp(self.error_data), s=self.smtp_server, p=self.smtp_port)) + if self.simulate: + LOG.info("Simulation mode, don't sending mail.") + return + server = smtplib.SMTP(self.smtp_server, self.smtp_port) if 'REQUEST_METHOD' not in os.environ: if self.verbose > 2: diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index 7a7d4c9..e46a5d9 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -154,12 +154,8 @@ class WebhookDeployApp(BaseHookApp): 'user_name': 'Frank Brehm'} """ - if self.full_name == 'puppet/hiera': - cfg = copy.copy(self.projects['hiera']) - return self.deploy_hiera(cfg) - for project_key in self.projects.keys(): - if project_key == 'hiera' or project_key == 'puppet_modules': + if project_key == 'puppet_modules': continue cfg = copy.copy(self.projects[project_key]) if 'namespace' not in cfg: @@ -187,39 +183,6 @@ class WebhookDeployApp(BaseHookApp): return True - # ------------------------------------------------------------------------- - def deploy_hiera(self, cfg): - - LOG.info("Deploying Hiera working directory ...") - - pname = 'hiera' - parent_dir = '/www/data/puppet-hiera' - if self.verbose > 2: - LOG.debug("Got config structure for hiera:\n{}".format(pp(cfg))) - if 'parent_dir' in cfg and cfg['parent_dir']: - parent_dir = cfg['parent_dir'] - workdir = pname - if 'workdir' in cfg and cfg['workdir']: - workdir = cfg['workdir'] - - full_path = os.path.join(parent_dir, workdir) - - LOG.info("Deploying working directory {!r} for Hiera ...".format(full_path)) - - if not os.access(parent_dir, os.F_OK): - msg = "Parent directory {!r} for Hiera does not exists.".format(parent_dir) - LOG.error(msg) - self.error_data.append(msg) - return True - - if not os.path.isdir(parent_dir): - msg = "Path of parent directory {!r} for Hiera is not a directory.".format(parent_dir) - LOG.error(msg) - self.error_data.append(msg) - return True - - return self.ensure_workingdir(parent_dir, workdir) - # ------------------------------------------------------------------------- def deploy(self, cfg): @@ -279,6 +242,10 @@ class WebhookDeployApp(BaseHookApp): cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd)) LOG.info("Executing: {}".format(cmd_str)) + if self.simulate: + LOG.info("Simulation mode, don't executing.") + return + git = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdoutdata, stderrdata) = git.communicate() ret_val = git.wait() @@ -298,6 +265,7 @@ class WebhookDeployApp(BaseHookApp): else: LOG.info(msg) self.print_out(msg) + finally: os.chdir(cur_dir) -- 2.39.5