Fix 28689 : Check s3 ext pillar cache file before calculating expiration

This commit is contained in:
Metin OSMAN 2015-11-09 09:22:49 +01:00 committed by rallytime
parent 3249b322e8
commit a0988dab58

View file

@ -177,17 +177,26 @@ def _init(creds, bucket, multiple_env, environment, prefix, s3_cache_expire):
cache_file = _get_buckets_cache_filename(bucket, prefix)
exp = time.time() - s3_cache_expire
cache_file_mtime = os.path.getmtime(cache_file)
# check mtime of the buckets files cache
if os.path.isfile(cache_file) and cache_file_mtime > exp:
log.debug("S3 bucket cache file {0} is not expired, mtime_diff={1}s, expiration={2}s".format(cache_file, cache_file_mtime - exp, s3_cache_expire))
return _read_buckets_cache_file(cache_file)
# check if cache_file exists and its mtime
if os.path.isfile(cache_file):
cache_file_mtime = os.path.getmtime(cache_file)
else:
# bucket files cache expired
log.debug("S3 bucket cache file {0} is expired, mtime_diff={1}s, expiration={2}s".format(cache_file, cache_file_mtime - exp, s3_cache_expire))
return _refresh_buckets_cache_file(creds, cache_file, multiple_env,
# file does not exists then set mtime to 0 (aka epoch)
cache_file_mtime = 0
expired = (cache_file_mtime <= exp)
log.debug("S3 bucket cache file {0} is {1}expired, mtime_diff={2}s, expiration={3}s".format(cache_file, "" if expired else "not ", cache_file_mtime - exp, s3_cache_expire))
if expired:
pillars = _refresh_buckets_cache_file(creds, cache_file, multiple_env,
environment, prefix)
else:
pillars = _read_buckets_cache_file(cache_file)
log.debug("S3 bucket retrieved pillars {0}".format(pillars))
return pillars
def _get_cache_dir():