Skip to content

Commit

Permalink
[FIO toup] aktualizr-lite: Use current target for status
Browse files Browse the repository at this point in the history
Now that we are tracking the installed target properly, we can use
getCurrent to make this easier and more informative.

Signed-off-by: Andy Doan <andy@foundries.io>
  • Loading branch information
doanac committed Jul 15, 2019
1 parent 9603eea commit aebd6f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/aktualizr_lite/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,41 @@ static std::shared_ptr<SotaUptaneClient> liteClient(Config &config, std::shared_
return client;
}

static void log_info_target(const std::string &prefix, const Config &config, const Uptane::Target &t) {
auto name = t.filename();
if (t.custom_version().length() > 0) {
name = t.custom_version();
}
LOG_INFO << prefix + name << "\tsha256:" << t.sha256Hash();
if (config.pacman.type == PackageManager::kOstreeDockerApp) {
bool shown = false;
auto apps = t.custom_data()["docker_apps"];
for (Json::ValueIterator i = apps.begin(); i != apps.end(); ++i) {
if (!shown) {
shown = true;
LOG_INFO << "\tDocker Apps:";
}
if ((*i).isObject() && (*i).isMember("filename")) {
LOG_INFO << "\t\t" << i.key().asString() << " -> " << (*i)["filename"].asString();
} else {
LOG_ERROR << "\t\tInvalid custom data for docker-app: " << i.key().asString();
}
}
}
}

static int status_main(Config &config, const bpo::variables_map &unused) {
(void)unused;
GObjectUniquePtr<OstreeSysroot> sysroot_smart = OstreeManager::LoadSysroot(config.pacman.sysroot);
OstreeDeployment *deployment = ostree_sysroot_get_booted_deployment(sysroot_smart.get());
if (deployment == nullptr) {
auto target = liteClient(config, nullptr)->getCurrent();

if (target == Uptane::Target::Unknown()) {
LOG_INFO << "No active deployment found";
} else {
LOG_INFO << "Active image is: " << ostree_deployment_get_csum(deployment);
auto name = target.filename();
if (target.custom_version().length() > 0) {
name = target.custom_version();
}
log_info_target("Active image is: ", config, target);
}
return 0;
}
Expand All @@ -95,26 +122,7 @@ static int list_main(Config &config, const bpo::variables_map &unused) {
for (auto &t : client->allTargets()) {
for (auto const &it : t.hardwareIds()) {
if (it == hwid) {
auto name = t.filename();
if (t.custom_version().length() > 0) {
name = t.custom_version();
}
LOG_INFO << name << "\tsha256:" << t.sha256Hash();
if (config.pacman.type == PackageManager::kOstreeDockerApp) {
bool shown = false;
auto apps = t.custom_data()["docker_apps"];
for (Json::ValueIterator i = apps.begin(); i != apps.end(); ++i) {
if (!shown) {
shown = true;
LOG_INFO << "\tDocker Apps:";
}
if ((*i).isObject() && (*i).isMember("filename")) {
LOG_INFO << "\t\t" << i.key().asString() << " -> " << (*i)["filename"].asString();
} else {
LOG_ERROR << "\t\tInvalid custom data for docker-app: " << i.key().asString();
}
}
}
log_info_target("", config, t);
break;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/aktualizr_lite/test_lite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ OSTREE_HASH=$sha LD_PRELOAD=$mock_ostree $valgrind $aklite --loglevel 1 -c $sota
ostree admin status

OSTREE_HASH=$sha LD_PRELOAD=$mock_ostree $valgrind $aklite --loglevel 1 -c $sota_dir/sota.toml update | grep "Updating to: Target(zlast"

out=$(OSTREE_HASH="$sha" LD_PRELOAD=$mock_ostree $valgrind $aklite --loglevel 1 -c $sota_dir/sota.toml status)
if [[ ! "$out" =~ "Active image is: zlast sha256:$sha" ]] ; then
echo "ERROR: status incorrect:"
echo $out
exit 1
fi

0 comments on commit aebd6f6

Please sign in to comment.