From 1bb26160e77cd18d24b9f4ae151a0c8f50a96c18 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 22 2018 08:34:21 +0000 Subject: [PATCH 1/2] Remove deprecation warnings for call to self.warn Signed-off-by: Chenxiong Qi --- diff --git a/freshmaker/auth.py b/freshmaker/auth.py index fce0206..997af60 100644 --- a/freshmaker/auth.py +++ b/freshmaker/auth.py @@ -185,7 +185,7 @@ def init_auth(login_manager, backend): if backend == 'noauth': # Do not enable any authentication backend working with frontend # authentication module in Apache. - log.warn("Authorization is disabled in Freshmaker configuration.") + log.warning("Authorization is disabled in Freshmaker configuration.") return if backend == 'kerberos': _validate_kerberos_config() diff --git a/freshmaker/bugzilla.py b/freshmaker/bugzilla.py index 3e3e739..c21ef2f 100644 --- a/freshmaker/bugzilla.py +++ b/freshmaker/bugzilla.py @@ -99,13 +99,13 @@ class BugzillaAPI(object): data = self._get_cve_whiteboard(cve) except requests.exceptions.HTTPError as e: if e.response.status_code == 404: - log.warn( + log.warning( "CVE %s cannot be found in bugzilla, " "threat_severity unknown. %s", cve, e.response.request.url) continue raise except IndexError: - log.warn( + log.warning( "CVE %s XML appears malformed. No children? " "threat_severity unknown.", cve) continue @@ -113,7 +113,7 @@ class BugzillaAPI(object): try: severity = data["impact"].lower() except KeyError: - log.warn( + log.warning( "CVE %s has no 'impact' in bugzilla whiteboard, " "threat_severity unknown.", cve) continue diff --git a/freshmaker/handlers/__init__.py b/freshmaker/handlers/__init__.py index 6672983..ebdd1db 100644 --- a/freshmaker/handlers/__init__.py +++ b/freshmaker/handlers/__init__.py @@ -131,7 +131,7 @@ class BaseHandler(object): Logs the message `msg` using `log_fnc`, passing msg, *args and **kwargs to it. - :param log_fnc: log.info, log.error, log.warn, ... + :param log_fnc: log.info, log.error, log.warning, ... :param str msg: Message to log (first argument passed to log_fnc). :param *args: Args passed to log_fnc. :param **kwargs: Kwargs passed to log_fnc. @@ -150,11 +150,11 @@ class BaseHandler(object): """ return self._log(log.info, msg, *args, **kwargs) - def log_warn(self, msg, *args, **kwargs): + def log_warning(self, msg, *args, **kwargs): """ - Wraps log.warn, prefixes the message with a context of this handler. + Wraps log.warning, prefixes the message with a context of this handler. """ - return self._log(log.warn, msg, *args, **kwargs) + return self._log(log.warning, msg, *args, **kwargs) def log_error(self, msg, *args, **kwargs): """ diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py index e4000a8..2f4a85e 100644 --- a/freshmaker/lightblue.py +++ b/freshmaker/lightblue.py @@ -352,7 +352,7 @@ class ContainerImage(dict): "content_sets": []} if not repository or not branch or not commit: - log.warn("%s: Cannot get additional data from distgit.", nvr) + log.warning("%s: Cannot get additional data from distgit.", nvr) return data if "/" in repository: namespace, name = repository.split("/") @@ -593,7 +593,7 @@ class LightBlue(object): return # Warn early, in case there is an error in the error handling code below - log.warn("Request to %s gave %r" % (response.request.url, response)) + log.warning("Request to %s gave %r" % (response.request.url, response)) if status_code in (http_client.NOT_FOUND, http_client.INTERNAL_SERVER_ERROR, diff --git a/freshmaker/logger.py b/freshmaker/logger.py index 552f068..e5ec380 100644 --- a/freshmaker/logger.py +++ b/freshmaker/logger.py @@ -37,7 +37,7 @@ import logging logging.debug("Phasers are set to stun.") logging.info("%s tried to build something", username) -logging.warn("%s failed to build", task_id) +logging.warning("%s failed to build", task_id) """ diff --git a/freshmaker/messaging.py b/freshmaker/messaging.py index e4d2860..83c8b9e 100644 --- a/freshmaker/messaging.py +++ b/freshmaker/messaging.py @@ -107,12 +107,12 @@ def _in_memory_publish(topic, msg): try: work_queue_put(wrapped_msg) except ValueError as e: - log.warn("No FreshmakerConsumer found. Shutting down? %r" % e) + log.warning("No FreshmakerConsumer found. Shutting down? %r" % e) except AttributeError: # In the event that `moksha.hub._hub` hasn't yet been initialized, we # need to store messages on the side until it becomes available. # As a last-ditch effort, try to hang initial messages in the config. - log.warn("Hub not initialized. Queueing on the side.") + log.warning("Hub not initialized. Queueing on the side.") _initial_messages.append(wrapped_msg) diff --git a/freshmaker/utils.py b/freshmaker/utils.py index a1218ce..8a4c67d 100644 --- a/freshmaker/utils.py +++ b/freshmaker/utils.py @@ -85,9 +85,9 @@ def get_url_for(*args, **kwargs): # system as the web views. app.config['SERVER_NAME'] = 'localhost' with app.app_context(): - log.warn("get_url_for() has been called without the Flask " - "app_context. That can lead to SQLAlchemy errors caused by " - "multiple session being used in the same time.") + log.warning("get_url_for() has been called without the Flask " + "app_context. That can lead to SQLAlchemy errors caused by " + "multiple session being used in the same time.") return url_for(*args, **kwargs) @@ -161,8 +161,8 @@ def retry(timeout=conf.net_timeout, interval=conf.net_retry_interval, wait_on=Ex return function(*args, **kwargs) except wait_on as e: if logger is not None: - logger.warn("Exception %r raised from %r. Retry in %rs", - e, function, interval) + logger.warning("Exception %r raised from %r. Retry in %rs", + e, function, interval) time.sleep(interval) return inner return wrapper @@ -192,7 +192,7 @@ def temp_dir(logger=None, *args, **kwargs): except OSError as exc: # Okay, we failed to delete temporary dir. if logger: - logger.warn('Error removing %s: %s', dir, exc.strerror) + logger.warning('Error removing %s: %s', dir, exc.strerror) def clone_repo(url, dest, branch='master', logger=None, commit=None): From 5dfa48ecf39b49f09a6ee5063474308961029a5a Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 22 2018 08:34:21 +0000 Subject: [PATCH 2/2] Fix deprecation warnings for call to test assertions Signed-off-by: Chenxiong Qi --- diff --git a/tests/test_brew_container_task_state_change_handler.py b/tests/test_brew_container_task_state_change_handler.py index e9f5f16..b378f9a 100644 --- a/tests/test_brew_container_task_state_change_handler.py +++ b/tests/test_brew_container_task_state_change_handler.py @@ -22,6 +22,7 @@ import json import mock import os +import six import sys import unittest @@ -259,7 +260,7 @@ class TestBrewContainerTaskStateChangeHandler(helpers.ModelsTestCase): self.handler.handle(event) self.assertEqual(build.state, ArtifactBuildState.FAILED.value) - self.assertRegexpMatches(build.state_reason, r"The following RPMs in container build.*") + six.assertRegex(self, build.state_reason, r"The following RPMs in container build.*") if __name__ == '__main__': diff --git a/tests/test_errata_advisory_state_changed.py b/tests/test_errata_advisory_state_changed.py index 04b3fe0..88cfe8c 100644 --- a/tests/test_errata_advisory_state_changed.py +++ b/tests/test_errata_advisory_state_changed.py @@ -22,6 +22,7 @@ # Written by Chenxiong Qi import json +import six from mock import patch, PropertyMock, Mock, call @@ -57,7 +58,8 @@ class TestFindBuildSrpmName(helpers.FreshmakerTestCase): handler = ErrataAdvisoryRPMsSignedHandler() - self.assertRaisesRegexp( + six.assertRaisesRegex( + self, ValueError, 'Build bind-dyndb-ldap-2.3-8.el6 does not have a SRPM', handler._find_build_srpm_name,