From 74164a8d13d03ae863dbbcf8090d580e1117ba4b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 20 Aug 2018 15:59:17 +0200 Subject: [PATCH] Generating puppet types --- lib/webhooks/__init__.py | 2 +- lib/webhooks/r10k.py | 48 +++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 77e89e3..a7b60f9 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.8.3' +__version__ = '0.8.4' # vim: ts=4 et list diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index ded2df5..0c9858b 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -182,6 +182,12 @@ class R10kHookApp(BaseHookApp): LOG.warn("Executing {!r} was not successful.".format(self.r10k_bin)) return + if not self.generate_puppet_types(): + msg = "'{c} generate types --environment {e}' was not successful.".format( + self.puppet_bin, self.ref) + LOG.warn(msg) + return + return self.del_env_cache() # ------------------------------------------------------------------------- @@ -256,6 +262,41 @@ class R10kHookApp(BaseHookApp): self.print_out(msg) return + # ------------------------------------------------------------------------- + def generate_puppet_types(self): + """Generates definitions for custom resource types using Puppet code + for the given environment.""" + + res = True + + cmd = [ + self.puppet_bin, 'generate', 'types', + '--environment', self.ref, + '--color', 'false', ] + + if self.verbose > 1: + cmd.append('--verbose') + if self.verbose > 3: + cmd.append('--debug') + + (ret_val, stdoutdata, stderrdata) = self.handler.call(cmd, sudo=self.do_sudo) + + if stdoutdata: + msg = "Output:\n{}".format(to_str(stdoutdata)) + 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: + self.error_data.append(msg) + res = False + self.print_out(msg) + + return res + # ------------------------------------------------------------------------- def exec_r10k(self): @@ -277,21 +318,18 @@ class R10kHookApp(BaseHookApp): (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) res = False - else: - LOG.info(msg) self.print_out(msg) return res -- 2.39.5