From: Frank Brehm Date: Thu, 6 Sep 2018 10:32:36 +0000 (+0200) Subject: Finishing get-forge-modules with new modules X-Git-Tag: 0.11.4^2~1 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=05106f9b504561626b8374fc9a3970d9f25187f4;p=pixelpark%2Fpuppetmaster-webhooks.git Finishing get-forge-modules with new modules --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index b8c85cc..1fc3a9f 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.11.2' +__version__ = '0.11.3' # vim: ts=4 et list diff --git a/lib/webhooks/get_forge_modules.py b/lib/webhooks/get_forge_modules.py index a6f3adb..7824b99 100644 --- a/lib/webhooks/get_forge_modules.py +++ b/lib/webhooks/get_forge_modules.py @@ -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)