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.
This commit is contained in:
parent
0974e4553a
commit
5cb5391e2d
@ -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):
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user