Added warning when invalid payload is encountered while saving exists notification

This commit is contained in:
Anuj Mathur 2013-09-19 11:33:41 +05:30
parent 0e21b29a03
commit 5d65e5bad7
2 changed files with 23 additions and 1 deletions

View File

@ -159,6 +159,8 @@ class GlanceNotification(Notification):
utils.str_time_to_unix(audit_period_ending)
images = self.payload.get('images', [])
else:
stacklog.warn("Received exists with invalid payload "
"GlanceRawData(%s)" % raw.id)
audit_period_beginning = None
audit_period_ending = None
images = []
@ -169,8 +171,8 @@ class GlanceNotification(Notification):
uuid = image['id']
deleted_at = image['deleted_at']
deleted_at = deleted_at and utils.str_time_to_unix(deleted_at)
if created_at:
if created_at:
values = {
'uuid': uuid,
'audit_period_beginning': audit_period_beginning,

View File

@ -675,3 +675,23 @@ class GlanceExistsNotificationTestCase(StacktachBaseTestCase):
json_body)
notification.save_exists(raw)
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()