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
This commit is contained in:
Ihar Hrachyshka 2016-04-22 16:48:56 +02:00
parent 07b4a0dfed
commit 53ad2105a9
1 changed files with 6 additions and 4 deletions

View File

@ -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.")