Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
test_update.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 KeyStore, with_aktualizr, with_uptane_backend, with_secondary, with_director, with_imagerepo,\
9  with_sysroot, with_treehub
10 
11 
12 logger = logging.getLogger(__file__)
13 
14 
15 """
16  Test update of Primary and Secondary if their package manager differs, `ostree` and `fake` respectively
17 
18  Aktualizr/Primary's package manager is set to `ostree`
19  Secondary's package manager is set to `fake`
20  Primary goal is to verify whether aktualizr succeeds with a binary/fake update of secondary
21  while aktualizr/primary is configured with ostree package manager
22 """
23 @with_uptane_backend(start_generic_server=True)
24 @with_secondary(start=True)
25 @with_director()
26 @with_treehub()
27 @with_sysroot()
28 @with_aktualizr(start=False, run_mode='once', output_logs=True)
29 def test_primary_ostree_secondary_fake_updates(uptane_repo, secondary, aktualizr, director,
30  uptane_server, sysroot, treehub):
31  target_rev = treehub.revision
32  # add an ostree update for Primary
33  uptane_repo.add_ostree_target(aktualizr.id, target_rev)
34  # add a fake/binary update for Secondary
35  secondary_update_hash = uptane_repo.add_image(secondary.id, "secondary-update.bin")
36 
37  with aktualizr:
38  aktualizr.wait_for_completion()
39 
40  # check the Primary update, must be in pending state since it requires reboot
41  pending_rev = aktualizr.get_primary_pending_version()
42  if pending_rev != target_rev:
43  logger.error("Pending version {} != the target version {}".format(pending_rev, target_rev))
44  return False
45 
46  # check the Secondary update
47  current_secondary_image_hash = aktualizr.get_current_image_info(secondary.id)
48  if current_secondary_image_hash != secondary_update_hash:
49  logger.error("Current secondary image {} != expected image {}".format(current_secondary_image_hash,
50  secondary_update_hash))
51  return False
52 
53  # emulate reboot and run aktualizr once more
54  sysroot.update_revision(pending_rev)
55  aktualizr.emulate_reboot()
56 
57  with aktualizr:
58  aktualizr.wait_for_completion()
59 
60  # check the Primary update after reboot
61  result = director.get_install_result() and (target_rev == aktualizr.get_current_primary_image_info())
62  return result
63 
64 
65 if __name__ == "__main__":
66  logging.basicConfig(level=logging.INFO)
67 
68  parser = argparse.ArgumentParser(description='Test backend failure')
69  parser.add_argument('-b', '--build-dir', help='build directory', default='build')
70  parser.add_argument('-s', '--src-dir', help='source directory', default='.')
71 
72  input_params = parser.parse_args()
73 
74  KeyStore.base_dir = input_params.src_dir
75  initial_cwd = getcwd()
76  chdir(input_params.build_dir)
77 
78  test_suite = [
79  test_primary_ostree_secondary_fake_updates
80  ]
81 
82  test_suite_run_result = True
83  for test in test_suite:
84  logger.info('>>> Running {}...'.format(test.__name__))
85  test_run_result = test()
86  logger.info('>>> {}: {}\n'.format('OK' if test_run_result else 'FAILED', test.__name__))
87  test_suite_run_result = test_suite_run_result and test_run_result
88 
89  chdir(initial_cwd)
90  exit(0 if test_suite_run_result else 1)
91