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,
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
74 @with_uptane_backend()
78 @with_secondary(start=
False)
79 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
80 def test_secondary_ostree_update_if_metadata_expires(uptane_repo, secondary, aktualizr, director, sysroot, treehub, **kwargs):
81 target_rev = treehub.revision
82 expires_within_sec = 10
85 uptane_repo.add_ostree_target(secondary.id, target_rev, expires_within_sec=expires_within_sec)
86 start_time = time.time()
90 aktualizr.wait_for_completion()
93 pending_rev = aktualizr.get_current_pending_image_info(secondary.id)
94 if pending_rev != target_rev:
95 logger.error(
"Pending version {} != the target version {}".format(pending_rev, target_rev))
99 time.sleep(max(0, expires_within_sec - (time.time() - start_time)))
102 sysroot.update_revision(pending_rev)
103 secondary.emulate_reboot()
110 aktualizr.wait_for_completion()
113 if not director.get_install_result():
114 logger.error(
"Installation result is not successful")
117 installed_rev = aktualizr.get_current_image_info(secondary.id)
118 if installed_rev != target_rev:
119 logger.error(
"Installed version {} != the target version {}".format(installed_rev, target_rev))
126 Test update of Primary's OSTree repo if an OSTree target metadata are expired
128 Metadata are valid at the moment of a new OSTree revision installation,
129 but are expired after that and before Primary is rebooted,
130 we still expect that the installed update is applied in this case
132 @with_uptane_backend()
136 @with_aktualizr(start=
False, run_mode=
'once', output_logs=
True)
137 def test_primary_ostree_update_if_metadata_expires(uptane_repo, aktualizr, director, sysroot, treehub, **kwargs):
138 target_rev = treehub.revision
139 expires_within_sec = 10
142 uptane_repo.add_ostree_target(aktualizr.id, target_rev, expires_within_sec=expires_within_sec)
143 start_time = time.time()
146 aktualizr.wait_for_completion()
149 pending_rev = aktualizr.get_primary_pending_version()
150 if pending_rev != target_rev:
151 logger.error(
"Pending version {} != the target version {}".format(pending_rev, target_rev))
155 time.sleep(max(0, expires_within_sec - (time.time() - start_time)))
158 sysroot.update_revision(pending_rev)
159 aktualizr.emulate_reboot()
162 aktualizr.wait_for_completion()
165 if not director.get_install_result():
166 logger.error(
"Installation result is not successful")
169 installed_rev = aktualizr.get_current_primary_image_info()
170 if installed_rev != target_rev:
171 logger.error(
"Installed version {} != the target version {}".format(installed_rev, target_rev))
177 if __name__ ==
"__main__":
178 logging.basicConfig(level=logging.INFO)
180 parser = argparse.ArgumentParser(description=
'Test backend failure')
181 parser.add_argument(
'-b',
'--build-dir', help=
'build directory', default=
'build')
182 parser.add_argument(
'-s',
'--src-dir', help=
'source directory', default=
'.')
184 input_params = parser.parse_args()
186 KeyStore.base_dir = input_params.src_dir
187 initial_cwd = getcwd()
188 chdir(input_params.build_dir)
191 test_primary_ostree_secondary_file_updates,
192 test_secondary_ostree_update_if_metadata_expires,
193 test_primary_ostree_update_if_metadata_expires
196 with TestRunner(test_suite)
as runner:
197 test_suite_run_result = runner.run()
200 exit(0
if test_suite_run_result
else 1)