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, RedirectHandler, 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'),
26 RedirectHandler(number_of_redirects=1000, url=
'/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez'),
34 @with_aktualizr(start=
False, run_mode=
'once')
35 def test_treehub_update_after_image_download_failure(uptane_repo,
40 target_rev = treehub.revision
41 uptane_repo.add_ostree_target(aktualizr.id, target_rev)
43 aktualizr.wait_for_completion()
45 pending_rev = aktualizr.get_primary_pending_version()
46 if pending_rev != target_rev:
47 logger.error(
"Pending version {} != the target one {}".format(pending_rev, target_rev))
50 sysroot.update_revision(pending_rev)
51 aktualizr.emulate_reboot()
54 aktualizr.wait_for_completion()
56 result = director.get_install_result()
and (target_rev == aktualizr.get_current_primary_image_info())
61 Verifies that aktualizr does not install an image which contains files with wrong checksums
63 @with_uptane_backend(start_generic_server=
True)
65 @with_treehub(handlers=[
66 MalformedImageHandler(url=
'/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez',
67 number_of_failures=-1, fake_filez=
True),
71 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
72 def test_treehub_update_if_bad_ostree_checksum(uptane_repo,
77 target_rev = treehub.revision
78 uptane_repo.add_ostree_target(aktualizr.id, target_rev)
80 aktualizr.wait_for_completion()
82 pending_rev = aktualizr.get_primary_pending_version()
83 if pending_rev == target_rev:
84 logger.error(
"Pending version {} == the target one {}".format(pending_rev, target_rev))
89 if __name__ ==
"__main__":
90 logging.basicConfig(level=logging.INFO)
92 parser = argparse.ArgumentParser(description=
'Test backend failure')
93 parser.add_argument(
'-b',
'--build-dir', help=
'build directory', default=
'build')
94 parser.add_argument(
'-s',
'--src-dir', help=
'source directory', default=
'.')
95 input_params = parser.parse_args()
97 KeyStore.base_dir = input_params.src_dir
98 initial_cwd = getcwd()
99 chdir(input_params.build_dir)
102 test_treehub_update_after_image_download_failure,
103 test_treehub_update_if_bad_ostree_checksum
106 with TestRunner(test_suite)
as runner:
107 test_suite_run_result = runner.run()
110 exit(0
if test_suite_run_result
else 1)