1 #include "libaktualizr/packagemanagerfactory.h"
3 #include "logging/logging.h"
4 #include "packagemanagerfake.h"
5 #include "storage/invstorage.h"
6 #include "utilities/fault_injection.h"
10 Json::Value PackageManagerFake::getInstalledPackages()
const {
11 Json::Value packages(Json::arrayValue);
13 package[
"name"] =
"fake-package";
14 package[
"version"] =
"1.0";
15 packages.append(package);
20 boost::optional<Uptane::Target> current_version;
21 storage_->loadPrimaryInstalledVersions(¤t_version,
nullptr);
23 if (!!current_version) {
24 return *current_version;
27 return Uptane::Target::Unknown();
34 if (fiu_fail(
"fake_package_install") != 0) {
35 std::string failure_cause = fault_injection_last_info();
36 if (failure_cause.empty()) {
39 LOG_DEBUG <<
"Causing installation failure with message: " << failure_cause;
43 if (config.fake_need_reboot) {
45 if (bootloader_ !=
nullptr) {
46 bootloader_->rebootFlagSet();
54 void PackageManagerFake::completeInstall()
const {
55 LOG_INFO <<
"Emulating a system reboot";
56 bootloader_->reboot(
true);
60 if (config.fake_need_reboot && !bootloader_->rebootDetected()) {
62 "Reboot is required for the pending update application");
65 boost::optional<Uptane::Target> pending_version;
66 storage_->loadPrimaryInstalledVersions(
nullptr, &pending_version);
68 if (!pending_version) {
69 throw std::runtime_error(
"No pending update, nothing to finalize");
74 if (target.MatchTarget(*pending_version)) {
75 if (fiu_fail(
"fake_install_finalization_failure") != 0) {
76 const std::string failure_cause = fault_injection_last_info();
77 if (failure_cause.empty()) {
82 "Failed to finalize the pending update installation");
93 if (config.fake_need_reboot) {
94 bootloader_->rebootFlagClear();
105 if (fiu_fail(
"fake_package_download") != 0) {
106 const std::string failure_cause = fault_injection_last_info();
107 if (!failure_cause.empty()) {
108 LOG_WARNING <<
"Error while downloading a target: " << failure_cause;
110 LOG_WARNING <<
"Error while downloading a target: forced failure";
118 LOG_ERROR <<
"Cannot download OSTree target " << target.filename() <<
" with the fake package manager!";
122 return PackageManagerInterface::fetchTarget(target, fetcher, keys, progress_cb, token);