Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
test_customrepo_failure.py
1 #!/usr/bin/env python3
2 
3 import logging
4 import argparse
5 
6 from os import getcwd, chdir
7 
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
12 
13 
14 logger = logging.getLogger(__file__)
15 
16 
17 """
18  Verifies whether aktualizr is updatable after malformed image is downloaded
19  from a custom image server with follow-up successful download.
20 """
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')
25  # TODO: this test fails too, although httpclient.cc sets
26  # CURLOPT_LOW_SPEED_TIME and CURLOPT_LOW_SPEED_TIME
27  # https://saeljira.it.here.com/browse/OTA-3737
28  #SlowRetrievalHandler(url='/primary-image.img')
29  ])
30 @with_imagerepo()
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,
34  aktualizr, **kwargs):
35  update_hash = uptane_repo.add_image(aktualizr.id, 'primary-image.img',
36  custom_url=custom_repo.base_url + '/' + 'primary-image.img')
37 
38  with aktualizr:
39  with director:
40  install_result = director.wait_for_install()
41 
42  return install_result and update_hash == aktualizr.get_current_image_info(aktualizr.id)
43 
44 
45 """
46  Verifies if aktualizr supports redirects - update is successful after redirect
47 """
48 @with_uptane_backend(start_generic_server=True)
49 @with_customrepo(handlers=[
50  RedirectHandler(number_of_redirects=10, url='/primary-image.img')
51  ])
52 @with_imagerepo()
53 @with_director()
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)
61 
62 """
63  Verifies if aktualizr rejects redirects over 10 times - update fails after redirect
64 """
65 @with_uptane_backend(start_generic_server=True)
66 @with_customrepo(handlers=[
67  RedirectHandler(number_of_redirects=(11 * 3 + 1), url='/primary-image.img')
68  ])
69 @with_imagerepo()
70 @with_director()
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')
76  with aktualizr:
77  aktualizr.wait_for_completion()
78 
79  return not director.get_install_result()
80 
81 
82 if __name__ == "__main__":
83  logging.basicConfig(level=logging.INFO)
84 
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()
89 
90  KeyStore.base_dir = input_params.src_dir
91  initial_cwd = getcwd()
92  chdir(input_params.build_dir)
93 
94  test_suite = [
95  test_customrepo_update_after_image_download_failure,
96  test_customrepo_update_redirect,
97  test_customrepo_unsuccessful_update_redirect,
98  ]
99 
100  with TestRunner(test_suite) as runner:
101  test_suite_run_result = runner.run()
102 
103  chdir(initial_cwd)
104  exit(0 if test_suite_run_result else 1)