Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
test_director_failure.py
1 #!/usr/bin/env python3
2 
3 import logging
4 import argparse
5 
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, TestRunner, \
9  DownloadInterruptionHandler, MalformedJsonHandler, DownloadInterruptionHandler
10 
11 logger = logging.getLogger(__file__)
12 
13 
14 """
15 Verifies whether aktualizr is updatable after director metadata download failure
16 with follow-up successful metadata download.
17 
18 Currently, it's tested against two types of metadata download/parsing failure:
19  - download interruption - metadata file download is interrupted once|three times, after that it's successful
20  - malformed json - aktualizr receives malformed json/metadata as a response to the first request for metadata,
21  a response to subsequent request is successful
22 
23 Note: Aktualizr doesn't send any installation report in manifest in case of metadata download failure
24 https://saeljira.it.here.com/browse/OTA-3730
25 """
26 @with_uptane_backend(start_generic_server=True)
27 @with_path(paths=['/1.root.json', '/targets.json'])
28 @with_director(handlers=[
29  DownloadInterruptionHandler(number_of_failures=1),
30  MalformedJsonHandler(number_of_failures=1),
31  DownloadInterruptionHandler(number_of_failures=3),
32  ], start=False)
33 @with_aktualizr(start=False, run_mode='full')
34 @with_install_manager()
35 def test_director_update_after_metadata_download_failure(install_mngr, director,
36  aktualizr, **kwargs):
37  with director:
38  with aktualizr:
39  install_result = director.wait_for_install()
40  install_result = install_result and install_mngr.are_images_installed()
41  return install_result
42 
43 
44 """
45  Verifies whether an update fails if director metadata download fails or they are malformed
46  - download is interrupted three times
47  - malformed json is received
48 """
49 @with_uptane_backend(start_generic_server=True)
50 @with_path(paths=['/1.root.json', '/targets.json'])
51 @with_imagerepo()
52 @with_director(handlers=[
53  DownloadInterruptionHandler(number_of_failures=3),
54  MalformedJsonHandler(number_of_failures=1),
55  ])
56 @with_aktualizr(run_mode='once')
57 @with_install_manager()
58 def test_director_unsuccessful_download(install_mngr, aktualizr,
59  director, **kwargs):
60  aktualizr.wait_for_completion()
61  return not (director.get_install_result() or install_mngr.are_images_installed())
62 
63 
64 if __name__ == "__main__":
65  logging.basicConfig(level=logging.INFO)
66 
67  parser = argparse.ArgumentParser(description='Test backend failure')
68  parser.add_argument('-b', '--build-dir', help='build directory', default='build')
69  parser.add_argument('-s', '--src-dir', help='source directory', default='.')
70  input_params = parser.parse_args()
71 
72  KeyStore.base_dir = input_params.src_dir
73  initial_cwd = getcwd()
74  chdir(input_params.build_dir)
75 
76  test_suite = [
77  test_director_update_after_metadata_download_failure,
78  test_director_unsuccessful_download
79  ]
80 
81  with TestRunner(test_suite) as runner:
82  test_suite_run_result = runner.run()
83 
84  chdir(initial_cwd)
85  exit(0 if test_suite_run_result else 1)