Skip to content
Browse files

agent_aws: factor out validation by arguments

Change-Id: I130cda4248b9687798f89c1bf46ad7b961c05d9e
  • Loading branch information
Moritz Kiemer
Moritz Kiemer committed Apr 25, 2019
1 parent 61bb4e7 commit 0137f8af61bc4b89c80238676f735bac26d1f352
Showing with 13 additions and 6 deletions.
  1. +13 −6 cmk/special_agents/
@@ -628,7 +628,8 @@ def _get_raw_content(self, colleague_contents, use_cache=False):
# Cache is only used if the age is lower than section interval AND
# the collected data from colleagues are not newer
self._cache_file_dir.mkdir(parents=True, exist_ok=True)
if use_cache and self._cache_is_recent_enough(colleague_contents):
if (use_cache and self.get_validity_from_args(colleague_contents) and
raw_content, cache_timestamp = self._read_from_cache()
raw_content = self._fetch_raw_content(colleague_contents)
@@ -652,20 +653,26 @@ def cache_timestamp(self):"Cannot calculate cache file age: %s", exc)

def _cache_is_recent_enough(self, colleague_contents):
def _cache_is_recent_enough(self):
mtime = self.cache_timestamp
if mtime is None:
return False

age = time.time() - mtime
if 0 < age < self.interval:
return True

if age < 0:"Cache file from future considered invalid: %s", self._cache_file)
return False
if age >= self.interval:
else:"Cache file %s is outdated", self._cache_file)
return False
return False

if colleague_contents.cache_timestamp > mtime:
def get_validity_from_args(self, colleague_contents):
my_cache_timestamp = self.cache_timestamp
if my_cache_timestamp is None:
return False
if colleague_contents.cache_timestamp > my_cache_timestamp:"Colleague data is newer than cache file %s", self._cache_file)
return False
return True

0 comments on commit 0137f8a

Please sign in to comment.
You can’t perform that action at this time.