Merge "Cleanup various deprecation warnings."

This commit is contained in:
Jenkins 2016-08-20 06:50:28 +00:00 committed by Gerrit Code Review
commit a4ee0a4d78
12 changed files with 81 additions and 64 deletions

@ -193,9 +193,10 @@ class Jenkins(object):
plugins_list = self.jenkins.get_plugins_info() plugins_list = self.jenkins.get_plugins_info()
except jenkins.JenkinsException as e: except jenkins.JenkinsException as e:
if re.search("Connection refused", str(e)): if re.search("Connection refused", str(e)):
logger.warn("Unable to retrieve Jenkins Plugin Info from {0}," logger.warning(
" using default empty plugins info list.".format( "Unable to retrieve Jenkins Plugin Info from {0},"
self.jenkins.server)) " using default empty plugins info list.".format(
self.jenkins.server))
plugins_list = [{'shortName': '', plugins_list = [{'shortName': '',
'version': '', 'version': '',
'longName': ''}] 'longName': ''}]

@ -21,6 +21,7 @@ import logging
import os import os
from six.moves import configparser, StringIO from six.moves import configparser, StringIO
from six import PY2
from jenkins_jobs import builder from jenkins_jobs import builder
from jenkins_jobs.errors import JJBConfigException from jenkins_jobs.errors import JJBConfigException
@ -116,7 +117,10 @@ class JJBConfig(object):
"config values.".format(conf)) "config values.".format(conf))
if config_fp is not None: if config_fp is not None:
config_parser.readfp(config_fp) if PY2:
config_parser.readfp(config_fp)
else:
config_parser.read_file(config_fp)
self.config_parser = config_parser self.config_parser = config_parser
@ -140,7 +144,10 @@ class JJBConfig(object):
""" """
config = configparser.ConfigParser() config = configparser.ConfigParser()
# Load default config always # Load default config always
config.readfp(StringIO(DEFAULT_CONF)) if PY2:
config.readfp(StringIO(DEFAULT_CONF))
else:
config.read_file(StringIO(DEFAULT_CONF))
return config return config
def _read_config_file(self, config_filename): def _read_config_file(self, config_filename):

@ -300,8 +300,8 @@ class DeprecatedTag(BaseYAMLObject):
@classmethod @classmethod
def from_yaml(cls, loader, node): def from_yaml(cls, loader, node):
logger.warn("tag '%s' is deprecated, switch to using '%s'", logger.warning("tag '%s' is deprecated, switch to using '%s'",
cls.yaml_tag, cls._new.yaml_tag) cls.yaml_tag, cls._new.yaml_tag)
return cls._new.from_yaml(loader, node) return cls._new.from_yaml(loader, node)

@ -2618,13 +2618,14 @@ def dsl(registry, xml_parent, data):
if 'target' in data: if 'target' in data:
if 'targets' not in data: if 'targets' not in data:
logger.warn("Converting from old format of 'target' to new " logger.warning("Converting from old format of 'target' to new "
"name 'targets', please update your job definitions.") "name 'targets', please update your job "
"definitions.")
data['targets'] = data['target'] data['targets'] = data['target']
else: else:
logger.warn("Ignoring old argument 'target' in favour of new " logger.warning("Ignoring old argument 'target' in favour of new "
"format argument 'targets', please remove old " "format argument 'targets', please remove old "
"format.") "format.")
if data.get('script-text'): if data.get('script-text'):
XML.SubElement(dsl, 'scriptText').text = data.get('script-text') XML.SubElement(dsl, 'scriptText').text = data.get('script-text')

@ -173,9 +173,9 @@ class General(jenkins_jobs.modules.base.Base):
if 'logrotate' in data: if 'logrotate' in data:
if not self.logrotate_warn_issued: if not self.logrotate_warn_issued:
logging.warn('logrotate is deprecated on jenkins>=1.637, use ' logging.warning('logrotate is deprecated on jenkins>=1.637,'
'the property build-discarder on newer jenkins ' ' the property build-discarder on newer'
'instead') ' jenkins instead')
self.logrotate_warn_issued = True self.logrotate_warn_issued = True
lr_xml = XML.SubElement(xml, 'logRotator') lr_xml = XML.SubElement(xml, 'logRotator')

@ -126,10 +126,10 @@ class HipChat(jenkins_jobs.modules.base.Base):
# convert for compatibility before dispatch # convert for compatibility before dispatch
if 'room' in hipchat: if 'room' in hipchat:
if 'rooms' in hipchat: if 'rooms' in hipchat:
logger.warn("Ignoring deprecated 'room' as 'rooms' also " logger.warning("Ignoring deprecated 'room' as 'rooms' also "
"defined.") "defined.")
else: else:
logger.warn("'room' is deprecated, please use 'rooms'") logger.warning("'room' is deprecated, please use 'rooms'")
hipchat['rooms'] = [hipchat['room']] hipchat['rooms'] = [hipchat['room']]
plugin_info = self.registry.get_plugin_info("Jenkins HipChat Plugin") plugin_info = self.registry.get_plugin_info("Jenkins HipChat Plugin")
@ -140,7 +140,7 @@ class HipChat(jenkins_jobs.modules.base.Base):
if publishers is None: if publishers is None:
publishers = XML.SubElement(xml_parent, 'publishers') publishers = XML.SubElement(xml_parent, 'publishers')
logger.warn( logger.warning(
"'hipchat' module supports the old plugin versions <1.9, " "'hipchat' module supports the old plugin versions <1.9, "
"newer versions are supported via the 'publishers' module. " "newer versions are supported via the 'publishers' module. "
"Please upgrade you job definition") "Please upgrade you job definition")
@ -160,8 +160,8 @@ class HipChat(jenkins_jobs.modules.base.Base):
# Handle backwards compatibility 'start-notify' but all add an element # Handle backwards compatibility 'start-notify' but all add an element
# of standardization with notify-* # of standardization with notify-*
if hipchat.get('start-notify'): if hipchat.get('start-notify'):
logger.warn("'start-notify' is deprecated, please use " logger.warning("'start-notify' is deprecated, please use "
"'notify-start'") "'notify-start'")
XML.SubElement(pdefhip, 'startNotification').text = str( XML.SubElement(pdefhip, 'startNotification').text = str(
hipchat.get('notify-start', hipchat.get('start-notify', hipchat.get('notify-start', hipchat.get('start-notify',
False))).lower() False))).lower()

@ -73,7 +73,7 @@ def archive(registry, xml_parent, data):
# backward compatibility # backward compatibility
latest_only = data.get('latest_only', False) latest_only = data.get('latest_only', False)
if 'latest_only' in data: if 'latest_only' in data:
logger.warn('latest_only is deprecated please use latest-only') logger.warning('latest_only is deprecated please use latest-only')
if 'latest-only' in data: if 'latest-only' in data:
latest_only = data['latest-only'] latest_only = data['latest-only']
if latest_only: if latest_only:
@ -464,7 +464,7 @@ def trigger_parameterized_builds(registry, xml_parent, data):
pass pass
if orig_order: if orig_order:
logger.warn( logger.warning(
"Using deprecated order for parameter sets in " "Using deprecated order for parameter sets in "
"triggered-parameterized-builds. This will be changed in a future " "triggered-parameterized-builds. This will be changed in a future "
"release to inherit the order from the user defined yaml. To " "release to inherit the order from the user defined yaml. To "
@ -493,7 +493,7 @@ def trigger_parameterized_builds(registry, xml_parent, data):
properties.text = param_value properties.text = param_value
elif param_type == 'git-revision' and param_value: elif param_type == 'git-revision' and param_value:
if 'combine-queued-commits' in project_def: if 'combine-queued-commits' in project_def:
logger.warn( logger.warning(
"'combine-queued-commit' has moved to reside under " "'combine-queued-commit' has moved to reside under "
"'git-revision' configuration, please update your " "'git-revision' configuration, please update your "
"configs as support for this will be removed." "configs as support for this will be removed."
@ -808,7 +808,7 @@ def coverage(registry, xml_parent, data):
:language: yaml :language: yaml
""" """
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.warn("Coverage function is deprecated. Switch to cobertura.") logger.warning("Coverage function is deprecated. Switch to cobertura.")
cobertura = XML.SubElement(xml_parent, cobertura = XML.SubElement(xml_parent,
'hudson.plugins.cobertura.CoberturaPublisher') 'hudson.plugins.cobertura.CoberturaPublisher')
@ -1301,8 +1301,8 @@ def xunit(registry, xml_parent, data):
for configured_type in data['types']: for configured_type in data['types']:
type_name = next(iter(configured_type.keys())) type_name = next(iter(configured_type.keys()))
if type_name not in implemented_types: if type_name not in implemented_types:
logger.warn("Requested xUnit type '%s' is not yet supported", logger.warning("Requested xUnit type '%s' is not yet supported",
type_name) type_name)
else: else:
# Append for generation # Append for generation
supported_types.append(configured_type) supported_types.append(configured_type)
@ -1329,7 +1329,7 @@ def xunit(registry, xml_parent, data):
xmlthresholds = XML.SubElement(xunit, 'thresholds') xmlthresholds = XML.SubElement(xunit, 'thresholds')
for t in data.get('thresholds', []): for t in data.get('thresholds', []):
if not ('failed' in t or 'skipped' in t): if not ('failed' in t or 'skipped' in t):
logger.warn( logger.warning(
"Unrecognized threshold, should be 'failed' or 'skipped'") "Unrecognized threshold, should be 'failed' or 'skipped'")
continue continue
elname = ("org.jenkinsci.plugins.xunit.threshold.%sThreshold" % elname = ("org.jenkinsci.plugins.xunit.threshold.%sThreshold" %
@ -2268,8 +2268,8 @@ def groovy_postbuild(registry, xml_parent, data):
logger = logging.getLogger("%s:groovy-postbuild" % __name__) logger = logging.getLogger("%s:groovy-postbuild" % __name__)
# Backward compatibility with old format # Backward compatibility with old format
if isinstance(data, six.string_types): if isinstance(data, six.string_types):
logger.warn( logger.warning(
"You use deprecated configuration, please follow documentation " "You use depricated configuration, please follow documentation "
"to change configuration. It is not going to be supported in " "to change configuration. It is not going to be supported in "
"future releases!" "future releases!"
) )
@ -4318,12 +4318,12 @@ def doxygen(registry, xml_parent, data):
if 'keep-all' in data: if 'keep-all' in data:
XML.SubElement(p, 'keepAll').text = str( XML.SubElement(p, 'keepAll').text = str(
data.get('keep-all', False)).lower() data.get('keep-all', False)).lower()
logger.warn("The value of 'keepall' will be ignored " logger.warning("The value of 'keepall' will be ignored "
"in preference to 'keep-all'.") "in preference to 'keep-all'.")
else: else:
XML.SubElement(p, 'keepAll').text = str( XML.SubElement(p, 'keepAll').text = str(
data.get('keepall', False)).lower() data.get('keepall', False)).lower()
logger.warn("'keepall' is deprecated please use 'keep-all'") logger.warning("'keepall' is deprecated please use 'keep-all'")
else: else:
XML.SubElement(p, 'keepAll').text = str( XML.SubElement(p, 'keepAll').text = str(
data.get('keep-all', False)).lower() data.get('keep-all', False)).lower()
@ -6222,7 +6222,7 @@ def slack(registry, xml_parent, data):
for yaml_name, _, _ in mapping_20: for yaml_name, _, _ in mapping_20:
if yaml_name in data: if yaml_name in data:
logger.warn( logger.warning(
"'%s' is invalid with plugin version < 2.0, ignored", "'%s' is invalid with plugin version < 2.0, ignored",
yaml_name, yaml_name,
) )

@ -264,10 +264,11 @@ def git(registry, xml_parent, data):
submodule_cfgs = ['disable-submodules', 'recursive-submodules'] submodule_cfgs = ['disable-submodules', 'recursive-submodules']
if optname in submodule_cfgs: if optname in submodule_cfgs:
if optname in data: if optname in data:
logger.warn("'{0}' is deprecated, please convert to use the " logger.warning(
"'submodule' section instead as support for this " "'{0}' is deprecated, please convert to use the "
"top level option will be removed in a future " "'submodule' section instead as support for this "
"release.".format(optname)) "top level option will be removed in a future "
"release.".format(optname))
if 'submodule' in data: if 'submodule' in data:
continue continue
@ -312,9 +313,10 @@ def git(registry, xml_parent, data):
if isinstance(data['clean'], bool): if isinstance(data['clean'], bool):
clean_after = data['clean'] clean_after = data['clean']
clean_before = False clean_before = False
logger.warn("'clean: bool' configuration format is deprecated, " logger.warning(
"please use the extension style format to configure " "'clean: bool' configuration format is deprecated, "
"this option.") "please use the extension style format to configure "
"this option.")
else: else:
clean_after = data['clean'].get('after', False) clean_after = data['clean'].get('after', False)
clean_before = data['clean'].get('before', False) clean_before = data['clean'].get('before', False)

@ -59,8 +59,9 @@ def gerrit_handle_legacy_configuration(data):
for old_key in old_keys: for old_key in old_keys:
if old_key in d: if old_key in d:
new_key = hyphenize(old_key) new_key = hyphenize(old_key)
logger.warn("'%s' is deprecated and will be removed after " logger.warning(
"1.0.0, please use '%s' instead", old_key, new_key) "'%s' is deprecated and will be removed after "
"1.0.0, please use '%s' instead", old_key, new_key)
d[new_key] = d[old_key] d[new_key] = d[old_key]
del d[old_key] del d[old_key]
@ -96,9 +97,10 @@ def gerrit_handle_legacy_configuration(data):
if key.startswith('trigger-on-')) if key.startswith('trigger-on-'))
trigger_on = data.setdefault('trigger-on', []) trigger_on = data.setdefault('trigger-on', [])
if old_format_events: if old_format_events:
logger.warn("The events: %s; which you used is/are deprecated. " logger.warning(
"Please use 'trigger-on' instead.", "The events: %s; which you used is/are deprecated. "
', '.join(old_format_events)) "Please use 'trigger-on' instead.",
', '.join(old_format_events))
if old_format_events and trigger_on: if old_format_events and trigger_on:
raise JenkinsJobsException( raise JenkinsJobsException(
@ -145,8 +147,9 @@ def build_gerrit_triggers(xml_parent, data):
if isinstance(event, six.string_types): if isinstance(event, six.string_types):
tag_name = available_simple_triggers.get(event) tag_name = available_simple_triggers.get(event)
if event == 'patchset-uploaded-event': if event == 'patchset-uploaded-event':
logger.warn("'%s' is deprecated. Use 'patchset-created-event' " logger.warning(
"format instead.", event) "'%s' is deprecated. Use 'patchset-created-event' "
"format instead.", event)
if not tag_name: if not tag_name:
known = ', '.join(available_simple_triggers.keys() known = ', '.join(available_simple_triggers.keys()
@ -489,7 +492,7 @@ def gerrit(registry, xml_parent, data):
'branches section' 'branches section'
else: else:
warning += 'please use branches section instead' warning += 'please use branches section instead'
logger.warn(warning) logger.warning(warning)
if not project_branches: if not project_branches:
project_branches = [ project_branches = [
{'branch-compare-type': project.get( {'branch-compare-type': project.get(
@ -644,9 +647,10 @@ def pollscm(registry, xml_parent, data):
raise MissingAttributeError(e) raise MissingAttributeError(e)
except TypeError: except TypeError:
# To keep backward compatibility # To keep backward compatibility
logger.warn("Your pollscm usage is deprecated, please use" logger.warning(
" the syntax described in the documentation" "Your pollscm usage is deprecated, please use"
" instead") " the syntax described in the documentation"
" instead")
cron = data cron = data
ipch = 'false' ipch = 'false'

@ -831,8 +831,9 @@ def port_allocator(registry, xml_parent, data):
names = data.get('names') names = data.get('names')
if not names: if not names:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.warn('port_allocator name is deprecated, use a names list ' logger.warning(
' instead') 'port_allocator name is deprecated, use a names list '
' instead')
names = [data['name']] names = [data['name']]
for name in names: for name in names:
dpt = XML.SubElement(ports, dpt = XML.SubElement(ports,
@ -1642,12 +1643,13 @@ def ssh_agent_credentials(registry, xml_parent, data):
entry_xml = XML.SubElement(entry_xml, 'credentialIds') entry_xml = XML.SubElement(entry_xml, 'credentialIds')
xml_key = 'string' xml_key = 'string'
if 'user' in data: if 'user' in data:
logger.warn("Both 'users' and 'user' parameters specified for " logger.warning(
"ssh-agent-credentials. 'users' is used, 'user' is " "Both 'users' and 'user' parameters specified for "
"ignored.") "ssh-agent-credentials. 'users' is used, 'user' is "
"ignored.")
elif 'user' in data: elif 'user' in data:
logger.warn("The 'user' param has been deprecated, " logger.warning("The 'user' param has been deprecated, "
"use the 'users' param instead.") "use the 'users' param instead.")
user_list.append(data['user']) user_list.append(data['user'])
else: else:
raise JenkinsJobsException("Missing 'user' or 'users' parameter " raise JenkinsJobsException("Missing 'user' or 'users' parameter "

@ -167,7 +167,7 @@ class YamlParser(object):
logger.error(message) logger.error(message)
raise JenkinsJobsException(message) raise JenkinsJobsException(message)
else: else:
logger.warn(message) logger.warning(message)
def _getJob(self, name): def _getJob(self, name):
job = self.data.get('job', {}).get(name, None) job = self.data.get('job', {}).get(name, None)

@ -228,11 +228,11 @@ class ModuleRegistry(object):
component = self.parser_data.get(component_type, {}).get(name) component = self.parser_data.get(component_type, {}).get(name)
if component: if component:
if name in eps and name not in self.masked_warned: if name in eps and name not in self.masked_warned:
# Warn only once for each macro
self.masked_warned[name] = True self.masked_warned[name] = True
logger.warn("You have a macro ('%s') defined for '%s' " logger.warning(
"component type that is masking an inbuilt " "You have a macro ('%s') defined for '%s' "
"definition" % (name, component_type)) "component type that is masking an inbuilt "
"definition" % (name, component_type))
for b in component[component_list_type]: for b in component[component_list_type]:
# Pass component_data in as template data to this function # Pass component_data in as template data to this function