From 53ad2105a960805021604dd355b30cd4bddd41c4 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Fri, 22 Apr 2016 16:48:56 +0200 Subject: [PATCH] disable urllib3 warnings only if the library provide them SNIMissingWarning was introduced in urllib3 in 1.13. When using rally with an older version of urllib3 (f.e. as used in liberty, urllib3>=1.8.3), the SNIMissingWarning may be not present, in which case the code will crash with AttributeError. So first check whether the warning is known to the urllib3 library being used with rally before trying to disable it. Change-Id: Idcdc7b43a032212064c4ed2e1a69b67656bf801c Closes-Bug: #1573650 --- rally/cli/cliutils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rally/cli/cliutils.py b/rally/cli/cliutils.py index af364fff14..65f642dd49 100644 --- a/rally/cli/cliutils.py +++ b/rally/cli/cliutils.py @@ -504,10 +504,12 @@ def run(argv, categories): urllib3_log.setLevel(logging.WARNING) LOG.debug("urllib3 insecure warnings are hidden.") - urllib3.disable_warnings( - urllib3.exceptions.InsecurePlatformWarning) - urllib3.disable_warnings(urllib3.exceptions.SNIMissingWarning) - urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + for warning in ("InsecurePlatformWarning", + "SNIMissingWarning", + "InsecureRequestWarning"): + warning_cls = getattr(urllib3.exceptions, warning, None) + if warning_cls is not None: + urllib3.disable_warnings(warning_cls) # NOTE(wtakase): This is for suppressing boto error logging. LOG.debug("ERROR log from boto module is hide.")