6 from os
import getcwd, chdir
8 from test_fixtures
import with_aktualizr, with_uptane_backend, KeyStore, with_secondary, with_path,\
9 DownloadInterruptionHandler, MalformedJsonHandler, with_director, with_imagerepo, InstallManager,\
10 with_install_manager, with_images, MalformedImageHandler, with_customrepo, SlowRetrievalHandler, \
11 RedirectHandler, with_sysroot, with_treehub, TestRunner
14 logger = logging.getLogger(__file__)
18 Verifies whether aktualizr is updatable after malformed image is downloaded
19 from a custom image server with follow-up successful download.
21 @with_uptane_backend(start_generic_server=
True)
22 @with_customrepo(handlers=[
23 DownloadInterruptionHandler(number_of_failures=1, url=
'/primary-image.img'),
24 MalformedImageHandler(number_of_failures=1, url=
'/primary-image.img')
31 @with_director(start=
False)
32 @with_aktualizr(start=
False, run_mode=
'full')
33 def test_customrepo_update_after_image_download_failure(uptane_repo, custom_repo, director,
35 update_hash = uptane_repo.add_image(aktualizr.id,
'primary-image.img',
36 custom_url=custom_repo.base_url +
'/' +
'primary-image.img')
40 install_result = director.wait_for_install()
42 return install_result
and update_hash == aktualizr.get_current_image_info(aktualizr.id)
46 Verifies if aktualizr supports redirects - update is successful after redirect
47 Note: should aktualizr support unlimited number of redirects
49 @with_uptane_backend(start_generic_server=
True)
52 @with_customrepo(handlers=[
53 RedirectHandler(number_of_redirects=10, url=
'/primary-image.img')
57 @with_aktualizr(run_mode=
'once', output_logs=
True)
58 def test_customrepo_update_redirect(aktualizr, uptane_repo,
59 custom_repo, director, **kwargs):
60 update_hash = uptane_repo.add_image(aktualizr.id,
'primary-image.img',
61 custom_url=custom_repo.base_url +
'/' +
'primary-image.img')
62 install_result = director.wait_for_install()
63 return install_result
and update_hash == aktualizr.get_current_image_info(aktualizr.id)
66 Verifies if aktualizr rejects redirects over 10 times - update fails after redirect
68 @with_uptane_backend(start_generic_server=
True)
69 @with_customrepo(handlers=[
70 RedirectHandler(number_of_redirects=(11 * 3 + 1), url=
'/primary-image.img')
74 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
75 def test_customrepo_unsuccessful_update_redirect(aktualizr, uptane_repo,
76 custom_repo, director, **kwargs):
77 update_hash = uptane_repo.add_image(aktualizr.id,
'primary-image.img',
78 custom_url=custom_repo.base_url +
'/' +
'primary-image.img')
80 aktualizr.wait_for_completion()
82 return not director.get_install_result()
85 if __name__ ==
"__main__":
86 logging.basicConfig(level=logging.INFO)
88 parser = argparse.ArgumentParser(description=
'Test backend failure')
89 parser.add_argument(
'-b',
'--build-dir', help=
'build directory', default=
'build')
90 parser.add_argument(
'-s',
'--src-dir', help=
'source directory', default=
'.')
91 input_params = parser.parse_args()
93 KeyStore.base_dir = input_params.src_dir
94 initial_cwd = getcwd()
95 chdir(input_params.build_dir)
98 test_customrepo_update_after_image_download_failure,
99 test_customrepo_update_redirect,
100 test_customrepo_unsuccessful_update_redirect,
103 test_suite_run_result = TestRunner(test_suite).run()
106 exit(0
if test_suite_run_result
else 1)