Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
test_treehub_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_sysroot, with_treehub, DownloadInterruptionHandler, MalformedImageHandler, TestRunner
9 
10 logger = logging.getLogger(__file__)
11 
12 
13 """
14  Verifies whether aktualizr is updatable after failure of object(s) download from Treehub/ostree repo
15  with follow-up successful download.
16 
17  Currently, it's tested against two types of object download failure:
18  - download interruption - object download is interrupted once, after that it's successful
19  - malformed object - object download is successful but it's malformed. It happens once after that it's successful
20 """
21 @with_uptane_backend(start_generic_server=True)
22 @with_director()
23 @with_treehub(handlers=[
24  DownloadInterruptionHandler(url='/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez'),
25  MalformedImageHandler(url='/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez'),
26 
27  # TODO: ostree objects download is not resilient to `Slow Retrieval Attack`
28  # https://saeljira.it.here.com/browse/OTA-3737
29  #SlowRetrievalHandler(url='/objects/6b/1604b586fcbe052bbc0bd9e1c8040f62e085ca2e228f37df957ac939dff361.filez'),
30 
31  # TODO: Limit a number of HTTP redirects within a single request processing
32  # https://saeljira.it.here.com/browse/OTA-3729
33  #RedirectHandler(number_of_redirects=1000, url='/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez')
34 ])
35 @with_sysroot()
36 @with_aktualizr(start=False, run_mode='once')
37 def test_treehub_update_after_image_download_failure(uptane_repo,
38  aktualizr,
39  director,
40  uptane_server,
41  sysroot, treehub):
42  target_rev = treehub.revision
43  uptane_repo.add_ostree_target(aktualizr.id, target_rev)
44  with aktualizr:
45  aktualizr.wait_for_completion()
46 
47  pending_rev = aktualizr.get_primary_pending_version()
48  if pending_rev != target_rev:
49  logger.error("Pending version {} != the target one {}".format(pending_rev, target_rev))
50  return False
51 
52  sysroot.update_revision(pending_rev)
53  aktualizr.emulate_reboot()
54 
55  with aktualizr:
56  aktualizr.wait_for_completion()
57 
58  result = director.get_install_result() and (target_rev == aktualizr.get_current_primary_image_info())
59  return result
60 
61 
62 """
63  Verifies that aktualizr does not install an image which contains files with wrong checksums
64 """
65 @with_uptane_backend(start_generic_server=True)
66 @with_director()
67 @with_treehub(handlers=[
68  MalformedImageHandler(url='/objects/41/5ce9717fc7a5f4d743a4f911e11bd3ed83930e46756303fd13a3eb7ed35892.filez',
69  number_of_failures=-1, fake_filez=True),
70 
71 ])
72 @with_sysroot()
73 @with_aktualizr(start=False, run_mode='once', output_logs=True)
74 def test_treehub_update_if_bad_ostree_checksum(uptane_repo,
75  aktualizr,
76  director,
77  uptane_server,
78  sysroot, treehub):
79  target_rev = treehub.revision
80  uptane_repo.add_ostree_target(aktualizr.id, target_rev)
81  with aktualizr:
82  aktualizr.wait_for_completion()
83 
84  pending_rev = aktualizr.get_primary_pending_version()
85  if pending_rev == target_rev:
86  logger.error("Pending version {} == the target one {}".format(pending_rev, target_rev))
87  return False
88  return True
89 
90 
91 if __name__ == "__main__":
92  logging.basicConfig(level=logging.INFO)
93 
94  parser = argparse.ArgumentParser(description='Test backend failure')
95  parser.add_argument('-b', '--build-dir', help='build directory', default='build')
96  parser.add_argument('-s', '--src-dir', help='source directory', default='.')
97  input_params = parser.parse_args()
98 
99  KeyStore.base_dir = input_params.src_dir
100  initial_cwd = getcwd()
101  chdir(input_params.build_dir)
102 
103  test_suite = [
104  test_treehub_update_after_image_download_failure,
105  test_treehub_update_if_bad_ostree_checksum
106  ]
107 
108  test_suite_run_result = TestRunner(test_suite).run()
109 
110  chdir(initial_cwd)
111  exit(0 if test_suite_run_result else 1)