From 00c54c9f79692c9ad57a44092249fb50abc110c8 Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Mon, 1 Apr 2013 14:35:50 -0400 Subject: [PATCH] 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. --- tests/unit/test_verifier_db.py | 8 +++----- verifier/dbverifier.py | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/unit/test_verifier_db.py b/tests/unit/test_verifier_db.py index 64c44ee..4d4c8e5 100644 --- a/tests/unit/test_verifier_db.py +++ b/tests/unit/test_verifier_db.py @@ -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) diff --git a/verifier/dbverifier.py b/verifier/dbverifier.py index 079f54c..d0f93ab 100644 --- a/verifier/dbverifier.py +++ b/verifier/dbverifier.py @@ -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)