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

Commit

Permalink
OTA-4174: IP Secondary refactoring
Browse files Browse the repository at this point in the history
- Decouple the secondary interface implementation (aktualizr_secondary) from the TCP server
- Decouple the secondary implementation common functionality from an update/install method specific (update agent)
- Encapsulate the manifest management functionality in a single component and reuse it for Primary and Secondary
- Remove some outdated tests for the secondary and add more relevant tests

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
Mike Sul committed Dec 31, 2019
1 parent 86723b4 commit 4548419
Show file tree
Hide file tree
Showing 78 changed files with 1,313 additions and 1,148 deletions.
1 change: 1 addition & 0 deletions src/aktualizr_get/get.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "get.h"
#include "crypto/keymanager.h"
#include "http/httpclient.h"
#include "storage/invstorage.h"

std::string aktualizrGet(Config &config, const std::string &url) {
auto storage = INvStorage::newStorage(config.storage);
Expand Down
12 changes: 6 additions & 6 deletions src/aktualizr_primary/secondary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class SecondaryWaiter {

LOG_INFO << "Accepted connection from a secondary: (" << sec_ip << ":" << sec_port << ")";
try {
auto sec_creation_res = Uptane::IpUptaneSecondary::create(sec_ip, sec_port, con_socket_.native_handle());
if (sec_creation_res.first) {
connected_secondaries_.push_back(sec_creation_res.second);
auto sec = Uptane::IpUptaneSecondary::create(sec_ip, sec_port, con_socket_.native_handle());
if (sec != nullptr) {
connected_secondaries_.push_back(sec);
}
} catch (const std::exception& exc) {
LOG_ERROR << "Failed to initialize a secondary: " << exc.what();
Expand Down Expand Up @@ -146,9 +146,9 @@ static Secondaries createIPSecondaries(const IPSecondariesConfig& config) {
SecondaryWaiter sec_waiter{config.secondaries_wait_port, config.secondaries_timeout_s, result};

for (auto& ip_sec_cfg : config.secondaries_cfg) {
auto sec_creation_res = Uptane::IpUptaneSecondary::connectAndCreate(ip_sec_cfg.ip, ip_sec_cfg.port);
if (sec_creation_res.first) {
result.push_back(sec_creation_res.second);
auto sec = Uptane::IpUptaneSecondary::connectAndCreate(ip_sec_cfg.ip, ip_sec_cfg.port);
if (sec != nullptr) {
result.push_back(sec);
} else {
sec_waiter.addSecondary(ip_sec_cfg.ip, ip_sec_cfg.port);
}
Expand Down
49 changes: 21 additions & 28 deletions src/aktualizr_secondary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
set(AKTUALIZR_SECONDARY_SRC main.cc)

set(AKTUALIZR_SECONDARY_LIB_SRC
update_agent_file.cc
aktualizr_secondary.cc
aktualizr_secondary_config.cc
aktualizr_secondary_common.cc
aktualizr_secondary_metadata.cc
socket_server.cc
secondary_tcp_server.cc
aktualizr_secondary_factory.cc
)

add_library(aktualizr_secondary_static_lib STATIC
Expand Down Expand Up @@ -37,12 +38,13 @@ install(TARGETS aktualizr-secondary
RUNTIME DESTINATION bin)

set(ALL_AKTUALIZR_SECONDARY_HEADERS
update_agent.h
update_agent_file.h
aktualizr_secondary.h
aktualizr_secondary_interface.h
aktualizr_secondary_config.h
aktualizr_secondary_common.h
aktualizr_secondary_metadata.h
socket_server.h
secondary_tcp_server.h
aktualizr_secondary_factory.h
)

include(AddAktualizrTest)
Expand All @@ -53,39 +55,30 @@ list(INSERT TEST_LIBS 0 aktualizr_secondary_static_lib)
add_aktualizr_test(NAME aktualizr_secondary_config
SOURCES aktualizr_secondary_config_test.cc PROJECT_WORKING_DIRECTORY)

add_aktualizr_test(NAME secondary_tcp_server
SOURCES secondary_tcp_server_test.cc PROJECT_WORKING_DIRECTORY)

if(BUILD_OSTREE)
add_aktualizr_test(NAME aktualizr_secondary_uptane_verification_ostree
SOURCES uptane_verification_ostree_test.cc
target_sources(aktualizr_secondary_static_lib PRIVATE update_agent_ostree.cc)

add_aktualizr_test(NAME aktualizr_secondary_ostree
SOURCES aktualizr_secondary_ostree_test.cc
ARGS ${PROJECT_BINARY_DIR}/ostree_repo
PROJECT_WORKING_DIRECTORY)

set_target_properties(t_aktualizr_secondary_uptane_verification_ostree PROPERTIES LINK_FLAGS -Wl,--export-dynamic)
target_link_libraries(t_aktualizr_secondary_uptane_verification_ostree aktualizr_secondary_static_lib uptane_generator_lib)
set_target_properties(t_aktualizr_secondary_ostree PROPERTIES LINK_FLAGS -Wl,--export-dynamic)
target_link_libraries(t_aktualizr_secondary_ostree aktualizr_secondary_static_lib uptane_generator_lib)

else(BUILD_OSTREE)
list(APPEND TEST_SOURCES uptane_verification_ostree_test.cc)
list(APPEND TEST_SOURCES aktualizr_secondary_ostree_test.cc)
endif(BUILD_OSTREE)

add_aktualizr_test(NAME aktualizr_secondary_uptane_verification
SOURCES uptane_verification_test.cc
add_aktualizr_test(NAME aktualizr_secondary
SOURCES aktualizr_secondary_test.cc
PROJECT_WORKING_DIRECTORY)

target_link_libraries(t_aktualizr_secondary_uptane_verification aktualizr_secondary_static_lib uptane_generator_lib)

add_aktualizr_test(NAME aktualizr_secondary_update
SOURCES update_test.cc
ARGS ${PROJECT_BINARY_DIR}/ostree_repo PROJECT_WORKING_DIRECTORY)
target_link_libraries(t_aktualizr_secondary aktualizr_secondary_static_lib uptane_generator_lib)

if(BUILD_OSTREE)
add_aktualizr_test(NAME aktualizr_secondary_uptane
SOURCES uptane_test.cc
LIBRARIES uptane_generator_lib
LIBRARIES aktualizr-posix
ARGS ${PROJECT_BINARY_DIR}/ostree_repo PROJECT_WORKING_DIRECTORY)
target_link_libraries(t_aktualizr_secondary_uptane virtual_secondary)
else(BUILD_OSTREE)
list(APPEND TEST_SOURCES uptane_test.cc)
endif(BUILD_OSTREE)

# test running the executable with command line option --help
add_test(NAME aktualizr_secondary_cmdline--help COMMAND aktualizr-secondary --help)
Expand Down Expand Up @@ -154,6 +147,6 @@ set_tests_properties(aktualizr_secondary_help_with_other_options
aktualizr_source_file_checks(${AKTUALIZR_SECONDARY_SRC}
${AKTUALIZR_SECONDARY_LIB_SRC}
${ALL_AKTUALIZR_SECONDARY_HEADERS}
${TEST_SOURCES})
${TEST_SOURCES} update_agent_ostree.cc update_agent_ostree.h)

# vim: set tabstop=4 shiftwidth=4 expandtab:
Loading

0 comments on commit 4548419

Please sign in to comment.