1 #include "packagemanagerfake.h"
2 #include "packagemanagerfactory.h"
4 #include "utilities/fault_injection.h"
8 Json::Value PackageManagerFake::getInstalledPackages()
const {
9 Json::Value packages(Json::arrayValue);
11 package[
"name"] =
"fake-package";
12 package[
"version"] =
"1.0";
13 packages.append(package);
18 boost::optional<Uptane::Target> current_version;
19 storage_->loadPrimaryInstalledVersions(¤t_version,
nullptr);
21 if (!!current_version) {
22 return *current_version;
25 return Uptane::Target::Unknown();
32 if (fiu_fail(
"fake_package_install") != 0) {
33 std::string failure_cause = fault_injection_last_info();
34 if (failure_cause.empty()) {
37 LOG_DEBUG <<
"Causing installation failure with message: " << failure_cause;
41 if (config.fake_need_reboot) {
43 if (bootloader_ !=
nullptr) {
44 bootloader_->rebootFlagSet();
52 void PackageManagerFake::completeInstall()
const {
53 LOG_INFO <<
"Emulating a system reboot";
54 bootloader_->reboot(
true);
58 if (config.fake_need_reboot && !bootloader_->rebootDetected()) {
60 "Reboot is required for the pending update application");
63 boost::optional<Uptane::Target> pending_version;
64 storage_->loadPrimaryInstalledVersions(
nullptr, &pending_version);
66 if (!pending_version) {
67 throw std::runtime_error(
"No pending update, nothing to finalize");
72 if (target.MatchTarget(*pending_version)) {
73 if (fiu_fail(
"fake_install_finalization_failure") != 0) {
74 const std::string failure_cause = fault_injection_last_info();
75 if (failure_cause.empty()) {
80 "Failed to finalize the pending update installation");
91 if (config.fake_need_reboot) {
92 bootloader_->rebootFlagClear();
103 if (fiu_fail(
"fake_package_download") != 0) {
104 const std::string failure_cause = fault_injection_last_info();
105 if (!failure_cause.empty()) {
106 LOG_WARNING <<
"Error while downloading a target: " << failure_cause;
108 LOG_WARNING <<
"Error while downloading a target: forced failure";
113 return PackageManagerInterface::fetchTarget(target, fetcher, keys, progress_cb, token);