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):
|
def _process_delete(raw, notification):
|
||||||
instance_id = notification.instance
|
if notification.launched_at and notification.launched_at != '':
|
||||||
deleted_at = utils.str_time_to_unix(notification.deleted_at)
|
instance_id = notification.instance
|
||||||
values = {
|
deleted_at = utils.str_time_to_unix(notification.deleted_at)
|
||||||
'instance': instance_id,
|
launched_at = utils.str_time_to_unix(notification.launched_at)
|
||||||
'deleted_at': deleted_at,
|
values = {
|
||||||
}
|
'instance': instance_id,
|
||||||
(delete, new) = STACKDB.get_or_create_instance_delete(**values)
|
'deleted_at': deleted_at,
|
||||||
delete.raw = raw
|
'launched_at': launched_at
|
||||||
|
}
|
||||||
|
(delete, new) = STACKDB.get_or_create_instance_delete(**values)
|
||||||
|
delete.raw = raw
|
||||||
|
|
||||||
launched_at = notification.launched_at
|
STACKDB.save(delete)
|
||||||
if launched_at and launched_at != '':
|
|
||||||
launched_at = utils.str_time_to_unix(launched_at)
|
|
||||||
delete.launched_at = launched_at
|
|
||||||
|
|
||||||
STACKDB.save(delete)
|
|
||||||
|
|
||||||
|
|
||||||
def _process_exists(raw, notification):
|
def _process_exists(raw, notification):
|
||||||
|
@ -677,7 +677,8 @@ class StacktachUsageParsingTestCase(StacktachBaseTestCase):
|
|||||||
delete.launched_at = launch_decimal
|
delete.launched_at = launch_decimal
|
||||||
delete.deleted_at = delete_decimal
|
delete.deleted_at = delete_decimal
|
||||||
views.STACKDB.get_or_create_instance_delete(
|
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))
|
.AndReturn((delete, True))
|
||||||
views.STACKDB.save(delete)
|
views.STACKDB.save(delete)
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
@ -691,27 +692,16 @@ class StacktachUsageParsingTestCase(StacktachBaseTestCase):
|
|||||||
|
|
||||||
def test_process_delete_no_launch(self):
|
def test_process_delete_no_launch(self):
|
||||||
delete_time = datetime.datetime.utcnow()
|
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 = self.mox.CreateMockAnything()
|
||||||
notification.instance = INSTANCE_ID_1
|
notification.instance = INSTANCE_ID_1
|
||||||
notification.deleted_at = str(delete_time)
|
notification.deleted_at = str(delete_time)
|
||||||
notification.launched_at = str(launch_time)
|
notification.launched_at = ''
|
||||||
|
|
||||||
raw = self.mox.CreateMockAnything()
|
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()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
views._process_delete(raw, notification)
|
views._process_delete(raw, notification)
|
||||||
|
|
||||||
self.assertEqual(delete.instance, INSTANCE_ID_1)
|
|
||||||
self.assertEqual(delete.deleted_at, delete_decimal)
|
|
||||||
self.mox.VerifyAll()
|
self.mox.VerifyAll()
|
||||||
|
|
||||||
def _create_exists_notification(self, audit_beginning, current_time,
|
def _create_exists_notification(self, audit_beginning, current_time,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user