Merge "No warn on old plugin conf format not in use"

This commit is contained in:
Zuul 2018-01-12 14:56:05 +00:00 committed by Gerrit Code Review
commit 1854fde4d9
3 changed files with 41 additions and 5 deletions
jenkins_jobs
tests/cmd

@ -51,6 +51,7 @@ query_plugins_info=False
CONFIG_REQUIRED_MESSAGE = ("A valid configuration file is required. "
"No configuration file passed.")
_NOTSET = object()
class JJBConfig(object):
@ -354,10 +355,13 @@ class JJBConfig(object):
# plugin configuration format in their config. This code should be
# removed in future versions of JJB after 2.0.
if value is default:
value = self.get_module_config(plugin, key, default)
logger.warning(
"Defining plugin configuration using [" + plugin + "] is"
" deprecated. The recommended way to define plugins now is by"
" configuring [plugin \"" + plugin + "\"]")
old_value = self.get_module_config(plugin, key, _NOTSET)
# only log warning if detected a plugin config setting.
if old_value is not _NOTSET:
value = old_value
logger.warning(
"Defining plugin configuration using [" + plugin + "] is "
"deprecated. The recommended way to define plugins now is "
"by configuring [plugin \"" + plugin + "\"]")
return value

@ -0,0 +1,5 @@
[old_plugin]
setting = some value
[plugin "new_plugin"]
setting = some value

@ -77,6 +77,33 @@ class TestConfigs(CmdTestsBase):
jenkins_jobs = entry.JenkinsJobs(args)
self.assertRaises(IOError, jenkins_jobs.execute)
def test_config_old_plugin_format_warning(self):
"""
Run test mode and check that old plugin settings result
in a warning, while ensuring that missing sections do not
trigger the same warning if a default value is provided.
"""
args = ['--conf',
os.path.join(self.fixtures_path, 'plugin_warning.ini'),
'test', 'foo']
jenkins_jobs = entry.JenkinsJobs(args)
jenkins_jobs.jjb_config.get_plugin_config(
'old_plugin', 'setting', True)
jenkins_jobs.jjb_config.get_plugin_config(
'old_plugin_no_conf', 'setting', True)
jenkins_jobs.jjb_config.get_plugin_config(
'new_plugin', 'setting')
self.assertIn(
'Defining plugin configuration using [old_plugin] is deprecated',
self.logger.output)
self.assertNotIn(
'Defining plugin configuration using [old_plugin_no_conf] is '
'deprecated',
self.logger.output)
self.assertNotIn(
'Defining plugin configuration using [new_plugin] is deprecated',
self.logger.output)
def test_config_options_not_replaced_by_cli_defaults(self):
"""
Run test mode and check config settings from conf file retained