Use status_code instead of http_status
In exceptions.HttpException has no attribute 'http_status'. Use status_code instead of http_status.In future, 'http_status' parameter will be removed. For UT, use response object instead of http_status. Change-Id: Id0e3ae5377ea713cf2394975c827605dbc860143 Signed-off-by: Sampath Priyankara <sam47priya@gmail.com>
This commit is contained in:
parent
a88eb502f0
commit
41653bc953
|
@ -95,8 +95,16 @@ class SendNotification(object):
|
|||
|
||||
except Exception as e:
|
||||
if isinstance(e, exceptions.HttpException):
|
||||
# If http_status is 409, skip the retry processing.
|
||||
if e.http_status == 409:
|
||||
|
||||
# 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:
|
||||
msg = ("Stop retrying to send a notification because "
|
||||
"same notification have been already sent.")
|
||||
LOG.info("%s", msg)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import mock
|
||||
import testtools
|
||||
import uuid
|
||||
|
||||
import eventlet
|
||||
from openstack import connection
|
||||
|
@ -29,6 +30,16 @@ PROFILE_TYPE = "ha"
|
|||
PROFILE_NAME = "masakari"
|
||||
|
||||
|
||||
class FakeResponse(object):
|
||||
|
||||
def __init__(self, status_code=200, headers=None):
|
||||
self.status_code = status_code
|
||||
self.headers = {
|
||||
'content-type': 'application/json',
|
||||
'x-openstack-request-id': uuid.uuid4().hex,
|
||||
}
|
||||
|
||||
|
||||
class TestSendNotification(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -98,9 +109,17 @@ class TestSendNotification(testtools.TestCase):
|
|||
mock_Profile.return_value = mock_prof
|
||||
mock_conn = mock.Mock()
|
||||
mock_Connection.return_value = mock_conn
|
||||
mock_conn.ha.create_notification.side_effect = \
|
||||
exceptions.HttpException(http_status=409)
|
||||
|
||||
# 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)
|
||||
|
||||
mock_conn.ha.create_notification.side_effect = status_ex
|
||||
notifier = masakari.SendNotification()
|
||||
notifier.send_notification(
|
||||
self.api_retry_max, self.api_retry_interval, self.event)
|
||||
|
@ -142,8 +161,17 @@ class TestSendNotification(testtools.TestCase):
|
|||
mock_Profile.return_value = mock_prof
|
||||
mock_conn = mock.Mock()
|
||||
mock_Connection.return_value = mock_conn
|
||||
mock_conn.ha.create_notification.side_effect = \
|
||||
exceptions.HttpException(http_status=500)
|
||||
|
||||
# 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)
|
||||
|
||||
mock_conn.ha.create_notification.side_effect = status_ex
|
||||
mock_sleep.return_value = None
|
||||
|
||||
notifier = masakari.SendNotification()
|
||||
|
|
Loading…
Reference in New Issue