]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Moving puppet_bin from lib/webhooks/base_app.py to lib/webhooks/r10k.py, Using call...
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 21 Aug 2018 09:01:41 +0000 (11:01 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 21 Aug 2018 09:01:41 +0000 (11:01 +0200)
lib/webhooks/__init__.py
lib/webhooks/base_app.py
lib/webhooks/deploy.py
lib/webhooks/handler.py
lib/webhooks/r10k.py

index a7b60f950ce9dbf4694f0eb0c3e1f98111d5a3b1..749c1577a13224e6b41214990bec4663989e6df5 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.8.4'
+__version__ = '0.8.5'
 
 # vim: ts=4 et list
index 6e1c5411461b27c1c350d8268fd50f2461741706..c61381feb2394d7ef7e4d8c1864e2c044b427f4d 100644 (file)
@@ -96,7 +96,6 @@ class BaseHookApp(BaseObject):
 
         self.cmdline_args = None
 
-        self.puppet_bin = None
         self.curl_bin = None
 
         self.handler = None
@@ -124,7 +123,6 @@ class BaseHookApp(BaseObject):
         else:
             LOG.debug("We are NOT in CGI.")
 
-        self.search_puppet_bin()
         self.search_curl_bin()
 
         self.handler = BaseHandler(
@@ -251,19 +249,6 @@ class BaseHookApp(BaseObject):
             sys.stderr.write("\nSimulation mode - nothing is really done.\n\n")
             self.simulate = True
 
-    # -------------------------------------------------------------------------
-    def search_puppet_bin(self):
-
-        searcher = BaseHandler(
-            appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
-
-        cmd = searcher.get_cmd('puppet')
-        del searcher
-        if not cmd:
-            sys.exit(9)
-        self.puppet_bin = cmd
-        return
-
     # -------------------------------------------------------------------------
     def search_curl_bin(self):
 
index d24bc1e2f0aa2780350147ed7b8a064db26631b6..723c7b3206370b5d7cc3676f2d30683046e21340 100644 (file)
@@ -13,7 +13,6 @@ import logging
 import textwrap
 import copy
 import pipes
-import subprocess
 
 # Third party modules
 
@@ -227,43 +226,29 @@ class WebhookDeployApp(BaseHookApp):
 
         try:
             os.chdir(parent_dir)
+
             cmd = []
-            if self.do_sudo:
-                cmd = ['sudo', '-n']
             if os.access(workdir, os.F_OK):
                 os.chdir(workdir)
-                cmd += ['git', 'pull']
+                cmd = ['git', 'pull']
             else:
-                cmd += ['git', 'clone', self.git_ssh_url, workdir]
+                cmd = ['git', 'clone', self.git_ssh_url, workdir]
                 if branch:
                     cmd += ['-b', branch]
-            if self.verbose > 2:
-                LOG.debug("Cmd: {}".format(pp(cmd)))
-            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()
+            (ret_val, stdoutdata, stderrdata) = self.handler.call(cmd, sudo=self.do_sudo)
 
-            LOG.debug("Return value: {}".format(ret_val))
             if stdoutdata:
                 msg = "Output:\n{}".format(to_str(stdoutdata))
-                LOG.info(msg)
                 self.print_out(msg)
             else:
                 LOG.debug("No output.")
+
             if stderrdata:
+                cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
                 msg = "Error messages on '{c}':\n{e}".format(c=cmd_str, e=to_str(stderrdata))
                 if ret_val:
-                    LOG.warn(msg)
                     self.error_data.append(msg)
-                else:
-                    LOG.info(msg)
                 self.print_out(msg)
 
         finally:
index a86c18dd2dc3737cd90646d8ecfa9b59acb49d42..33a377165743da5eaa9ea2ad5dd6afad2134c3ef 100644 (file)
@@ -487,7 +487,7 @@ class BaseHandler(BaseObject):
 
         if stderrdata:
             if six.PY3:
-                if self.verbose > 3:
+                if self.verbose > 2:
                     LOG.debug("Decoding {what} from {enc!r}.".format(
                         what='STDERR', enc=cur_encoding))
                 stderrdata = stderrdata.decode(cur_encoding)
@@ -503,13 +503,13 @@ class BaseHandler(BaseObject):
 
         if stdoutdata:
             if six.PY3:
-                if self.verbose > 3:
+                if self.verbose > 2:
                     LOG.debug("Decoding {what} from {enc!r}.".format(
                         what='STDOUT', enc=cur_encoding))
                 stdoutdata = stdoutdata.decode(cur_encoding)
             if not quiet:
                 msg = "Output on {where}:\n{what}.".format(
-                    where="STDOUT", what=stderrdata.strip())
+                    where="STDOUT", what=stdoutdata.strip())
                 if log_output:
                     LOG.info(msg)
                 else:
index 0c9858bb696bdbe39d8bc8eff6389ede79fb7500..c154431a3473e15a88799ef3b2c5e932ed3861e5 100644 (file)
@@ -15,7 +15,6 @@ import logging
 import textwrap
 import locale
 import pipes
-import subprocess
 import urllib.parse
 import time
 import warnings
@@ -47,6 +46,7 @@ class R10kHookApp(BaseHookApp):
         """Constructor."""
 
         self.r10k_bin = None
+        self.puppet_bin = None
         self.description = textwrap.dedent('''\
             Receives push events as JSON-Data and deploys it with r10k.
             ''').strip()
@@ -65,6 +65,7 @@ class R10kHookApp(BaseHookApp):
 
         self.user_agent = 'pp-webhook-client/' + __version__
 
+        self.search_puppet_bin()
         self.search_r10k_bin()
         self.check_cert_files()
 
@@ -81,6 +82,19 @@ class R10kHookApp(BaseHookApp):
 
         return res
 
+    # -------------------------------------------------------------------------
+    def search_puppet_bin(self):
+
+        searcher = BaseHandler(
+            appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+
+        cmd = searcher.get_cmd('puppet')
+        del searcher
+        if not cmd:
+            sys.exit(9)
+        self.puppet_bin = cmd
+        return
+
     # -------------------------------------------------------------------------
     def search_r10k_bin(self):