autopkgtest: Move cache upgrade into its own function

The intialise method is already complex enough and this was a trivial
snippet to extract to reduce the complexity a bit.

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 6 years ago
parent cd654183b7
commit 198e257a91
No known key found for this signature in database
GPG Key ID: A65B78DBE67C7AAC

@ -162,24 +162,7 @@ class AutopkgtestPolicy(BasePolicy):
if os.path.exists(self.results_cache_file): if os.path.exists(self.results_cache_file):
with open(self.results_cache_file) as f: with open(self.results_cache_file) as f:
test_results = json.load(f) test_results = json.load(f)
for result in all_leaf_results(test_results): self.test_results = self.check_and_upgrade_cache(test_results)
try:
result[0] = Result[result[0]]
except KeyError:
# Legacy support
if isinstance(result[0], type(True)):
if result[0]:
result[0] = Result.PASS
else:
result[0] = Result.FAIL
else:
raise
# More legacy support
try:
dummy = result[3]
except IndexError:
result.append(self._now)
self.test_results = test_results
self.logger.info('Read previous results from %s', self.results_cache_file) self.logger.info('Read previous results from %s', self.results_cache_file)
# The cache can contain results against versions of packages that # The cache can contain results against versions of packages that
@ -258,6 +241,26 @@ class AutopkgtestPolicy(BasePolicy):
else: else:
raise RuntimeError('Unknown ADT_AMQP schema %s' % amqp_url.split(':', 1)[0]) raise RuntimeError('Unknown ADT_AMQP schema %s' % amqp_url.split(':', 1)[0])
def check_and_upgrade_cache(self, test_results):
for result in all_leaf_results(test_results):
try:
result[0] = Result[result[0]]
except KeyError:
# Legacy support
if isinstance(result[0], type(True)):
if result[0]:
result[0] = Result.PASS
else:
result[0] = Result.FAIL
else:
raise
# More legacy support
try:
dummy = result[3]
except IndexError:
result.append(self._now)
return test_results
def filter_results_for_old_versions(self): def filter_results_for_old_versions(self):
'''Remove results for old versions from the cache''' '''Remove results for old versions from the cache'''

Loading…
Cancel
Save