return True
# -------------------------------------------------------------------------
- def send_error_msgs(self, project='undefined'):
+ def send_error_msgs(self, project=None):
if not self.error_data:
return
if len(self.error_data) > 1:
s = 's'
- body = 'Error{s} while processing {p!r} project:\n\n'.format(
- s=s, p=project)
+ if project:
+ body = 'Error{s} while processing {p!r} project:\n\n'.format(
+ s=s, p=project)
+ subject = 'Puppetmaster deploy error{s} for project {p!r}'.format(
+ s=s, p=project)
+ else:
+ body = 'Error{s} while processing {a!r}:\n\n'.format(
+ s=s, a=self.appname)
+ subject = 'Puppetmaster error{s} processing {a!r}'.format(
+ s=s, a=self.appname)
body += '\n\n'.join(self.error_data)
body += '\n\nCheers\nPuppetmaster'
msg.set_content(body)
msg.set_charset('utf-8')
- msg['Subject'] = 'Puppetmaster deploy error{s} for project {p!r}'.format(
- s=s, p=project)
+ msg['Subject'] = subject
msg['From'] = self.sender_address
to_addresses = ''
if self.mail_to_addresses:
LOG.debug("Susseccful sent message to {r!r} via {s}:{p}.".format(
r=to_addresses, s=self.smtp_server, p=self.smtp_port))
else:
- LOG.error((
- "Errors on sending error message for project "
- "{pr!r} to {r!r} via {s}:{p}:\n{e}").format(
- r=to_addresses, s=self.smtp_server, p=self.smtp_port,
- pr=project, e=pp(result)))
+ if project:
+ msg = (
+ "Errors on sending error message for project "
+ "{pr!r} to {r!r} via {s}:{p}:\n{e}").format(
+ r=to_addresses, s=self.smtp_server, p=self.smtp_port,
+ pr=project, e=pp(result))
+ else:
+ msg = (
+ "Errors on sending error message for {a!r} "
+ "to {r!r} via {s}:{p}:\n{e}").format(
+ a=self.appname, r=to_addresses, s=self.smtp_server,
+ p=self.smtp_port, e=pp(result))
+ LOG.error(msg)
return
from operator import itemgetter
+from distutils.version import LooseVersion
+
# Third party modules
import six
import yaml
pass
+# =============================================================================
+class InvalidEnvironmentError(GetModuleChangesError):
+
+ # -------------------------------------------------------------------------
+ def __init__(self, env_name):
+ """
+ Constructor.
+
+ @param env_name: the name of the invalid environment
+ @type function_name: str
+ """
+
+ self.env_name = env_name
+ if not env_name:
+ self.env_name = '__unkown_environment__'
+
+ # -------------------------------------------------------------------------
+ def __str__(self):
+ """Typecasting into a string for error output."""
+
+ return "Puppet environment {!r} does not exists.".format(self.env_name)
+
# =============================================================================
class GetModuleChangesApp(BaseHookApp):
LOG.error(str(e))
self.exit(7)
- mod_list = self.get_newer_modules(module_infos)
+ version_infos = self.get_newer_modules(module_infos)
# -------------------------------------------------------------------------
def get_newer_modules(self, module_infos):
env_found = False
-
+ LOG.info("Checking verions of modules ...")
+
+ version_infos = []
+
+ for module_info in module_infos.values():
+
+ if self.verbose > 1:
+ LOG.debug("Checking module {!r} ...".format(module_info.full_name))
+
+ if self.environment not in module_info.local_versions:
+ LOG.debug("Module {m!r} not used in environment {e!r}.".format(
+ m=module_info.full_name, e=self.environment))
+ continue
+ env_found = True
+ local_version = LooseVersion(module_info.local_versions[self.environment])
+ if self.verbose > 1:
+ LOG.debug("Module {m!r} has local version {v!r}.".format(
+ m=module_info.full_name, v=str(local_version)))
+
+ if not module_info.forge_avail or not module_info.forge_version:
+ LOG.debug("Module {m!r} not available on Puppet forge.".format(
+ m=module_info.full_name))
+ continue
+
+ forge_version = LooseVersion(module_info.forge_version)
+ if self.verbose > 1:
+ LOG.debug("Version of module {m!r} on Puppet forge: {v!r}.".format(
+ m=module_info.full_name, v=str(forge_version)))
+
+ if local_version < forge_version:
+ LOG.info((
+ "Version of module {m!r} on Puppet forge {fv!r} is newer than "
+ "the local version {lv!r}.").format(
+ m=module_info.full_name, lv=str(local_version), fv=str(forge_version)))
+ else:
+ LOG.debug((
+ "Version of module {m!r} on Puppet forge {fv!r} is equal or older than "
+ "the local version {lv!r}.").format(
+ m=module_info.full_name, lv=str(local_version), fv=str(forge_version)))
+ continue
+
+ version_info = {
+ 'name': module_info.name,
+ 'full_name': module_info.full_name,
+ 'local_version': local_version,
+ 'forge_version': forge_version
+ }
+ version_infos.append(version_info)
+
+ if not env_found:
+ raise InvalidEnvironmentError(self.environment)
+
+ if self.verbose > 1:
+ LOG.debug("Found newer modules in Puppet forge:\n{}".format(pp(version_infos)))
+
+ return version_infos
# =============================================================================