Work around for blank deleted_ats
This commit is contained in:
parent
787409e05e
commit
488e5c9fd2
@ -237,6 +237,7 @@ class NovaNotification(Notification):
|
|||||||
self.payload.get('new_instance_type_id', None)
|
self.payload.get('new_instance_type_id', None)
|
||||||
self.launched_at = self.payload.get('launched_at', None)
|
self.launched_at = self.payload.get('launched_at', None)
|
||||||
self.deleted_at = self.payload.get('deleted_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(
|
self.audit_period_beginning = self.payload.get(
|
||||||
'audit_period_beginning', None)
|
'audit_period_beginning', None)
|
||||||
self.audit_period_ending = self.payload.get(
|
self.audit_period_ending = self.payload.get(
|
||||||
|
@ -242,7 +242,11 @@ def _process_usage_for_updates(raw, notification):
|
|||||||
def _process_delete(raw, notification):
|
def _process_delete(raw, notification):
|
||||||
if notification.launched_at and notification.launched_at != '':
|
if notification.launched_at and notification.launched_at != '':
|
||||||
instance_id = notification.instance
|
instance_id = notification.instance
|
||||||
|
deleted_at = None
|
||||||
|
if notification.deleted_at:
|
||||||
deleted_at = utils.str_time_to_unix(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)
|
launched_at = utils.str_time_to_unix(notification.launched_at)
|
||||||
values = {
|
values = {
|
||||||
'instance': instance_id,
|
'instance': instance_id,
|
||||||
|
@ -665,12 +665,74 @@ class StacktachUsageParsingTestCase(StacktachBaseTestCase):
|
|||||||
|
|
||||||
def test_process_delete(self):
|
def test_process_delete(self):
|
||||||
delete_time = datetime.datetime.utcnow()
|
delete_time = datetime.datetime.utcnow()
|
||||||
|
terminated_time = delete_time-datetime.timedelta(seconds=1)
|
||||||
launch_time = delete_time-datetime.timedelta(days=1)
|
launch_time = delete_time-datetime.timedelta(days=1)
|
||||||
launch_decimal = utils.decimal_utc(launch_time)
|
launch_decimal = utils.decimal_utc(launch_time)
|
||||||
delete_decimal = utils.decimal_utc(delete_time)
|
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.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)
|
notification.launched_at = str(launch_time)
|
||||||
|
|
||||||
raw = self.mox.CreateMockAnything()
|
raw = self.mox.CreateMockAnything()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user