diff --git a/actions.md b/actions.md index 25bbd2dbfa..5ab5f163d0 100644 --- a/actions.md +++ b/actions.md @@ -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) diff --git a/src/aktualizr_info/aktualizr_info_test.cc b/src/aktualizr_info/aktualizr_info_test.cc index cc97ef8c51..e7a09183a6 100644 --- a/src/aktualizr_info/aktualizr_info_test.cc +++ b/src/aktualizr_info/aktualizr_info_test.cc @@ -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 version: " + 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 version: " + 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)}}); + + aktualizr_info_process_.run(); + ASSERT_FALSE(aktualizr_info_output.empty()); + EXPECT_NE(aktualizr_info_output.find("undetermined image version"), std::string::npos); +} + /** * Print device name only for scripting purposes. */ diff --git a/src/aktualizr_info/main.cc b/src/aktualizr_info/main.cc index 2d734e9fcc..038daff61a 100644 --- a/src/aktualizr_info/main.cc +++ b/src/aktualizr_info/main.cc @@ -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 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, + ¤t_version, &pending_version); + + if (load_installed_version_res != true || + (current_version >= installed_targets.size() && pending_version >= installed_targets.size())) { + std::cout << " undetermined image version\n"; + } else { + if (installed_targets.size() > current_version) { + std::cout << " installed image version: " << 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 version: " << installed_targets[pending_version].sha256Hash() << "\n"; + std::cout << " pending image filename: " << installed_targets[pending_version].filename() << "\n"; + } + } } }