mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-08-11 15:44:08 +00:00
autopkgtest: Extract some ("boring") loops into a function
When we convert legacy results in the autopkgtest-results.cache file, we are only touching leaf results. By moving the loops into a function, we can remove 2-3 levels of ("redundant") nesting. This in turn makes it more clear what is relevant in the conversion. This same also holds in save_state when we convert an Enum to a string. Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
fce1fe5c27
commit
cd654183b7
@ -82,6 +82,12 @@ def added_pkgs_compared_to_target_suite(package_ids, target_suite, *, invert=Fal
|
|||||||
yield from (p for p in package_ids if p.package_name not in names_ignored)
|
yield from (p for p in package_ids if p.package_name not in names_ignored)
|
||||||
|
|
||||||
|
|
||||||
|
def all_leaf_results(test_results):
|
||||||
|
for trigger in test_results.values():
|
||||||
|
for arch in trigger.values():
|
||||||
|
yield from arch.values()
|
||||||
|
|
||||||
|
|
||||||
class AutopkgtestPolicy(BasePolicy):
|
class AutopkgtestPolicy(BasePolicy):
|
||||||
"""autopkgtest regression policy for source migrations
|
"""autopkgtest regression policy for source migrations
|
||||||
|
|
||||||
@ -155,27 +161,25 @@ class AutopkgtestPolicy(BasePolicy):
|
|||||||
# read the cached results that we collected so far
|
# read the cached results that we collected so far
|
||||||
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:
|
||||||
results = json.load(f)
|
test_results = json.load(f)
|
||||||
for trigger in results.values():
|
for result in all_leaf_results(test_results):
|
||||||
for arch in trigger.values():
|
try:
|
||||||
for result in arch.values():
|
result[0] = Result[result[0]]
|
||||||
try:
|
except KeyError:
|
||||||
result[0] = Result[result[0]]
|
# Legacy support
|
||||||
except KeyError:
|
if isinstance(result[0], type(True)):
|
||||||
# Legacy support
|
if result[0]:
|
||||||
if isinstance(result[0], type(True)):
|
result[0] = Result.PASS
|
||||||
if result[0]:
|
else:
|
||||||
result[0] = Result.PASS
|
result[0] = Result.FAIL
|
||||||
else:
|
else:
|
||||||
result[0] = Result.FAIL
|
raise
|
||||||
else:
|
# More legacy support
|
||||||
raise
|
try:
|
||||||
# More legacy support
|
dummy = result[3]
|
||||||
try:
|
except IndexError:
|
||||||
dummy = result[3]
|
result.append(self._now)
|
||||||
except IndexError:
|
self.test_results = test_results
|
||||||
result.append(self._now)
|
|
||||||
self.test_results = 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
|
||||||
@ -305,13 +309,11 @@ class AutopkgtestPolicy(BasePolicy):
|
|||||||
# update the results on-disk cache, unless we are using a r/o shared one
|
# update the results on-disk cache, unless we are using a r/o shared one
|
||||||
if not self.options.adt_shared_results_cache:
|
if not self.options.adt_shared_results_cache:
|
||||||
self.logger.info('Updating results cache')
|
self.logger.info('Updating results cache')
|
||||||
results = deepcopy(self.test_results)
|
test_results = deepcopy(self.test_results)
|
||||||
for trigger in results.values():
|
for result in all_leaf_results(test_results):
|
||||||
for arch in trigger.values():
|
result[0] = result[0].name
|
||||||
for result in arch.values():
|
|
||||||
result[0] = result[0].name
|
|
||||||
with open(self.results_cache_file + '.new', 'w') as f:
|
with open(self.results_cache_file + '.new', 'w') as f:
|
||||||
json.dump(results, f, indent=2)
|
json.dump(test_results, f, indent=2)
|
||||||
os.rename(self.results_cache_file + '.new', self.results_cache_file)
|
os.rename(self.results_cache_file + '.new', self.results_cache_file)
|
||||||
|
|
||||||
# update the pending tests on-disk cache
|
# update the pending tests on-disk cache
|
||||||
|
Loading…
x
Reference in New Issue
Block a user