launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27742
[Merge] ~cjwatson/launchpad:archive-auth-memcache-expire-time into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:archive-auth-memcache-expire-time into launchpad:master.
Commit message:
Fix wsgi-archive-auth's expiry handling for pymemcache
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/412092
I adjusted `MemcacheFixture` to apply the same type check that `pymemcache` does, in order to catch any other stragglers.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:archive-auth-memcache-expire-time into launchpad:master.
diff --git a/lib/lp/services/memcache/testing.py b/lib/lp/services/memcache/testing.py
index 14b6ca5..307d92f 100644
--- a/lib/lp/services/memcache/testing.py
+++ b/lib/lp/services/memcache/testing.py
@@ -8,6 +8,7 @@ __all__ = [
import time as _time
import fixtures
+from pymemcache.exceptions import MemcacheIllegalInputError
from lp.services.memcache.client import MemcacheClient
from lp.services.memcache.interfaces import IMemcacheClient
@@ -36,8 +37,12 @@ class MemcacheFixture(fixtures.Fixture, MemcacheClient):
# absolute epoch-seconds, and tells them apart using a magic
# threshold. See memcached/memcached.c:realtime.
MONTH_IN_SECONDS = 60 * 60 * 24 * 30
- if expire and expire <= MONTH_IN_SECONDS:
- expire = _time.time() + expire
+ if expire:
+ if not isinstance(expire, int):
+ raise MemcacheIllegalInputError(
+ "expire must be integer, got bad value: %r" % expire)
+ if expire <= MONTH_IN_SECONDS:
+ expire = int(_time.time()) + expire
self._cache[key] = (val, expire)
return 1
diff --git a/lib/lp/soyuz/wsgi/archiveauth.py b/lib/lp/soyuz/wsgi/archiveauth.py
index dc0dece..b02c49b 100644
--- a/lib/lp/soyuz/wsgi/archiveauth.py
+++ b/lib/lp/soyuz/wsgi/archiveauth.py
@@ -92,7 +92,7 @@ def check_password(environ, user, password):
proxy.checkArchiveAuthToken(archive_reference, user, password)
# Cache positive responses for a minute to reduce database load.
_memcache_client.set(
- memcache_key, _crypt_sha256(password), time.time() + 60)
+ memcache_key, _crypt_sha256(password), int(time.time()) + 60)
_log(environ, "%s@%s: Authorized.", user, archive_reference)
return True
except Fault as e: