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

OTA-2540: Print installed and pending version on Secondary #1201

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ These tools all link with libaktualizr, although they do not necessary use the A
- [x] Print TLS credentials (aktualizr_info_test.cc)
- [x] Print primary ECU keys (aktualizr_info_test.cc)
- [x] Print primary ECU current and pending versions (aktualizr_info_test.cc)
- [x] Print secondary ECU current and pending versions (aktualizr_info_test.cc)
- [x] Print device name only for scripting purposes (aktualizr_info_test.cc)
- [x] Print delegations (aktualizr_info_test.cc)

Expand Down
48 changes: 48 additions & 0 deletions src/aktualizr_info/aktualizr_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,54 @@ TEST_F(AktualizrInfoTest, PrintPrimaryEcuCurrentAndPendingVersionsNegative) {
EXPECT_EQ(aktualizr_info_output.find("Pending primary ecu version:"), std::string::npos);
}

/**
* Verifies aktualizr-info output of Secondary ECU's current and pending versions
*
* Checks actions:
*
* - [x] Print secondary ECU current and pending versions
*/
TEST_F(AktualizrInfoTest, PrintSecondaryEcuCurrentAndPendingVersions) {
const std::string secondary_ecu_serial = "c6998d3e-2a68-4ac2-817e-4ea6ef87d21f";
const std::string secondary_ecu_id = "secondary-hdwr-af250269-bd6f-4148-9426-4101df7f613a";
const std::string secondary_ecu_filename = "secondary.file";
const std::string secondary_ecu_filename_update = "secondary.file.update";
const std::string current_ecu_version = "639a4e39-e6ba-4832-ace4-8b12cf20d562";
const std::string pending_ecu_version = "9636753d-2a09-4c80-8b25-64b2c2d0c4df";

db_storage_->storeEcuSerials(
{{Uptane::EcuSerial(primary_ecu_serial), Uptane::HardwareIdentifier(primary_ecu_id)},
{Uptane::EcuSerial(secondary_ecu_serial), Uptane::HardwareIdentifier(secondary_ecu_id)}});
db_storage_->storeEcuRegistered();

db_storage_->saveInstalledVersion(secondary_ecu_serial,
{secondary_ecu_filename, {{Uptane::Hash::Type::kSha256, current_ecu_version}}, 1},
InstalledVersionUpdateMode::kCurrent);

db_storage_->saveInstalledVersion(
secondary_ecu_serial, {secondary_ecu_filename_update, {{Uptane::Hash::Type::kSha256, pending_ecu_version}}, 1},
InstalledVersionUpdateMode::kPending);

aktualizr_info_process_.run();
ASSERT_FALSE(aktualizr_info_output.empty());

EXPECT_NE(aktualizr_info_output.find("installed image hash: " + current_ecu_version), std::string::npos);
EXPECT_NE(aktualizr_info_output.find("installed image filename: " + secondary_ecu_filename), std::string::npos);
EXPECT_NE(aktualizr_info_output.find("pending image hash: " + pending_ecu_version), std::string::npos);
EXPECT_NE(aktualizr_info_output.find("pending image filename: " + secondary_ecu_filename_update), std::string::npos);

// negative test, no any installed images
db_storage_->clearInstalledVersions();
db_storage_->clearEcuSerials();
db_storage_->storeEcuSerials(
{{Uptane::EcuSerial(primary_ecu_serial), Uptane::HardwareIdentifier(primary_ecu_id)},
{Uptane::EcuSerial(secondary_ecu_serial), Uptane::HardwareIdentifier(secondary_ecu_id)}});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the negative test too!


aktualizr_info_process_.run();
ASSERT_FALSE(aktualizr_info_output.empty());
EXPECT_NE(aktualizr_info_output.find("no details about installed nor pending images"), std::string::npos);
}

/**
* Print device name only for scripting purposes.
*/
Expand Down
21 changes: 21 additions & 0 deletions src/aktualizr_info/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ int main(int argc, char **argv) {
for (; it != serials.end(); ++it) {
std::cout << secondary_number++ << ") serial ID: " << it->first << std::endl;
std::cout << " hardware ID: " << it->second << std::endl;

std::vector<Uptane::Target> installed_targets;
size_t current_version = SIZE_MAX;
size_t pending_version = SIZE_MAX;

auto load_installed_version_res = storage->loadInstalledVersions((it->first).ToString(), &installed_targets,
&current_version, &pending_version);

if (!load_installed_version_res ||
(current_version >= installed_targets.size() && pending_version >= installed_targets.size())) {
std::cout << " no details about installed nor pending images\n";
} else {
if (installed_targets.size() > current_version) {
std::cout << " installed image hash: " << installed_targets[current_version].sha256Hash() << "\n";
std::cout << " installed image filename: " << installed_targets[current_version].filename() << "\n";
}
if (installed_targets.size() > pending_version) {
std::cout << " pending image hash: " << installed_targets[pending_version].sha256Hash() << "\n";
std::cout << " pending image filename: " << installed_targets[pending_version].filename() << "\n";
}
}
}
}

Expand Down