Added warning when invalid payload is encountered while saving exists notification
This commit is contained in:
@@ -159,6 +159,8 @@ class GlanceNotification(Notification):
|
|||||||
utils.str_time_to_unix(audit_period_ending)
|
utils.str_time_to_unix(audit_period_ending)
|
||||||
images = self.payload.get('images', [])
|
images = self.payload.get('images', [])
|
||||||
else:
|
else:
|
||||||
|
stacklog.warn("Received exists with invalid payload "
|
||||||
|
"GlanceRawData(%s)" % raw.id)
|
||||||
audit_period_beginning = None
|
audit_period_beginning = None
|
||||||
audit_period_ending = None
|
audit_period_ending = None
|
||||||
images = []
|
images = []
|
||||||
@@ -169,8 +171,8 @@ class GlanceNotification(Notification):
|
|||||||
uuid = image['id']
|
uuid = image['id']
|
||||||
deleted_at = image['deleted_at']
|
deleted_at = image['deleted_at']
|
||||||
deleted_at = deleted_at and utils.str_time_to_unix(deleted_at)
|
deleted_at = deleted_at and utils.str_time_to_unix(deleted_at)
|
||||||
if created_at:
|
|
||||||
|
|
||||||
|
if created_at:
|
||||||
values = {
|
values = {
|
||||||
'uuid': uuid,
|
'uuid': uuid,
|
||||||
'audit_period_beginning': audit_period_beginning,
|
'audit_period_beginning': audit_period_beginning,
|
||||||
|
@@ -675,3 +675,23 @@ class GlanceExistsNotificationTestCase(StacktachBaseTestCase):
|
|||||||
json_body)
|
json_body)
|
||||||
notification.save_exists(raw)
|
notification.save_exists(raw)
|
||||||
self.mox.VerifyAll()
|
self.mox.VerifyAll()
|
||||||
|
|
||||||
|
def test_save_exists_should_log_warning_when_payload_is_invalid(self):
|
||||||
|
raw = self.mox.CreateMockAnything()
|
||||||
|
raw.id = 1
|
||||||
|
body = {
|
||||||
|
"event_type": "image.exists",
|
||||||
|
"publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
|
||||||
|
"payload": []
|
||||||
|
}
|
||||||
|
deployment = "1"
|
||||||
|
routing_key = "glance_monitor.info"
|
||||||
|
json_body = json.dumps([routing_key, body])
|
||||||
|
self.mox.StubOutWithMock(stacklog, 'warn')
|
||||||
|
stacklog.warn("Received exists with invalid payload GlanceRawData(1)")
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
notification = GlanceNotification(body, deployment, routing_key,
|
||||||
|
json_body)
|
||||||
|
notification.save_exists(raw)
|
||||||
|
self.mox.VerifyAll()
|
||||||
|
Reference in New Issue
Block a user