Using audit_period_ending in _verify_for_delete

The previous logic used the raw's timestamp, which could end up
    slightly outside of the audit period. This would give us a
    small window where a delete could happen outside of the
    audit period, but we'd still detect it. The new logic uses
    the exact end of the audit period.
This commit is contained in:
Andrew Melton 2013-04-01 14:35:50 -04:00
parent d6c441a507
commit 00c54c9f79
2 changed files with 7 additions and 9 deletions

View File

@ -256,8 +256,7 @@ class VerifierTestCase(unittest.TestCase):
exist.instance = INSTANCE_ID_1
exist.launched_at = decimal.Decimal('1.1')
exist.deleted_at = None
exist.raw = self.mox.CreateMockAnything()
exist.raw.when = decimal.Decimal('1.1')
exist.audit_period_ending = decimal.Decimal('1.1')
filters = {
'instance': INSTANCE_ID_1,
'launched_at__gte': decimal.Decimal('1.0'),
@ -279,13 +278,12 @@ class VerifierTestCase(unittest.TestCase):
exist.instance = INSTANCE_ID_1
exist.launched_at = decimal.Decimal('1.1')
exist.deleted_at = None
exist.raw = self.mox.CreateMockAnything()
exist.raw.when = decimal.Decimal('1.1')
exist.audit_period_ending = decimal.Decimal('1.3')
filters = {
'instance': INSTANCE_ID_1,
'launched_at__gte': decimal.Decimal('1.0'),
'launched_at__lte': decimal.Decimal('1.999999'),
'deleted_at__lte': decimal.Decimal('1.1')
'deleted_at__lte': decimal.Decimal('1.3')
}
results = self.mox.CreateMockAnything()
models.InstanceDeletes.objects.filter(**filters).AndReturn(results)

View File

@ -182,11 +182,11 @@ def _verify_for_delete(exist):
# Thus, we need to check if we have a delete for this instance.
# We need to be careful though, since we could be verifying an
# exist event that we got before the delete. So, we restrict the
# search to only deletes before the time this exist was sent.
# search to only deletes before this exist's audit period ended.
# If we find any, we fail validation
deletes = _find_delete(exist.instance,
dt.dt_from_decimal(exist.launched_at),
dt.dt_from_decimal(exist.raw.when))
launched_at = dt.dt_from_decimal(exist.launched_at)
deleted_at_max = dt.dt_from_decimal(exist.audit_period_ending)
deletes = _find_delete(exist.instance, launched_at, deleted_at_max)
if deletes.count() > 0:
reason = 'Found InstanceDeletes for non-delete exist'
raise VerificationException(reason)