]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Finishing get-forge-modules with new modules
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 10:32:36 +0000 (12:32 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 10:32:36 +0000 (12:32 +0200)
lib/webhooks/__init__.py
lib/webhooks/get_forge_modules.py

index b8c85cc88722669894ba854fd4e71210255ffbd5..1fc3a9f6a2493a17a329887ecff196216b64314e 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.11.2'
+__version__ = '0.11.3'
 
 # vim: ts=4 et list
index a6f3adb05825a9d31b9b95dcc99b196aa2d49396..7824b997660720a4ed378df508731e95f196584d 100644 (file)
@@ -161,7 +161,13 @@ class GetForgeModulesApp(BaseHookApp):
         self.print_out(msg)
         print()
 
-        self.check_data_dir()
+        try:
+            self.check_data_dir()
+        except BaseHookError as e:
+            if self.simulate:
+                LOG.error(str(e))
+            else:
+                six.reraise(*sys.exc_info())
         self.init_puppet_environments()
         self.collect_local_modules()
         self.get_forge_information()
@@ -183,6 +189,7 @@ class GetForgeModulesApp(BaseHookApp):
             appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
 
         for env in self.environments:
+            LOG.debug("Evaluating environment {!r} ..".format(env))
             self.read_puppetfile(env)
             self.read_metadata_files(env)
         if self.verbose > 2:
@@ -233,16 +240,18 @@ class GetForgeModulesApp(BaseHookApp):
         for module_dir in glob.glob(pattern):
             module_info = self.get_meta_module_info(module_dir, env)
             if module_info:
-                full_name = module_info.full_name
-                if full_name in self.modules:
-                    self.modules[full_name].merge_in(module_info)
-                else:
-                    self.modules[full_name] = module_info
+                if self.verbose > 1:
+                    LOG.debug("Got infos about module {!r}".format(module_info.full_name))
+                elif self.verbose > 2:
+                    LOG.debug("Got module info:\n{}".format(pp(module_info.as_dict())))
+                self.modules.merge(module_info)
+            else:
+                LOG.warn("Got no module info from direcrory {!r}".format(module_dir))
 
     # -------------------------------------------------------------------------
     def get_meta_module_info(self, module_dir, env):
 
-        if self.verbose > 2:
+        if self.verbose > 1:
             LOG.debug("Get module information from {!r}.".format(module_dir))
 
         if not os.path.exists(module_dir):
@@ -284,6 +293,8 @@ class GetForgeModulesApp(BaseHookApp):
     # -------------------------------------------------------------------------
     def read_puppetfile(self, env):
 
+        LOG.info("Reading Puppetfile of environment {!r} ..".format(env))
+
         pfile = Puppetfile(
             env_root_dir=self.puppet_root_env_dir, environment=env,
             appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
@@ -292,15 +303,17 @@ class GetForgeModulesApp(BaseHookApp):
         if self.verbose > 1:
             LOG.debug("Got Puppetfile:\n{}".format(pp(pfile.as_dict())))
 
+        pfile_modules = None
         try:
-            self.modules = pfile.read_modules()
+            pfile_modules = pfile.read_modules()
         except PuppetfileError as e:
             LOG.warn(str(e))
-            self.modules = ModuleInfoDict(
-                appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
         else:
             if self.verbose > 2:
                 LOG.debug("Successful read {!r}.".format(pfile.filename))
+        if pfile_modules:
+            for module_info in pfile_modules.values():
+                self.modules.merge(module_info)
 
     # -------------------------------------------------------------------------
     def init_puppet_environments(self):
@@ -340,6 +353,10 @@ class GetForgeModulesApp(BaseHookApp):
 
         LOG.info("Trying to open {!r} exclusive ...".format(tmp_file))
 
+        if self.simulate:
+            LOG.info("Simulation mode, cache file will not be written.")
+            return
+
         try:
             fd = os.open(tmp_file, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
             fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)