From: Frank Brehm Date: Tue, 21 Aug 2018 09:01:41 +0000 (+0200) Subject: Moving puppet_bin from lib/webhooks/base_app.py to lib/webhooks/r10k.py, Using call... X-Git-Tag: 0.8.5^2~1 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=2df3ad9e7701364d7ddaaa6994ed83e0f6fb79b9;p=pixelpark%2Fpuppetmaster-webhooks.git Moving puppet_bin from lib/webhooks/base_app.py to lib/webhooks/r10k.py, Using call() from lib/webhooks/handler.py in lib/webhooks/deploy.py --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index a7b60f9..749c157 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.8.4' +__version__ = '0.8.5' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index 6e1c541..c61381f 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -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): diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index d24bc1e..723c7b3 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -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: diff --git a/lib/webhooks/handler.py b/lib/webhooks/handler.py index a86c18d..33a3771 100644 --- a/lib/webhooks/handler.py +++ b/lib/webhooks/handler.py @@ -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: diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index 0c9858b..c154431 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -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):