Merge pull request #241 from rackerlabs/stable_delete_end_drop_no_launched_at

Push delete.end with blank launched_at fix to Stable
This commit is contained in:
Andrew Melton 2013-10-30 13:20:28 -07:00
commit ab6e24806f
2 changed files with 15 additions and 27 deletions

View File

@ -228,21 +228,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):

View File

@ -784,7 +784,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()
@ -798,27 +799,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 test_process_exists(self):