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
48 @with_uptane_backend(start_generic_server=
True)
49 @with_customrepo(handlers=[
50 RedirectHandler(number_of_redirects=10, url=
'/primary-image.img')
54 @with_aktualizr(run_mode=
'once', output_logs=
True)
55 def test_customrepo_update_redirect(aktualizr, uptane_repo,
56 custom_repo, director, **kwargs):
57 update_hash = uptane_repo.add_image(aktualizr.id,
'primary-image.img',
58 custom_url=custom_repo.base_url +
'/' +
'primary-image.img')
59 install_result = director.wait_for_install()
60 return install_result
and update_hash == aktualizr.get_current_image_info(aktualizr.id)
63 Verifies if aktualizr rejects redirects over 10 times - update fails after redirect
65 @with_uptane_backend(start_generic_server=
True)
66 @with_customrepo(handlers=[
67 RedirectHandler(number_of_redirects=(11 * 3 + 1), url=
'/primary-image.img')
71 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
72 def test_customrepo_unsuccessful_update_redirect(aktualizr, uptane_repo,
73 custom_repo, director, **kwargs):
74 update_hash = uptane_repo.add_image(aktualizr.id,
'primary-image.img',
75 custom_url=custom_repo.base_url +
'/' +
'primary-image.img')
77 aktualizr.wait_for_completion()
79 return not director.get_install_result()
82 if __name__ ==
"__main__":
83 logging.basicConfig(level=logging.INFO)
85 parser = argparse.ArgumentParser(description=
'Test backend failure')
86 parser.add_argument(
'-b',
'--build-dir', help=
'build directory', default=
'build')
87 parser.add_argument(
'-s',
'--src-dir', help=
'source directory', default=
'.')
88 input_params = parser.parse_args()
90 KeyStore.base_dir = input_params.src_dir
91 initial_cwd = getcwd()
92 chdir(input_params.build_dir)
95 test_customrepo_update_after_image_download_failure,
96 test_customrepo_update_redirect,
97 test_customrepo_unsuccessful_update_redirect,
100 with TestRunner(test_suite)
as runner:
101 test_suite_run_result = runner.run()
104 exit(0
if test_suite_run_result
else 1)