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

Commit

Permalink
aktualizr_primary: add cmdline param for custom hwinfo file
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Smirnov <[email protected]>
  • Loading branch information
Eugene Smirnov committed Apr 15, 2020
1 parent 2850ae5 commit 4ed0f55
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/aktualizr_primary/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ bpo::variables_map parseOptions(int argc, char *argv[]) {
("primary-ecu-serial", bpo::value<std::string>(), "serial number of Primary ECU")
("primary-ecu-hardware-id", bpo::value<std::string>(), "hardware ID of Primary ECU")
("secondary-config-file", bpo::value<boost::filesystem::path>(), "secondary ECUs configuration file")
("campaign-id", bpo::value<std::string>(), "ID of the campaign to act on");
("campaign-id", bpo::value<std::string>(), "ID of the campaign to act on")
("hwinfo-file", bpo::value<boost::filesystem::path>(), "custom hardware information JSON file");
// clang-format on

// consider the first positional argument as the aktualizr run mode
Expand Down Expand Up @@ -147,6 +148,16 @@ int main(int argc, char *argv[]) {
SigHandler::signal(SIGINT);
SigHandler::signal(SIGTERM);

Json::Value hwinfo;
if (commandline_map.count("hwinfo-file") != 0) {
auto file = commandline_map["hwinfo-file"].as<boost::filesystem::path>();
hwinfo = Utils::parseJSONFile(file);
if (hwinfo.empty()) {
LOG_ERROR << file << " is not a valid JSON file";
return EXIT_FAILURE;
}
}

std::string run_mode;
if (commandline_map.count("run-mode") != 0) {
run_mode = commandline_map["run-mode"].as<std::string>();
Expand All @@ -161,7 +172,7 @@ int main(int argc, char *argv[]) {
aktualizr.CampaignControl(commandline_map["campaign-id"].as<std::string>(), campaign::cmdFromName(run_mode))
.get();
} else if (run_mode == "check") {
aktualizr.SendDeviceData().get();
aktualizr.SendDeviceData(hwinfo).get();
aktualizr.CheckUpdates().get();
} else if (run_mode == "download") {
result::UpdateCheck update_result = aktualizr.CheckUpdates().get();
Expand All @@ -170,14 +181,14 @@ int main(int argc, char *argv[]) {
result::UpdateCheck update_result = aktualizr.CheckUpdates().get();
aktualizr.Install(update_result.updates).get();
} else if (run_mode == "once") {
aktualizr.SendDeviceData().get();
aktualizr.SendDeviceData(hwinfo).get();
aktualizr.UptaneCycle();
} else {
boost::signals2::connection ac_conn =
aktualizr.SetSignalHandler(std::bind(targets_autoclean_cb, std::ref(aktualizr), std::placeholders::_1));

try {
aktualizr.RunForever().get();
aktualizr.RunForever(hwinfo).get();
} catch (const std::exception &ex) {
LOG_ERROR << ex.what();
}
Expand Down
6 changes: 3 additions & 3 deletions src/libaktualizr/primary/aktualizr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ bool Aktualizr::UptaneCycle() {
return true;
}

std::future<void> Aktualizr::RunForever() {
std::future<void> future = std::async(std::launch::async, [&]() {
SendDeviceData().get();
std::future<void> Aktualizr::RunForever(const Json::Value &custom_hwinfo) {
std::future<void> future = std::async(std::launch::async, [this, custom_hwinfo]() {
SendDeviceData(custom_hwinfo).get();

std::unique_lock<std::mutex> l(exit_cond_.m);
while (true) {
Expand Down
3 changes: 2 additions & 1 deletion src/libaktualizr/primary/aktualizr.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ class Aktualizr {

/**
* Asynchronously run aktualizr indefinitely until Shutdown is called.
* @param custom_hwinfo if not empty will be sent to the backend instead of `lshw` output
* @return Empty std::future object
*/
std::future<void> RunForever();
std::future<void> RunForever(const Json::Value& custom_hwinfo = Json::nullValue);

/**
* Shuts down currently running `RunForever()` method
Expand Down
2 changes: 1 addition & 1 deletion src/libaktualizr/primary/sotauptaneclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ data::InstallationResult SotaUptaneClient::PackageInstallSetResult(const Uptane:

void SotaUptaneClient::reportHwInfo(const Json::Value &custom_hwinfo) {
Json::Value system_info;

if (custom_hwinfo.empty()) {
system_info = Utils::getHardwareInfo();
if (system_info.empty()) {
Expand Down

0 comments on commit 4ed0f55

Please sign in to comment.