Skip to content

Commit

Permalink
rootfsmanager: Add storage usage if pull successful
Browse files Browse the repository at this point in the history
Get, print, and attach to the `EcuDownloadCompleted` event storage usage
info if an ostree pull is successful.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Sep 2, 2023
1 parent 46b4ee7 commit fa57ced
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/composeappmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ DownloadResult ComposeAppManager::Download(const TufTarget& target) {
return ostree_download_res;
}

DownloadResult res{DownloadResult::Status::Ok, ""};
DownloadResult res{ostree_download_res};
const Uptane::Target uptane_target{Target::fromTufTarget(target)};

if (cfg_.force_update) {
Expand Down
10 changes: 9 additions & 1 deletion src/rootfstreemanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ DownloadResult RootfsTreeManager::Download(const TufTarget& target) {
LOG_INFO << "Fetching ostree commit " + target.Sha256Hash() + " from " + remote.baseUrl;
pull_err = OstreeManager::pull(config.sysroot, remote.baseUrl, keys_, Target::fromTufTarget(target), nullptr,
prog_cb, remote.isRemoteSet ? nullptr : remote.name.c_str(), remote.headers);

storage::Volume::UsageInfo post_pull_usage_info{getUsageInfo()};
if (post_pull_usage_info.isOk()) {
LOG_INFO << "Post pull storage usage info; " << post_pull_usage_info;
} else {
LOG_ERROR << "Failed to obtain storage usage statistic: " << post_pull_usage_info.err;
}
if (pull_err.isSuccess()) {
res = {DownloadResult::Status::Ok, ""};
res = {DownloadResult::Status::Ok,
"before ostree pull; " + pre_pull_usage_info.str() + "\nafter ostree pull; " + post_pull_usage_info.str()};
break;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/liteclienttest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ class ClientTest :virtual public ::testing::Test {
return ostree_repo_.getDeltaSize(to.custom_data()["delta-stats"]["sha256"].asString(), from.sha256Hash(), to.sha256Hash());
}

std::string getEventContext(const std::string& ev_id) {
for (const auto& ev: device_gateway_.getEvents()) {
if (ev_id == ev["eventType"]["id"].asString()) {
return ev["event"]["details"].asString();
}
}
return "";
}

protected:
static const std::string branch;
static const std::string hw_id;
Expand Down
9 changes: 5 additions & 4 deletions tests/nospace_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ TEST_F(NoSpaceTest, OstreeUpdateNoSpaceIfStaticDeltaStats) {
<< ", available: " << usage_info.available;
update(*client, getInitialTarget(), new_target, data::ResultCode::Numeric::kDownloadFailed,
{DownloadResult::Status::DownloadFailed_NoSpace, "Insufficient storage available"});
const auto events{device_gateway_.getEvents()};
const std::string event_err_msg{events[events.size() - 1]["event"]["details"].asString()};
const std::string event_err_msg{getEventContext("EcuDownloadCompleted")};
ASSERT_TRUE(std::string::npos != event_err_msg.find(expected_msg.str())) << event_err_msg;
ASSERT_TRUE(std::string::npos !=
event_err_msg.find(OSTree::Sysroot::Config::ReservedStorageSpacePercentageDeltaParamName))
Expand All @@ -341,8 +340,7 @@ TEST_F(NoSpaceTest, OstreeUpdateNoSpaceIfStaticDeltaStats) {
<< ", available: " << usage_info.available;
update(*client, getInitialTarget(), new_target, data::ResultCode::Numeric::kDownloadFailed,
{DownloadResult::Status::DownloadFailed_NoSpace, "Insufficient storage available"});
const auto events{device_gateway_.getEvents()};
const std::string event_err_msg{events[events.size() - 1]["event"]["details"].asString()};
const std::string event_err_msg{getEventContext("EcuDownloadCompleted")};
ASSERT_TRUE(std::string::npos != event_err_msg.find(expected_msg.str())) << event_err_msg;
ASSERT_TRUE(std::string::npos !=
event_err_msg.find(OSTree::Sysroot::Config::ReservedStorageSpacePercentageOstreeParamName))
Expand All @@ -355,6 +353,9 @@ TEST_F(NoSpaceTest, OstreeUpdateNoSpaceIfStaticDeltaStats) {
update(*client, getInitialTarget(), new_target);
reboot(client);
ASSERT_TRUE(targetsMatch(client->getCurrent(), new_target));
const std::string msg{getEventContext("EcuDownloadCompleted")};
ASSERT_TRUE(std::string::npos != msg.find("before ostree pull")) << msg;
ASSERT_TRUE(std::string::npos != msg.find("after ostree pull")) << msg;
}
UnsetFreeBlockNumb();
}
Expand Down

0 comments on commit fa57ced

Please sign in to comment.