From bcc22b8d84e3560453724b00cb7f938479c44a0b Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Wed, 12 Jun 2024 08:03:04 -0500 Subject: [PATCH] Added check for SubjectAltNameWarning exception in distributed_cleanup.py If urllib3 is v2.0 and greater then errors are produced when no subjectAltName is in the certificate. For less than v2.0 we want to silence the SubjectAltNameWarning exception. Ticket: ENT-11875 Changelog: none (cherry picked from commit f6d21787b57ce831b59a36a4d9b9fa245caa8b1d) --- templates/federated_reporting/nova_api.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/templates/federated_reporting/nova_api.py b/templates/federated_reporting/nova_api.py index 6725f86ecf..cec6349324 100755 --- a/templates/federated_reporting/nova_api.py +++ b/templates/federated_reporting/nova_api.py @@ -69,13 +69,15 @@ def __init__( basic_auth="{}:{}".format(self._api_user, self._api_password) ) self._headers["Content-Type"] = "application/json" - # In order to avoid SubjectAltNameWarning with our self-signed certs, silence it - if not sys.warnoptions: - import warnings - - warnings.simplefilter( - "ignore", category=urllib3.exceptions.SubjectAltNameWarning - ) + # urllib3 v2.0 removed SubjectAltNameWarning and instead throws an error if no SubjectAltName is present in a certificate + if hasattr(urllib3.exceptions, "SubjectAltNameWarning"): + # if urllib3 is < v2.0 then SubjectAltNameWarning will exist and should be silenced + if not sys.warnoptions: + import warnings + + warnings.simplefilter( + "ignore", category=urllib3.exceptions.SubjectAltNameWarning + ) def __str__(self): return str(self.__class__) + ":" + str(self.__dict__)