1 #include "packagemanagerfake.h"
3 #include "utilities/fault_injection.h"
5 Json::Value PackageManagerFake::getInstalledPackages()
const {
6 Json::Value packages(Json::arrayValue);
8 package[
"name"] =
"fake-package";
9 package[
"version"] =
"1.0";
10 packages.append(package);
15 boost::optional<Uptane::Target> current_version;
16 storage_->loadPrimaryInstalledVersions(¤t_version,
nullptr);
18 if (!!current_version) {
19 return *current_version;
22 return Uptane::Target::Unknown();
29 if (fiu_fail(
"fake_package_install") != 0) {
30 std::string failure_cause = fault_injection_last_info();
31 if (failure_cause.empty()) {
34 LOG_DEBUG <<
"Causing installation failure with message: " << failure_cause;
38 if (config.fake_need_reboot) {
40 if (bootloader_ !=
nullptr) {
41 bootloader_->rebootFlagSet();
49 void PackageManagerFake::completeInstall()
const {
50 LOG_INFO <<
"Emulating a system reboot";
51 bootloader_->reboot(
true);
55 boost::optional<Uptane::Target> pending_version;
56 storage_->loadPrimaryInstalledVersions(
nullptr, &pending_version);
58 if (!pending_version) {
59 throw std::runtime_error(
"No pending update, nothing to finalize");
64 if (target.MatchTarget(*pending_version)) {
65 if (fiu_fail(
"fake_install_finalization_failure") != 0) {
66 const std::string failure_cause = fault_injection_last_info();
67 if (failure_cause.empty()) {
72 "Failed to finalize the pending update installation");
92 if (fiu_fail(
"fake_package_download") != 0) {
93 const std::string failure_cause = fault_injection_last_info();
94 if (!failure_cause.empty()) {
95 LOG_WARNING <<
"Error while downloading a target: " << failure_cause;
97 LOG_WARNING <<
"Error while downloading a target: forced failure";
102 return PackageManagerInterface::fetchTarget(target, fetcher, keys, progress_cb, token);