Migrate hipchat conf to new plugin style conf
Remove the old default hipchat configuration style in favour of using the new plugin style and provide a mechanism to copy the url value from the jenkins section automatically as part of a simple migration. This will allow removal of querying the jenkins section from existing module code and allow for better isolation. Change-Id: I6889777904ebabc01c044abcd31c9d8a20c255c4
This commit is contained in:
parent
99b3cd55dc
commit
906781a752
|
@ -45,10 +45,6 @@ allow_empty_variables=False
|
|||
[jenkins]
|
||||
url=http://localhost:8080/
|
||||
query_plugins_info=True
|
||||
|
||||
[hipchat]
|
||||
authtoken=dummy
|
||||
send-as=Jenkins
|
||||
"""
|
||||
|
||||
CONFIG_REQUIRED_MESSAGE = ("A valid configuration file is required. "
|
||||
|
@ -135,9 +131,9 @@ class JJBConfig(object):
|
|||
self.jenkins = defaultdict(None)
|
||||
self.builder = defaultdict(None)
|
||||
self.yamlparser = defaultdict(None)
|
||||
self.hipchat = defaultdict(None)
|
||||
|
||||
self._setup()
|
||||
self._handle_deprecated_hipchat_config()
|
||||
|
||||
def _init_defaults(self):
|
||||
""" Initialize default configuration values using DEFAULT_CONF
|
||||
|
@ -165,6 +161,37 @@ class JJBConfig(object):
|
|||
|
||||
return config_fp
|
||||
|
||||
def _handle_deprecated_hipchat_config(self):
|
||||
config = self.config_parser
|
||||
|
||||
if config.has_section('hipchat'):
|
||||
if config.has_section('plugin "hipchat"'):
|
||||
logger.warning(
|
||||
"Both [hipchat] and [plugin \"hipchat\"] sections "
|
||||
"defined, legacy [hipchat] section will be ignored."
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"[hipchat] section is deprecated and should be moved to a "
|
||||
"[plugins \"hipchat\"] section instead as the [hipchat] "
|
||||
"section will be ignored in the future."
|
||||
)
|
||||
config.add_section('plugin "hipchat"')
|
||||
for option in config.options("hipchat"):
|
||||
config.set('plugin "hipchat"', option,
|
||||
config.get("hipchat", option))
|
||||
|
||||
config.remove_section("hipchat")
|
||||
|
||||
# remove need to reference jenkins section when using hipchat plugin
|
||||
# moving to backports configparser would allow use of extended
|
||||
# interpolation to remove the need for plugins to need information
|
||||
# directly from the jenkins section within code and allow variables
|
||||
# in the config file to refer instead.
|
||||
if (config.has_section('plugin "hipchat"') and
|
||||
not config.has_option('plugin "hipchat"', 'url')):
|
||||
config.set('plugin "hipchat"', "url", config.get('jenkins', 'url'))
|
||||
|
||||
def _setup(self):
|
||||
config = self.config_parser
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ 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 = jjb_config.jenkins['url']
|
||||
self.jenkinsUrl = jjb_config.get_plugin_config('hipchat', 'url')
|
||||
self.sendAs = jjb_config.get_plugin_config('hipchat', 'send-as')
|
||||
|
||||
def gen_xml(self, xml_parent, data):
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
[plugin "hipchat"]
|
||||
authtoken=dummy
|
||||
send-as=Jenkins
|
|
@ -0,0 +1 @@
|
|||
hipchat004.conf
|
|
@ -0,0 +1 @@
|
|||
hipchat004.conf
|
Loading…
Reference in New Issue