Merge pull request #254 from rackerlabs/stable_deleted_at_fix

Pushing work around for blank deleted_ats to stable
This commit is contained in:
Andrew Melton 2013-11-22 07:45:56 -08:00
commit a1813f18d6
3 changed files with 68 additions and 1 deletions

View File

@ -234,6 +234,7 @@ class NovaNotification(Notification):
self.payload.get('new_instance_type_id', None)
self.launched_at = self.payload.get('launched_at', None)
self.deleted_at = self.payload.get('deleted_at', None)
self.terminated_at = self.payload.get('terminated_at', None)
self.audit_period_beginning = self.payload.get(
'audit_period_beginning', None)
self.audit_period_ending = self.payload.get(

View File

@ -242,7 +242,11 @@ def _process_usage_for_updates(raw, notification):
def _process_delete(raw, notification):
if notification.launched_at and notification.launched_at != '':
instance_id = notification.instance
deleted_at = utils.str_time_to_unix(notification.deleted_at)
deleted_at = None
if notification.deleted_at:
deleted_at = utils.str_time_to_unix(notification.deleted_at)
elif notification.terminated_at:
deleted_at = utils.str_time_to_unix(notification.terminated_at)
launched_at = utils.str_time_to_unix(notification.launched_at)
values = {
'instance': instance_id,

View File

@ -665,12 +665,74 @@ class StacktachUsageParsingTestCase(StacktachBaseTestCase):
def test_process_delete(self):
delete_time = datetime.datetime.utcnow()
terminated_time = delete_time-datetime.timedelta(seconds=1)
launch_time = delete_time-datetime.timedelta(days=1)
launch_decimal = utils.decimal_utc(launch_time)
delete_decimal = utils.decimal_utc(delete_time)
notification = self.mox.CreateMockAnything()
notification.instance = INSTANCE_ID_1
notification.deleted_at = str(delete_time)
notification.terminated_at = str(terminated_time)
notification.launched_at = str(launch_time)
raw = self.mox.CreateMockAnything()
delete = self.mox.CreateMockAnything()
delete.instance = INSTANCE_ID_1
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,
launched_at=launch_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.launched_at, launch_decimal)
self.assertEqual(delete.deleted_at, delete_decimal)
self.mox.VerifyAll()
def test_process_delete_with_only_terminated_at(self):
delete_time = datetime.datetime.utcnow()
launch_time = delete_time-datetime.timedelta(days=1)
launch_decimal = utils.decimal_utc(launch_time)
delete_decimal = utils.decimal_utc(delete_time)
notification = self.mox.CreateMockAnything()
notification.instance = INSTANCE_ID_1
notification.deleted_at = ''
notification.terminated_at = str(delete_time)
notification.launched_at = str(launch_time)
raw = self.mox.CreateMockAnything()
delete = self.mox.CreateMockAnything()
delete.instance = INSTANCE_ID_1
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,
launched_at=launch_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.launched_at, launch_decimal)
self.assertEqual(delete.deleted_at, delete_decimal)
self.mox.VerifyAll()
def test_process_delete_with_neither(self):
delete_time = datetime.datetime.utcnow()
launch_time = delete_time-datetime.timedelta(days=1)
launch_decimal = utils.decimal_utc(launch_time)
delete_decimal = utils.decimal_utc(delete_time)
notification = self.mox.CreateMockAnything()
notification.instance = INSTANCE_ID_1
notification.deleted_at = ''
notification.terminated_at = str(delete_time)
notification.launched_at = str(launch_time)
raw = self.mox.CreateMockAnything()