7 from os
import getcwd, chdir
9 from test_fixtures
import KeyStore, with_aktualizr, with_uptane_backend, with_secondary, with_director, with_imagerepo,\
10 with_sysroot, with_treehub, TestRunner
13 logger = logging.getLogger(__file__)
17 Test update of Primary and Secondary if their package manager differs, `ostree`
18 and binary (`none` or `fake`) respectively
20 Aktualizr/Primary's package manager is set to `ostree`
21 Secondary's package manager is set to `fake` which means a file/binary update
22 Primary goal is to verify whether aktualizr succeeds with a binary/fake update of secondary
23 while aktualizr/primary is configured with ostree package manager
25 @with_uptane_backend(start_generic_server=
True)
26 @with_secondary(start=
True)
30 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
31 def test_primary_ostree_secondary_file_updates(uptane_repo, secondary, aktualizr, director, sysroot,
32 treehub, uptane_server, **kwargs):
33 target_rev = treehub.revision
35 uptane_repo.add_ostree_target(aktualizr.id, target_rev)
37 secondary_update_hash = uptane_repo.add_image(secondary.id,
"secondary-update.bin")
40 aktualizr.wait_for_completion()
43 pending_rev = aktualizr.get_primary_pending_version()
44 if pending_rev != target_rev:
45 logger.error(
"Pending version {} != the target version {}".format(pending_rev, target_rev))
49 current_secondary_image_hash = aktualizr.get_current_image_info(secondary.id)
50 if current_secondary_image_hash != secondary_update_hash:
51 logger.error(
"Current secondary image {} != expected image {}".format(current_secondary_image_hash,
52 secondary_update_hash))
56 sysroot.update_revision(pending_rev)
57 aktualizr.emulate_reboot()
60 aktualizr.wait_for_completion()
63 result = director.get_install_result()
and (target_rev == aktualizr.get_current_primary_image_info())
68 Test update of Secondary's ostree repo if an ostree target metadata are expired
70 Metadata are valid at the moment of a new ostree revision installation,
71 but are expired after that and before Secondary is rebooted,
72 we still expect that the installed update is applied in this case
75 @with_uptane_backend()
78 @with_secondary(start=
False)
79 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
80 def test_secodary_ostree_update_if_metadata_expires(uptane_repo, secondary, aktualizr, treehub, sysroot, director, **kwargs):
81 target_rev = treehub.revision
82 expires_within_sec = 10
84 uptane_repo.add_ostree_target(secondary.id, target_rev, expires_within_sec=expires_within_sec)
85 start_time = time.time()
89 aktualizr.wait_for_completion()
91 pending_rev = aktualizr.get_current_pending_image_info(secondary.id)
93 if pending_rev != target_rev:
94 logger.error(
"Pending version {} != the target one {}".format(pending_rev, target_rev))
98 time.sleep(max(0, expires_within_sec - (time.time() - start_time)))
100 sysroot.update_revision(pending_rev)
101 secondary.emulate_reboot()
105 aktualizr.wait_for_completion()
107 if not director.get_install_result():
108 logger.error(
"Installation result is not successful")
111 installed_rev = aktualizr.get_current_image_info(secondary.id)
113 if installed_rev != target_rev:
114 logger.error(
"Installed version {} != the target one {}".format(installed_rev, target_rev))
121 Test update of Primary's ostree repo if an ostree target metadata are expired
123 Metadata are valid at the moment of a new ostree revision installation,
124 but are expired after that and before Primary is rebooted,
125 we still expect that the installed update is applied in this case
127 @with_uptane_backend(start_generic_server=
True)
131 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
132 def test_primary_ostree_update_if_metadata_expires(uptane_repo, aktualizr, director, sysroot, treehub, uptane_server, **kwargs):
133 target_rev = treehub.revision
134 expires_within_sec = 10
137 uptane_repo.add_ostree_target(aktualizr.id, target_rev, expires_within_sec=expires_within_sec)
138 start_time = time.time()
141 aktualizr.wait_for_completion()
144 pending_rev = aktualizr.get_primary_pending_version()
145 if pending_rev != target_rev:
146 logger.error(
"Pending version {} != the target version {}".format(pending_rev, target_rev))
150 time.sleep(max(0, expires_within_sec - (time.time() - start_time)))
153 sysroot.update_revision(pending_rev)
154 aktualizr.emulate_reboot()
157 aktualizr.wait_for_completion()
160 result = director.get_install_result()
and (target_rev == aktualizr.get_current_primary_image_info())
164 if __name__ ==
"__main__":
165 logging.basicConfig(level=logging.INFO)
167 parser = argparse.ArgumentParser(description=
'Test backend failure')
168 parser.add_argument(
'-b',
'--build-dir', help=
'build directory', default=
'build')
169 parser.add_argument(
'-s',
'--src-dir', help=
'source directory', default=
'.')
171 input_params = parser.parse_args()
173 KeyStore.base_dir = input_params.src_dir
174 initial_cwd = getcwd()
175 chdir(input_params.build_dir)
178 test_primary_ostree_secondary_file_updates,
179 test_secodary_ostree_update_if_metadata_expires,
180 test_primary_ostree_update_if_metadata_expires
183 test_suite_run_result = TestRunner(test_suite).run()
186 exit(0
if test_suite_run_result
else 1)