From 5cb5391e2d3804950e2d630f9e2d173af6d22171 Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Wed, 30 Oct 2013 15:12:08 -0400 Subject: [PATCH] Drop delete.end notifications with blank launched_at We can safely drop delete.end notifications without values for launched_at because these instances never got launched. Thus, we'd never expect any usage for them. --- stacktach/views.py | 26 ++++++++++++-------------- tests/unit/test_stacktach.py | 16 +++------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/stacktach/views.py b/stacktach/views.py index 58963d4..f3dacef 100644 --- a/stacktach/views.py +++ b/stacktach/views.py @@ -231,21 +231,19 @@ def _process_usage_for_updates(raw, notification): def _process_delete(raw, notification): - instance_id = notification.instance - deleted_at = utils.str_time_to_unix(notification.deleted_at) - values = { - 'instance': instance_id, - 'deleted_at': deleted_at, - } - (delete, new) = STACKDB.get_or_create_instance_delete(**values) - delete.raw = raw + if notification.launched_at and notification.launched_at != '': + instance_id = notification.instance + deleted_at = utils.str_time_to_unix(notification.deleted_at) + launched_at = utils.str_time_to_unix(notification.launched_at) + values = { + 'instance': instance_id, + 'deleted_at': deleted_at, + 'launched_at': launched_at + } + (delete, new) = STACKDB.get_or_create_instance_delete(**values) + delete.raw = raw - launched_at = notification.launched_at - if launched_at and launched_at != '': - launched_at = utils.str_time_to_unix(launched_at) - delete.launched_at = launched_at - - STACKDB.save(delete) + STACKDB.save(delete) def _process_exists(raw, notification): diff --git a/tests/unit/test_stacktach.py b/tests/unit/test_stacktach.py index bbe8e16..f823b63 100644 --- a/tests/unit/test_stacktach.py +++ b/tests/unit/test_stacktach.py @@ -677,7 +677,8 @@ class StacktachUsageParsingTestCase(StacktachBaseTestCase): delete.launched_at = launch_decimal delete.deleted_at = delete_decimal views.STACKDB.get_or_create_instance_delete( - instance=INSTANCE_ID_1, deleted_at=delete_decimal)\ + instance=INSTANCE_ID_1, deleted_at=delete_decimal, + launched_at=launch_decimal)\ .AndReturn((delete, True)) views.STACKDB.save(delete) self.mox.ReplayAll() @@ -691,27 +692,16 @@ class StacktachUsageParsingTestCase(StacktachBaseTestCase): def test_process_delete_no_launch(self): delete_time = datetime.datetime.utcnow() - launch_time = delete_time-datetime.timedelta(days=1) - delete_decimal = utils.decimal_utc(delete_time) notification = self.mox.CreateMockAnything() notification.instance = INSTANCE_ID_1 notification.deleted_at = str(delete_time) - notification.launched_at = str(launch_time) + notification.launched_at = '' raw = self.mox.CreateMockAnything() - delete = self.mox.CreateMockAnything() - delete.instance = INSTANCE_ID_1 - delete.deleted_at = delete_decimal - views.STACKDB.get_or_create_instance_delete( - instance=INSTANCE_ID_1, deleted_at=delete_decimal)\ - .AndReturn((delete, True)) - views.STACKDB.save(delete) self.mox.ReplayAll() views._process_delete(raw, notification) - self.assertEqual(delete.instance, INSTANCE_ID_1) - self.assertEqual(delete.deleted_at, delete_decimal) self.mox.VerifyAll() def _create_exists_notification(self, audit_beginning, current_time,