]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Simplifying deplay logic, Using simulate flag
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 20 Oct 2017 14:07:43 +0000 (16:07 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 20 Oct 2017 14:07:43 +0000 (16:07 +0200)
lib/webhooks/__init__.py
lib/webhooks/base_app.py
lib/webhooks/deploy.py

index b38e659481c2a169cd1d3bc5a3885ab445408027..f18c805ccc35de39d26bef3e80d56077de231a20 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.6.1'
+__version__ = '0.6.2'
 
 # vim: ts=4 et list
index ec828d5c0a6ddc1a70ae588ae787359cb3570e87..fadc306f44dd91e858653aca05c5f63000788378 100644 (file)
@@ -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:
index 7a7d4c9f499adcc28c9b70ca922cb25f54c6b332..e46a5d9aaa1ba459f5cd10ca38351db7779a61a3 100644 (file)
@@ -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)