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 Jan 13, 2020
1 parent e100348 commit 0f8a6c1
Show file tree
Hide file tree
Showing 79 changed files with 1,359 additions and 1,180 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
70 changes: 27 additions & 43 deletions src/aktualizr_secondary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +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)

# do not link tests with libaktualizr
list(REMOVE_ITEM TEST_LIBS aktualizr_lib)
Expand All @@ -26,18 +26,19 @@ add_library(aktualizr_secondary_lib SHARED
$<TARGET_OBJECTS:utilities>
$<TARGET_OBJECTS:storage>
$<TARGET_OBJECTS:logging>
$<TARGET_OBJECTS:uptane>)
$<TARGET_OBJECTS:uptane>
$<TARGET_OBJECTS:campaign>)
target_link_libraries(aktualizr_secondary_lib ${AKTUALIZR_EXTERNAL_LIBS})
target_include_directories(aktualizr_secondary_lib PUBLIC
$<TARGET_PROPERTY:asn1_lib,INCLUDE_DIRECTORIES>
${PROJECT_SOURCE_DIR}/src/libaktualizr-posix
)
${PROJECT_SOURCE_DIR}/src/libaktualizr-posix)

if (BUILD_ISOTP)
target_sources(aktualizr_secondary_lib PRIVATE $<TARGET_OBJECTS:isotp_conn>)
endif (BUILD_ISOTP)

add_executable(aktualizr-secondary ${AKTUALIZR_SECONDARY_SRC})

target_link_libraries(aktualizr-secondary aktualizr_secondary_lib)
install(TARGETS aktualizr_secondary_lib LIBRARY DESTINATION lib COMPONENT aktualizr)

Expand All @@ -46,13 +47,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 @@ -62,47 +63,30 @@ list(INSERT TEST_LIBS 0 aktualizr_secondary_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
ARGS ${PROJECT_BINARY_DIR}/ostree_repo
PROJECT_WORKING_DIRECTORY)
target_sources(aktualizr_secondary_lib PRIVATE update_agent_ostree.cc)
list(APPEND AKTUALIZR_SECONDARY_LIB_SRC update_agent_ostree.cc)
list(APPEND ALL_AKTUALIZR_SECONDARY_HEADERS update_agent_ostree.h)

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)
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_ostree PROPERTIES LINK_FLAGS -Wl,--export-dynamic)
target_link_libraries(t_aktualizr_secondary_ostree aktualizr_secondary_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 update_agent_ostree.cc)
list(APPEND ALL_AKTUALIZR_SECONDARY_HEADERS update_agent_ostree.h)
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 LIBRARIES aktualizr_secondary_lib)

if(BUILD_OSTREE)
add_aktualizr_test(NAME aktualizr_secondary_uptane_verification
SOURCES uptane_verification_test.cc
ARGS ${PROJECT_BINARY_DIR}/ostree_repo
LIBRARIES aktualizr_secondary_lib uptane_generator_lib $<TARGET_OBJECTS:campaign>
PROJECT_WORKING_DIRECTORY )

set_target_properties(t_aktualizr_secondary_uptane_verification PROPERTIES LINK_FLAGS -Wl,--export-dynamic)
target_link_libraries(t_aktualizr_secondary_uptane_verification aktualizr_secondary_lib uptane_generator_lib)

add_aktualizr_test(NAME aktualizr_secondary_uptane
SOURCES uptane_test.cc
LIBRARIES aktualizr_secondary_lib uptane_generator_lib virtual_secondary $<TARGET_OBJECTS:campaign> $<TARGET_OBJECTS:primary> $<TARGET_OBJECTS:http>
ARGS ${PROJECT_BINARY_DIR}/ostree_repo PROJECT_WORKING_DIRECTORY)
else(BUILD_OSTREE)
list(APPEND TEST_SOURCES uptane_verification_test.cc uptane_test.cc)
endif(BUILD_OSTREE)
target_link_libraries(t_aktualizr_secondary aktualizr_secondary_lib uptane_generator_lib)

# test running the executable with command line option --help
add_test(NAME aktualizr_secondary_cmdline--help COMMAND aktualizr-secondary --help)
Expand Down
Loading

0 comments on commit 0f8a6c1

Please sign in to comment.