]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Generating puppet types
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Aug 2018 13:59:17 +0000 (15:59 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Aug 2018 13:59:17 +0000 (15:59 +0200)
lib/webhooks/__init__.py
lib/webhooks/r10k.py

index 77e89e32f0ae8ce127ad2a1e6845593faba85337..a7b60f950ce9dbf4694f0eb0c3e1f98111d5a3b1 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.8.3'
+__version__ = '0.8.4'
 
 # vim: ts=4 et list
index ded2df568eacde0abcc85cd81767b2b798b9a264..0c9858bb696bdbe39d8bc8eff6389ede79fb7500 100644 (file)
@@ -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