From 0da11b51c5e586d1b104e91f6917c129777f0555 Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Mon, 28 Dec 2015 22:39:32 -0800 Subject: [PATCH] Use JJBConfig in ModuleRegistry. Remove reference to ConfigParser object in ModuleRegistry. Instead: * make use of JJBConfig.get_module_config to grab settings for Hipchat Notifier Plugin * make use of JJBConfig.yamlparser['allow_empty_variables'] rather than repeating ConfigParser logic moved out of the YamlParser into JJBConfig in an earlier commit. Change-Id: Icb7ef514826005545e48af993335ce120f973b0d --- jenkins_jobs/modules/hipchat_notif.py | 9 +++++---- jenkins_jobs/parser.py | 2 +- jenkins_jobs/registry.py | 14 ++++---------- tests/moduleregistry/test_moduleregistry.py | 3 +-- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/jenkins_jobs/modules/hipchat_notif.py b/jenkins_jobs/modules/hipchat_notif.py index d5d50c411..4cc88ea15 100644 --- a/jenkins_jobs/modules/hipchat_notif.py +++ b/jenkins_jobs/modules/hipchat_notif.py @@ -100,10 +100,11 @@ class HipChat(jenkins_jobs.modules.base.Base): This is done lazily to avoid looking up the '[hipchat]' section unless actually required. """ + jjb_config = self.registry.jjb_config if(not self.authToken): try: - self.authToken = self.registry.global_config.get( - 'hipchat', 'authtoken') + self.authToken = jjb_config.get_module_config('hipchat', + 'authtoken') # Require that the authtoken is non-null if self.authToken == '': raise jenkins_jobs.errors.JenkinsJobsException( @@ -113,8 +114,8 @@ class HipChat(jenkins_jobs.modules.base.Base): 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') - self.sendAs = self.registry.global_config.get('hipchat', 'send-as') + self.jenkinsUrl = jjb_config.jenkins['url'] + self.sendAs = jjb_config.get_module_config('hipchat', 'send-as') def gen_xml(self, parser, xml_parent, data): hipchat = data.get('hipchat') diff --git a/jenkins_jobs/parser.py b/jenkins_jobs/parser.py index 8a1949d14..ba947e79c 100644 --- a/jenkins_jobs/parser.py +++ b/jenkins_jobs/parser.py @@ -79,7 +79,7 @@ class YamlParser(object): self.keep_desc = jjb_config.yamlparser['keep_descriptions'] self.path = jjb_config.yamlparser['include_path'] - self.registry = ModuleRegistry(jjb_config.config_parser, + self.registry = ModuleRegistry(jjb_config, plugins_info) def parse_fp(self, fp): diff --git a/jenkins_jobs/registry.py b/jenkins_jobs/registry.py index 5b9f4fd45..66fd20637 100644 --- a/jenkins_jobs/registry.py +++ b/jenkins_jobs/registry.py @@ -30,11 +30,11 @@ logger = logging.getLogger(__name__) class ModuleRegistry(object): entry_points_cache = {} - def __init__(self, config, plugins_list=None): + def __init__(self, jjb_config, plugins_list=None): self.modules = [] self.modules_by_component_type = {} self.handlers = {} - self.global_config = config + self.jjb_config = jjb_config self.masked_warned = {} if plugins_list is None: @@ -153,15 +153,9 @@ class ModuleRegistry(object): if template_data: # Template data contains values that should be interpolated # into the component definition - allow_empty_variables = self.global_config \ - and self.global_config.has_section('job_builder') \ - and self.global_config.has_option( - 'job_builder', 'allow_empty_variables') \ - and self.global_config.getboolean( - 'job_builder', 'allow_empty_variables') - component_data = deep_format( - component_data, template_data, allow_empty_variables) + component_data, template_data, + self.jjb_config.yamlparser['allow_empty_variables']) else: # The component is a simple string name, eg "run-tests" name = component diff --git a/tests/moduleregistry/test_moduleregistry.py b/tests/moduleregistry/test_moduleregistry.py index 8479db9f6..65e5bde20 100644 --- a/tests/moduleregistry/test_moduleregistry.py +++ b/tests/moduleregistry/test_moduleregistry.py @@ -34,7 +34,6 @@ class ModuleRegistryPluginInfoTestsWithScenarios(TestWithScenarios, jjb_config = JJBConfig() jjb_config.validate() - config = jjb_config.config_parser plugin_info = [{'shortName': "HerpDerpPlugin", 'longName': "Blah Blah Blah Plugin" @@ -45,7 +44,7 @@ class ModuleRegistryPluginInfoTestsWithScenarios(TestWithScenarios, }) self.addDetail("plugin_info", text_content(str(plugin_info))) - self.registry = ModuleRegistry(config, plugin_info) + self.registry = ModuleRegistry(jjb_config, plugin_info) def tearDown(self): super(ModuleRegistryPluginInfoTestsWithScenarios, self).tearDown()