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

Commit

Permalink
Merge pull request #1609 from advancedtelematic/fix/OTA-4389/aktualiz…
Browse files Browse the repository at this point in the history
…r-secondary_logging

Adjust some log in aktualizr_secondary
  • Loading branch information
pattivacek authored Mar 24, 2020
2 parents fdafed8 + f02c298 commit 4d9b41e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/aktualizr_secondary/aktualizr_secondary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ AktualizrSecondary::AktualizrSecondary(AktualizrSecondaryConfig config, std::sha
initPendingTargetIfAny();

if (hasPendingUpdate()) {
LOG_INFO << "Found a pending target to be applied.";
// TODO(OTA-4545): refactor this to make it simpler as we don't need to persist/store
// an installation status of each ECU but store it just for a given secondary ECU
std::vector<Uptane::Target> installed_versions;
Expand Down Expand Up @@ -101,6 +102,7 @@ bool AktualizrSecondary::sendFirmware(const std::string& firmware) {
return false;
}

LOG_INFO << "Download firmware " << pending_target_.filename() << " successful.";
return true;
}

Expand Down Expand Up @@ -198,6 +200,7 @@ bool AktualizrSecondary::doFullVerification(const Metadata& metadata) {

pending_target_ = targetsForThisEcu[0];

LOG_DEBUG << "Metadata verified, new update found.";
return true;
}

Expand Down Expand Up @@ -246,7 +249,7 @@ void AktualizrSecondary::uptaneInitialize() {

void AktualizrSecondary::initPendingTargetIfAny() {
if (!director_repo_.checkMetaOffline(*storage_)) {
LOG_INFO << "No valid and pending Director targets to be applied";
LOG_INFO << "No valid metadata found in storage.";
return;
}

Expand All @@ -262,6 +265,5 @@ void AktualizrSecondary::initPendingTargetIfAny() {
return;
}

LOG_INFO << "There is a valid and pending Director target to be applied";
pending_target_ = targetsForThisEcu[0];
}
45 changes: 24 additions & 21 deletions src/aktualizr_secondary/secondary_tcp_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@ SecondaryTcpServer::SecondaryTcpServer(Uptane::SecondaryInterface &secondary, co

ConnectionSocket conn_socket(primary_ip, primary_port, listen_socket_.port());
if (conn_socket.connect() == 0) {
LOG_INFO << "Connected to Primary, sending info about this secondary...";
LOG_INFO << "Connected to Primary, sending info about this Secondary.";
HandleOneConnection(*conn_socket);
} else {
LOG_INFO << "Failed to connect to Primary";
LOG_INFO << "Failed to connect to Primary.";
}
}

void SecondaryTcpServer::run() {
if (listen(*listen_socket_, SOMAXCONN) < 0) {
throw std::system_error(errno, std::system_category(), "listen");
}
LOG_INFO << "Secondary TCP server listens on " << listen_socket_.toString();
LOG_INFO << "Secondary TCP server listening on " << listen_socket_.toString();

while (keep_running_.load()) {
sockaddr_storage peer_sa{};
socklen_t peer_sa_size = sizeof(sockaddr_storage);

LOG_DEBUG << "Waiting for connection from client...";
LOG_DEBUG << "Waiting for connection from Primary...";
int con_fd = accept(*listen_socket_, reinterpret_cast<sockaddr *>(&peer_sa), &peer_sa_size);
if (con_fd == -1) {
LOG_INFO << "Socket accept failed. aborting";
LOG_INFO << "Socket accept failed, aborting.";
break;
}
Socket con_socket(con_fd);
LOG_DEBUG << "Connected...";
LOG_DEBUG << "Connected to Primary.";
bool continue_serving = HandleOneConnection(*con_socket);
LOG_DEBUG << "Client disconnected";
LOG_DEBUG << "Primary disconnected.";
if (!continue_serving) {
break;
}
}
LOG_INFO << "Secondary TCP server exit";
LOG_INFO << "Secondary TCP server exiting.";
}

void SecondaryTcpServer::stop() {
Expand Down Expand Up @@ -113,18 +113,6 @@ bool SecondaryTcpServer::HandleOneConnection(int socket) {
case AKIpUptaneMes_PR_putMetaReq: {
auto md = msg->putMetaReq();
Uptane::RawMetaPack meta_pack;
if (md->image.present == image_PR_json) {
meta_pack.image_root = ToString(md->image.choice.json.root); // NOLINT
meta_pack.image_targets = ToString(md->image.choice.json.targets); // NOLINT
meta_pack.image_snapshot = ToString(md->image.choice.json.snapshot); // NOLINT
meta_pack.image_timestamp = ToString(md->image.choice.json.timestamp); // NOLINT
LOG_DEBUG << "Received Image repo Root metadata:\n" << meta_pack.image_root;
LOG_DEBUG << "Received Image repo Targets metadata:\n" << meta_pack.image_targets;
LOG_DEBUG << "Received Image repo Snapshot metadata:\n" << meta_pack.image_snapshot;
LOG_DEBUG << "Received Image repo Timestamp metadata:\n" << meta_pack.image_timestamp;
} else {
LOG_WARNING << "Images metadata in unknown format:" << md->image.present;
}

if (md->director.present == director_PR_json) {
meta_pack.director_root = ToString(md->director.choice.json.root); // NOLINT
Expand All @@ -134,6 +122,20 @@ bool SecondaryTcpServer::HandleOneConnection(int socket) {
} else {
LOG_WARNING << "Director metadata in unknown format:" << md->director.present;
}

if (md->image.present == image_PR_json) {
meta_pack.image_root = ToString(md->image.choice.json.root); // NOLINT
meta_pack.image_timestamp = ToString(md->image.choice.json.timestamp); // NOLINT
meta_pack.image_snapshot = ToString(md->image.choice.json.snapshot); // NOLINT
meta_pack.image_targets = ToString(md->image.choice.json.targets); // NOLINT
LOG_DEBUG << "Received Image repo Root metadata:\n" << meta_pack.image_root;
LOG_DEBUG << "Received Image repo Timestamp metadata:\n" << meta_pack.image_timestamp;
LOG_DEBUG << "Received Image repo Snapshot metadata:\n" << meta_pack.image_snapshot;
LOG_DEBUG << "Received Image repo Targets metadata:\n" << meta_pack.image_targets;
} else {
LOG_WARNING << "Image repo metadata in unknown format:" << md->image.present;
}

bool ok;
try {
ok = impl_.putMetadata(meta_pack);
Expand All @@ -146,14 +148,15 @@ bool SecondaryTcpServer::HandleOneConnection(int socket) {
r->result = ok ? AKInstallationResult_success : AKInstallationResult_failure;
} break;
case AKIpUptaneMes_PR_sendFirmwareReq: {
LOG_INFO << "Received sendFirmwareReq from Primary.";
auto fw = msg->sendFirmwareReq();
auto send_firmware_result = impl_.sendFirmware(ToString(fw->firmware));
resp->present(AKIpUptaneMes_PR_sendFirmwareResp);
auto r = resp->sendFirmwareResp();
r->result = send_firmware_result ? AKInstallationResult_success : AKInstallationResult_failure;
LOG_INFO << "Download " << (send_firmware_result ? "successful" : "failed") << ".";
} break;
case AKIpUptaneMes_PR_installReq: {
LOG_INFO << "Received installReq from Primary.";
auto request = msg->installReq();

auto install_result = impl_.install(ToString(request->hash));
Expand Down

0 comments on commit 4d9b41e

Please sign in to comment.