From efa1ddf0c3283a6d6353e78433549e0f2eee3dab Mon Sep 17 00:00:00 2001 From: Jon-Paul Sullivan Date: Fri, 25 Jan 2013 11:13:00 +0000 Subject: [PATCH] Bugfix and tidy-up Allow the configuration file to be optional for test mode Tidy-up the hipchat notifier module - Require a valid hipchat authtoken Ignore temporary vi/vim files in .gitignore Add extra debugging output - write out cache file to enable easy removal to force upload - clearly notify that no changes are seen so uploading not occurring Change-Id: Ia418704b76090e284e0b801609f2f05bfa06b9ae Reviewed-on: https://review.openstack.org/20380 Reviewed-by: Jeremy Stanley Reviewed-by: Khai Do Reviewed-by: Clark Boylan Approved: James E. Blair Reviewed-by: James E. Blair Tested-by: Jenkins --- .gitignore | 1 + jenkins_jobs/builder.py | 3 +++ jenkins_jobs/cmd.py | 10 ++++++++-- jenkins_jobs/modules/hipchat_notif.py | 22 +++++++++++++--------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index beb909c8f..d62b42724 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.*.swp *.egg *.egg-info *.pyc diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 73423a2e9..57d7e4c4d 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -237,6 +237,7 @@ class CacheStorage(object): self.data = {} return self.data = yaml.load(yfile) + logger.debug("Using cache: '{0}'".format(self.cachefilename)) yfile.close() @staticmethod @@ -348,3 +349,5 @@ class Builder(object): if self.cache.has_changed(job.name, md5): self.jenkins.update_job(job.name, job.output()) self.cache.set(job.name, md5) + else: + logger.debug("'{0}' has not changed".format(job.name)) diff --git a/jenkins_jobs/cmd.py b/jenkins_jobs/cmd.py index 78bfc1a24..7316c657d 100755 --- a/jenkins_jobs/cmd.py +++ b/jenkins_jobs/cmd.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import jenkins_jobs.builder +import jenkins_jobs.errors import argparse import ConfigParser import logging @@ -52,13 +53,18 @@ def main(): if os.path.isfile(localconf): conf = localconf - if not options.command == 'test': + if os.path.isfile(conf): logger.debug("Reading config from {0}".format(conf)) conffp = open(conf, 'r') config = ConfigParser.ConfigParser() config.readfp(conffp) - else: + elif options.command == 'test': + logger.debug("Not reading config for test output generation") config = {} + else: + raise jenkins_jobs.errors.JenkinsJobsException( + "A valid configuration file is required when not run as a test") + logger.debug("Config: {0}".format(config)) builder = jenkins_jobs.builder.Builder(config.get('jenkins', 'url'), config.get('jenkins', 'user'), diff --git a/jenkins_jobs/modules/hipchat_notif.py b/jenkins_jobs/modules/hipchat_notif.py index 3cd10cf19..cdc1e9cc8 100644 --- a/jenkins_jobs/modules/hipchat_notif.py +++ b/jenkins_jobs/modules/hipchat_notif.py @@ -47,6 +47,7 @@ import jenkins_jobs.modules.base import jenkins_jobs.errors import logging import ConfigParser +import sys logger = logging.getLogger(__name__) @@ -65,15 +66,18 @@ class HipChat(jenkins_jobs.modules.base.Base): unless actually required. """ if(not self.authToken): - # Verify that the config object in the registry is of type - # ConfigParser (it could possibly be a regular 'dict' object which - # doesn't have the right get() method). - if(not isinstance(self.registry.global_config, - ConfigParser.ConfigParser)): - raise jenkins_jobs.errors.JenkinsJobsException( - 'HipChat requires a config object in the registry.') - self.authToken = self.registry.global_config.get( - 'hipchat', 'authtoken') + try: + self.authToken = self.registry.global_config.get( + 'hipchat', 'authtoken') + # Require that the authtoken is non-null + if self.authToken == '': + raise jenkins_jobs.errors.JenkinsJobsException( + "Hipchat authtoken must not be a blank string") + except (ConfigParser.NoSectionError, + jenkins_jobs.errors.JenkinsJobsException), e: + logger.fatal("The configuration file needs a hipchat section" + + " containing authtoken:\n{0}".format(e)) + sys.exit(1) self.jenkinsUrl = self.registry.global_config.get('jenkins', 'url') def gen_xml(self, parser, xml_parent, data):