Merge lp://staging/~rvb/maas/nonce-bug-1190986 into lp://staging/~maas-committers/maas/trunk
Proposed by
Raphaël Badin
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Raphaël Badin | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 1697 | ||||
Proposed branch: | lp://staging/~rvb/maas/nonce-bug-1190986 | ||||
Merge into: | lp://staging/~maas-committers/maas/trunk | ||||
Diff against target: |
222 lines (+213/-0) 2 files modified
src/maasserver/nonces_cleanup.py (+94/-0) src/maasserver/tests/test_nonces_cleanup.py (+119/-0) |
||||
To merge this branch: | bzr merge lp://staging/~rvb/maas/nonce-bug-1190986 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gavin Panella (community) | Approve | ||
Review via email:
|
Commit message
Add utility to remove old nonces.
Description of the change
Note that this is *just* the utility itself (function cleanup_
To post a comment you must log in.
Looks good, and easy to understand!
[1]
+ create_ checkpoint_ nonce() _nonce( ) old_nonces( checkpoint)
+ # Delete old nonces.
+ checkpoint = find_checkpoint
+ if checkpoint is None:
+ return 0
+ return delete_
Seems odd to create the new nonce before deleting; there is a very
slow race condition there.
[2]
+def delete_ old_nonces( checkpoint) : filter( id__lte= checkpoint. id) delete. count() delete. delete( )
+ """Delete nonces older than the given nonce."""
+ nonce_to_delete = Nonce.objects.
+ count = nonce_to_
+ nonce_to_
+ return count
Do we need the count?
[3]
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = []
Please merge trunk and update this to the newest template; there's a
'str = None' missing from there.
[4]
+ self.patch( module_ time, "time") .return_ value = ( threshold)
+ now - timestamp_
I'd hesitate from patching time.time() - it may be used by nose before
the patching machinery is invoked to repair its work. How about:
from maasserver import nonces_cleanup
timemod = self.patch( nonces_ cleanup, "time")
timemod. time.return_ value = now - timestamp_threshold
timemod. time.return_ value = now
...
?
[5]
+ self.assertLess Equal(before, float(checkpoin t.key.strip( key_suffix) )) terEqual( t.key.strip( key_suffix) ))
+ self.assertGrea
+ after, float(checkpoin
strip() doesn't work like that; key_suffix will be used as
*characters* to strip. In this instance it works, but perhaps a
different mechanism ought to be used, e.g.:
Also, with testtools you can do the above check in one go:
Though it's not really any clearer.