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

Commit

Permalink
Log connectivity restored after an interruption
Browse files Browse the repository at this point in the history
Signed-off-by: Zee314159 <252806294@qq.com>
  • Loading branch information
Zee314159 committed Dec 1, 2019
1 parent 5b09647 commit 573d771
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libaktualizr/primary/sotauptaneclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -948,15 +948,22 @@ bool SotaUptaneClient::putManifestSimple(const Json::Value &custom) {
return false;
}

static bool connect = true;
auto manifest = AssembleManifest();
if (custom != Json::nullValue) {
manifest["custom"] = custom;
}
auto signed_manifest = uptane_manifest.signManifest(manifest);
HttpResponse response = http->put(config.uptane.director_server + "/manifest", signed_manifest);
if (response.isOk()) {
if (!connect) {
LOG_INFO << "Connectivity is restored.";
}
connect = true;
storage->clearInstallationResults();
return true;
} else {
connect = false;
}

LOG_WARNING << "Put manifest request failed: " << response.getStatusStr();
Expand Down
1 change: 1 addition & 0 deletions src/libaktualizr/primary/sotauptaneclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class SotaUptaneClient {
FRIEND_TEST(UptaneCI, CheckKeys);
FRIEND_TEST(UptaneKey, Check); // Note hacky name
FRIEND_TEST(UptaneNetwork, DownloadFailure);
FRIEND_TEST(UptaneNetwork, LogConnectivityRestored);
FRIEND_TEST(UptaneVector, Test);
FRIEND_TEST(aktualizr_secondary_uptane, credentialsPassing);
friend class CheckForUpdate; // for load tests
Expand Down
39 changes: 39 additions & 0 deletions src/libaktualizr/uptane/uptane_network_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* network issues.
*/
#include <gtest/gtest.h>
#include "gtest/internal/gtest-port.h"

#include <boost/process.hpp>
#include <fstream>
Expand Down Expand Up @@ -139,6 +140,44 @@ TEST(UptaneNetwork, DownloadFailure) {
EXPECT_TRUE(result.first);
}

/*
* Output a log when connectivity is restored.
*/
TEST(UptaneNetwork, LogConnectivityRestored) {
testing::internal::CaptureStdout();

TemporaryDirectory temp_dir;
conf.storage.path = temp_dir.Path();
conf.provision.expiry_days = "logconnect";
conf.provision.primary_ecu_serial = "logconnect";
conf.provision.primary_ecu_hardware_id = "hardware_id";
const std::string good_url = conf.provision.server;
bool result;
auto http = std::make_shared<HttpClient>();
auto store = INvStorage::newStorage(conf.storage);
{
KeyManager keys(store, conf.keymanagerConfig());
Initializer initializer(conf.provision, store, http, keys, {});
result = initializer.isSuccessful();
}
EXPECT_TRUE(result);
{
conf.provision.server = conf.provision.server.substr(conf.provision.server.size() - 2) + "11";
KeyManager keys(store, conf.keymanagerConfig());
Initializer initializer(conf.provision, store, http, keys, {});
result = initializer.isSuccessful();
}
EXPECT_FALSE(result);
{
conf.provision.server = good_url;
KeyManager keys(store, conf.keymanagerConfig());
Initializer initializer(conf.provision, store, http, keys, {});
result = initializer.isSuccessful();
}
EXPECT_TRUE(result);
EXPECT_STREQ("Connectivity is restored.", testing::internal::GetCapturedStdout().c_str());
}

#ifndef __NO_MAIN__
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 573d771

Please sign in to comment.