From fe4e09408ca57b55925dd4469c18518bcb0251cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Piliszek?= Date: Wed, 28 Jul 2021 19:40:06 +0000 Subject: [PATCH] Remove conditionals for an ancient openstacksdk Change-Id: I4b035925b212236e5a31cd3752d08d281501c26d --- masakarimonitors/ha/masakari.py | 11 +--------- .../tests/unit/ha/test_masakari.py | 20 ++++--------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/masakarimonitors/ha/masakari.py b/masakarimonitors/ha/masakari.py index 509580c..0c65b44 100644 --- a/masakarimonitors/ha/masakari.py +++ b/masakarimonitors/ha/masakari.py @@ -68,16 +68,7 @@ class SendNotification(object): except Exception as e: if isinstance(e, exceptions.HttpException): - - # TODO(samP): Remove attribute check and else case if - # openstacksdk is bumped up from '>=0.9.19' to '>=0.10.0' - # in global-requirements. - if hasattr(e, 'status_code'): - is_status_409 = e.status_code == 409 - else: - is_status_409 = e.http_status == 409 - - if is_status_409: + if e.status_code == 409: msg = ("Stop retrying to send a notification because " "same notification have been already sent.") LOG.info("%s", msg) diff --git a/masakarimonitors/tests/unit/ha/test_masakari.py b/masakarimonitors/tests/unit/ha/test_masakari.py index bb37670..7d33335 100644 --- a/masakarimonitors/tests/unit/ha/test_masakari.py +++ b/masakarimonitors/tests/unit/ha/test_masakari.py @@ -97,14 +97,8 @@ class TestSendNotification(testtools.TestCase): mock_conn.instance_ha.create_notification.return_value = mock.Mock() mock_connection.return_value = mock_conn - # TODO(samP): Remove attribute check and else case if - # openstacksdk is bumped up from '>=0.9.19' to '>=0.10.0' - # in global-requirements. - if hasattr(exceptions.HttpException(), 'status_code'): - response = FakeResponse(status_code=409) - status_ex = exceptions.HttpException(response=response) - else: - status_ex = exceptions.HttpException(http_status=409) + response = FakeResponse(status_code=409) + status_ex = exceptions.HttpException(response=response) mock_conn.instance_ha.create_notification.side_effect = status_ex notifier = masakari.SendNotification() @@ -129,14 +123,8 @@ class TestSendNotification(testtools.TestCase): mock_conn.instance_ha.create_notification.return_value = mock.Mock() mock_connection.return_value = mock_conn - # TODO(samP): Remove attribute check and else case if - # openstacksdk is bumped up from '>=0.9.19' to '>=0.10.0' - # in global-requirements. - if hasattr(exceptions.HttpException(), 'status_code'): - response = FakeResponse(status_code=500) - status_ex = exceptions.HttpException(response=response) - else: - status_ex = exceptions.HttpException(http_status=500) + response = FakeResponse(status_code=500) + status_ex = exceptions.HttpException(response=response) mock_conn.instance_ha.create_notification.side_effect = status_ex mock_sleep.return_value = None