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
This commit is contained in:
Wayne Warren 2015-12-28 22:39:32 -08:00 committed by Darragh Bailey
parent 4f04de1f9a
commit 0da11b51c5
4 changed files with 11 additions and 17 deletions

View File

@ -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')

View File

@ -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):

View File

@ -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

View File

@ -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()