6 from os
import getcwd, chdir
7 from test_fixtures
import KeyStore, with_uptane_backend, with_path, with_director, with_aktualizr, \
8 with_sysroot, with_treehub, DownloadInterruptionHandler, MalformedImageHandler, TestRunner
10 logger = logging.getLogger(__file__)
14 Verifies whether aktualizr is updatable after failure of object(s) download from Treehub/ostree repo
15 with follow-up successful download.
17 Currently, it's tested against two types of object download failure:
18 - download interruption - object download is interrupted once, after that it's successful
19 - malformed object - object download is successful but it's malformed. It happens once after that it's successful
21 @with_uptane_backend(start_generic_server=
True)
23 @with_treehub(handlers=[
24 DownloadInterruptionHandler(url=
'/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez'),
25 MalformedImageHandler(url=
'/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez'),
36 @with_aktualizr(start=
False, run_mode=
'once')
37 def test_treehub_update_after_image_download_failure(uptane_repo,
42 target_rev = treehub.revision
43 uptane_repo.add_ostree_target(aktualizr.id, target_rev)
45 aktualizr.wait_for_completion()
47 pending_rev = aktualizr.get_primary_pending_version()
48 if pending_rev != target_rev:
49 logger.error(
"Pending version {} != the target one {}".format(pending_rev, target_rev))
52 sysroot.update_revision(pending_rev)
53 aktualizr.emulate_reboot()
56 aktualizr.wait_for_completion()
58 result = director.get_install_result()
and (target_rev == aktualizr.get_current_primary_image_info())
63 Verifies that aktualizr does not install an image which contains files with wrong checksums
65 @with_uptane_backend(start_generic_server=
True)
67 @with_treehub(handlers=[
68 MalformedImageHandler(url=
'/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez',
69 number_of_failures=-1, fake_filez=
True),
73 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
74 def test_treehub_update_if_bad_ostree_checksum(uptane_repo,
79 target_rev = treehub.revision
80 uptane_repo.add_ostree_target(aktualizr.id, target_rev)
82 aktualizr.wait_for_completion()
84 pending_rev = aktualizr.get_primary_pending_version()
85 if pending_rev == target_rev:
86 logger.error(
"Pending version {} == the target one {}".format(pending_rev, target_rev))
91 if __name__ ==
"__main__":
92 logging.basicConfig(level=logging.INFO)
94 parser = argparse.ArgumentParser(description=
'Test backend failure')
95 parser.add_argument(
'-b',
'--build-dir', help=
'build directory', default=
'build')
96 parser.add_argument(
'-s',
'--src-dir', help=
'source directory', default=
'.')
97 input_params = parser.parse_args()
99 KeyStore.base_dir = input_params.src_dir
100 initial_cwd = getcwd()
101 chdir(input_params.build_dir)
104 test_treehub_update_after_image_download_failure,
105 test_treehub_update_if_bad_ostree_checksum
108 test_suite_run_result = TestRunner(test_suite).run()
111 exit(0
if test_suite_run_result
else 1)