Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Added API to direct update raw_roport in the installation result
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Bushko <[email protected]>
  • Loading branch information
kbushgit committed Apr 6, 2020
1 parent ef71c30 commit 2575a2e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libaktualizr/storage/invstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class INvStorage {
std::vector<std::pair<Uptane::EcuSerial, data::InstallationResult>>* 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;
Expand Down
10 changes: 10 additions & 0 deletions src/libaktualizr/storage/sqlstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>("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();
Expand Down
1 change: 1 addition & 0 deletions src/libaktualizr/storage/sqlstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class SQLStorage : public SQLStorageBase, public INvStorage {
std::vector<std::pair<Uptane::EcuSerial, data::InstallationResult>>* 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;
Expand Down
3 changes: 3 additions & 0 deletions src/libaktualizr/storage/storage_common_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 2575a2e

Please sign in to comment.