diff --git a/src/libaktualizr/storage/invstorage.h b/src/libaktualizr/storage/invstorage.h index 122fb6482c..7b5fad26a0 100644 --- a/src/libaktualizr/storage/invstorage.h +++ b/src/libaktualizr/storage/invstorage.h @@ -204,6 +204,7 @@ class INvStorage { std::vector>* results) = 0; virtual void storeDeviceInstallationResult(const data::InstallationResult& result, const std::string& raw_report, const std::string& correlation_id) = 0; + virtual bool storeDeviceInstallationRawReport(const std::string& raw_report) = 0; virtual bool loadDeviceInstallationResult(data::InstallationResult* result, std::string* raw_report, std::string* correlation_id) = 0; virtual void clearInstallationResults() = 0; diff --git a/src/libaktualizr/storage/sqlstorage.cc b/src/libaktualizr/storage/sqlstorage.cc index 0e04577674..1c4a8a1aca 100644 --- a/src/libaktualizr/storage/sqlstorage.cc +++ b/src/libaktualizr/storage/sqlstorage.cc @@ -1519,6 +1519,16 @@ void SQLStorage::storeDeviceInstallationResult(const data::InstallationResult& r } } +bool SQLStorage::storeDeviceInstallationRawReport(const std::string& raw_report) { + SQLite3Guard db = dbConnection(); + auto statement = db.prepareStatement("UPDATE device_installation_result SET raw_report=?;", raw_report); + if (statement.step() != SQLITE_DONE) { + LOG_ERROR << "Can't set device raw report result: " << db.errmsg(); + return false; + } + return true; +} + bool SQLStorage::loadDeviceInstallationResult(data::InstallationResult* result, std::string* raw_report, std::string* correlation_id) { SQLite3Guard db = dbConnection(); diff --git a/src/libaktualizr/storage/sqlstorage.h b/src/libaktualizr/storage/sqlstorage.h index bb8e87ded8..8b981d78ba 100644 --- a/src/libaktualizr/storage/sqlstorage.h +++ b/src/libaktualizr/storage/sqlstorage.h @@ -87,6 +87,7 @@ class SQLStorage : public SQLStorageBase, public INvStorage { std::vector>* results) override; void storeDeviceInstallationResult(const data::InstallationResult& result, const std::string& raw_report, const std::string& correlation_id) override; + bool storeDeviceInstallationRawReport(const std::string& raw_report) override; bool loadDeviceInstallationResult(data::InstallationResult* result, std::string* raw_report, std::string* correlation_id) override; void saveEcuReportCounter(const Uptane::EcuSerial& ecu_serial, int64_t counter) override; diff --git a/src/libaktualizr/storage/storage_common_test.cc b/src/libaktualizr/storage/storage_common_test.cc index e2d7f2c230..b879228db1 100644 --- a/src/libaktualizr/storage/storage_common_test.cc +++ b/src/libaktualizr/storage/storage_common_test.cc @@ -458,12 +458,15 @@ TEST(storage, load_store_installation_results) { EXPECT_EQ(dev_res.result_code.num_code, data::ResultCode::Numeric::kGeneralError); EXPECT_EQ(report, "raw"); EXPECT_EQ(correlation_id, "corrid"); + EXPECT_TRUE(storage->storeDeviceInstallationRawReport("user's raw report")); storage->clearInstallationResults(); res.clear(); EXPECT_FALSE(storage->loadEcuInstallationResults(&res)); EXPECT_EQ(res.size(), 0); EXPECT_FALSE(storage->loadDeviceInstallationResult(&dev_res, &report, &correlation_id)); + EXPECT_FALSE(storage->storeDeviceInstallationRawReport( + "This call will return a negative value since the installation report was cleaned!")); } /* Load and store targets. */