6 from os
import getcwd, chdir
7 from test_fixtures
import KeyStore, with_uptane_backend, with_path, with_director, with_aktualizr,\
8 with_install_manager, with_imagerepo, with_images, MalformedImageHandler, \
9 DownloadInterruptionHandler, MalformedJsonHandler, DownloadInterruptionHandler, TestRunner
12 logger = logging.getLogger(__file__)
16 Verifies whether aktualizr is updatable after image metadata download failure
17 with follow-up successful metadata download.
19 Currently, it's tested against two types of metadata download/parsing failure:
20 - download interruption - metadata file download is interrupted once|three times, after that it's successful
21 - malformed json - aktualizr receives malformed json/metadata as a response to the first request for metadata,
22 a response to subsequent request is successful
24 Note: Aktualizr doesn't send any installation report in manifest in case of metadata download failure
26 @with_uptane_backend(start_generic_server=
True)
27 @with_path(paths=[
'/1.root.json',
'/timestamp.json',
'/snapshot.json',
'/targets.json'])
28 @with_imagerepo(handlers=[
29 DownloadInterruptionHandler(number_of_failures=1),
30 MalformedJsonHandler(number_of_failures=1),
31 DownloadInterruptionHandler(number_of_failures=3),
33 @with_director(start=
False)
34 @with_aktualizr(start=
False, run_mode=
'full')
35 @with_install_manager()
36 def test_imagerepo_update_after_metadata_download_failure(install_mngr, director,
40 install_result = director.wait_for_install()
41 logger.info(
'Director install result: {}'.format(install_result))
42 install_result = install_result
and install_mngr.are_images_installed()
43 logger.info(
'Are images installed: {}'.format(install_result))
48 Verifies whether aktualizr is updatable after image download failure
49 with follow-up successful download.
51 Currently, it's tested against two types of image download failure:
52 - download interruption - file download is interrupted once, after that it's successful
53 - malformed image - image download is successful but it's malformed. It happens once after that it's successful
55 @with_uptane_backend(start_generic_server=
True)
56 @with_images(images_to_install=[((
'primary-hw-ID-001',
'primary-ecu-id'),
'primary-image.img')])
57 @with_imagerepo(handlers=[
58 DownloadInterruptionHandler(number_of_failures=1, url=
'/targets/primary-image.img'),
59 MalformedImageHandler(number_of_failures=1, url=
'/targets/primary-image.img'),
61 @with_director(start=
False)
62 @with_aktualizr(start=
False, run_mode=
'full', id=(
'primary-hw-ID-001',
'primary-ecu-id'))
63 @with_install_manager()
64 def test_imagerepo_update_after_image_download_failure(install_mngr, director,
68 install_result = director.wait_for_install()
69 install_result = install_result
and install_mngr.are_images_installed()
74 Verifies whether an update fails if repo metadata download fails or they are malformed
75 - download is interrupted three times
76 - malformed json is received
78 @with_uptane_backend(start_generic_server=
True)
79 @with_path(paths=[
'/1.root.json',
'/timestamp.json',
'/snapshot.json',
'/targets.json'])
80 @with_imagerepo(handlers=[
81 DownloadInterruptionHandler(number_of_failures=3),
82 MalformedJsonHandler(number_of_failures=1),
85 @with_aktualizr(run_mode=
'once')
86 @with_install_manager()
87 def test_imagerepo_unsuccessful_download(install_mngr, aktualizr,
89 aktualizr.wait_for_completion()
90 return not (director.get_install_result()
or install_mngr.are_images_installed())
93 if __name__ ==
"__main__":
94 logging.basicConfig(level=logging.INFO)
96 parser = argparse.ArgumentParser(description=
'Test backend failure')
97 parser.add_argument(
'-b',
'--build-dir', help=
'build directory', default=
'build')
98 parser.add_argument(
'-s',
'--src-dir', help=
'source directory', default=
'.')
99 input_params = parser.parse_args()
101 KeyStore.base_dir = input_params.src_dir
102 initial_cwd = getcwd()
103 chdir(input_params.build_dir)
106 test_imagerepo_update_after_metadata_download_failure,
107 test_imagerepo_update_after_image_download_failure,
108 test_imagerepo_unsuccessful_download,
111 with TestRunner(test_suite)
as runner:
112 test_suite_run_result = runner.run()
115 exit(0
if test_suite_run_result
else 1)