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

Commit

Permalink
OTA-2540: Print currently installed and pending image's sha256 and fi…
Browse files Browse the repository at this point in the history
…lename on secondary ECUs

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
Mike Sul committed May 6, 2019
1 parent cf9c980 commit 0391fa4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
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 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.
*/
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 != 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";
}
}
}
}

Expand Down

0 comments on commit 0391fa4

Please sign in to comment.