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

Commit

Permalink
fix/ota-3634/Change selfupdate to use fake package manager (#1368)
Browse files Browse the repository at this point in the history
fix/ota-3634/Change selfupdate to use fake package manager
  • Loading branch information
lbonn authored Sep 24, 2019
2 parents bb4722a + cfa5179 commit 74fa9fd
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 44 deletions.
3 changes: 2 additions & 1 deletion ci/gitlab/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ bionic-pkg-test:
- /^docs\//
script:
- ./scripts/test_install_garage_deploy.sh
- ./scripts/test_install_aktualizr.sh

xenial-pkg-test:
variables:
Expand All @@ -207,7 +208,7 @@ xenial-pkg-test:
- /^docs\//
script:
- ./scripts/test_install_garage_deploy.sh
- ./scripts/test_install_aktualizr_and_update.sh
- ./scripts/test_install_aktualizr.sh
- ./scripts/test-uptane-generator.sh

# -- yocto tests
Expand Down
8 changes: 4 additions & 4 deletions scripts/build_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ mkdir -p "$TEST_INSTALL_DESTDIR"
LDFLAGS="-s" "$GITREPO_ROOT/scripts/test.sh"

# copy provisioning data and scripts
cp -rf "$GITREPO_ROOT/tests/test_data/prov_selfupdate" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/tests/config/selfupdate.toml" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/scripts/selfupdate_server.py" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/tests/test_data/selfupdate_2.0" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/tests/test_data/prov_testupdate" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/tests/config/testupdate.toml" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/scripts/testupdate_server.py" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/tests/test_data/testupdate_2.0" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/src/uptane_generator/run/create_repo.sh" "$TEST_INSTALL_DESTDIR"
cp -rf "$GITREPO_ROOT/src/uptane_generator/run/serve_repo.py" "$TEST_INSTALL_DESTDIR"

Expand Down
2 changes: 1 addition & 1 deletion scripts/test_aktualizr_deb_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ IMG_TAG=aktualizr-deb-$(cat /proc/sys/kernel/random/uuid)
echo "Building docker for testing aktualizr deb package inside it."
docker build -t "${IMG_TAG}" -f "${INSTALL_DOCKERFILE}" .
echo "Running docker container with aktualizr debian package inside."
docker run --rm -v "${PKG_SRCDIR}":/persistent -t "${IMG_TAG}" /bin/bash -c "/scripts/test_install_aktualizr_and_update.sh && /scripts/test-uptane-generator.sh"
docker run --rm -v "${PKG_SRCDIR}":/persistent -t "${IMG_TAG}" /bin/bash -c "/scripts/test-uptane-generator.sh"
10 changes: 10 additions & 0 deletions scripts/test_install_aktualizr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash

set -exuo pipefail

TEST_INSTALL_DESTDIR=${TEST_INSTALL_DESTDIR:-/persistent}

dpkg-deb -I "$TEST_INSTALL_DESTDIR"/aktualizr*.deb && dpkg -i "$TEST_INSTALL_DESTDIR"/aktualizr*.deb
akt_version=$(aktualizr --version)
(grep "$(cat "$TEST_INSTALL_DESTDIR"/aktualizr-version)" <<< "$akt_version") || (echo "$akt_version"; false)

29 changes: 0 additions & 29 deletions scripts/test_install_aktualizr_and_update.sh

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/libaktualizr/config/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST(config, TomlInt) {
*/
TEST(config, TomlPrimarySerial) {
RecordProperty("zephyr_key", "OTA-988");
Config conf("tests/config/selfupdate.toml");
Config conf("tests/config/testupdate.toml");
EXPECT_EQ(conf.provision.primary_ecu_serial, "723f79763eda1c753ce565c16862c79acdde32eb922d6662f088083c51ffde66");
}

Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ add_test(NAME test_backend_failure
COMMAND ${PROJECT_SOURCE_DIR}/tests/test_backend_failure.py
--build-dir ${PROJECT_BINARY_DIR} --src-dir ${PROJECT_SOURCE_DIR} --ostree ${BUILD_OSTREE})

add_test(NAME test_install_aktualizr_and_update COMMAND ${PROJECT_SOURCE_DIR}/tests/test_install_aktualizr_and_update.sh ${PROJECT_BINARY_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_executable(aktualizr-cycle-simple aktualizr_cycle_simple.cc)
target_link_libraries(aktualizr-cycle-simple aktualizr_static_lib ${AKTUALIZR_EXTERNAL_LIBS})
aktualizr_source_file_checks(aktualizr_cycle_simple.cc)
Expand Down
8 changes: 3 additions & 5 deletions tests/config/selfupdate.toml → tests/config/testupdate.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[tls]
server = "http://localhost:8000"

[import]
tls_cacert_path = "ca.pem"
tls_pkey_path = "pkey.pem"
Expand All @@ -13,7 +10,8 @@ key_source = "file"

[provision]
primary_ecu_serial = "723f79763eda1c753ce565c16862c79acdde32eb922d6662f088083c51ffde66"
primary_ecu_hardware_id = "selfupdate-device"
primary_ecu_hardware_id = "testupdate-device"

[pacman]
type = "debian"
type = "none"

File renamed without changes.
6 changes: 3 additions & 3 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ class KeyStore:

@staticmethod
def ca():
return path.join(KeyStore.base_dir, 'tests/test_data/prov_selfupdate/ca.pem')
return path.join(KeyStore.base_dir, 'tests/test_data/prov_testupdate/ca.pem')

@staticmethod
def pkey():
return path.join(KeyStore.base_dir, 'tests/test_data/prov_selfupdate/pkey.pem')
return path.join(KeyStore.base_dir, 'tests/test_data/prov_testupdate/pkey.pem')

@staticmethod
def cert():
return path.join(KeyStore.base_dir, 'tests/test_data/prov_selfupdate/client.pem')
return path.join(KeyStore.base_dir, 'tests/test_data/prov_testupdate/client.pem')


class IPSecondary:
Expand Down
36 changes: 36 additions & 0 deletions tests/test_install_aktualizr_and_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /bin/bash

set -exuo pipefail

SCRIPT_DIR="$(dirname "$0")"
TEST_INSTALL_DESTDIR=$(mktemp -d)/install
./scripts/testupdate_server.py 0 "$TEST_INSTALL_DESTDIR"&
PORT=$("$SCRIPT_DIR/find_listening_port.sh" $!)
trap 'kill %1' EXIT

until curl 127.0.0.1:"$PORT" &> /dev/null; do
sleep 0.2
done

$1/src/aktualizr_primary/aktualizr --version

$1/src/uptane_generator/uptane-generator generate --path "$TEST_INSTALL_DESTDIR/fake_root"
$1/src/uptane_generator/uptane-generator image --path "$TEST_INSTALL_DESTDIR/fake_root" --targetname testupdate_2.0 --filename "./tests/test_data/testupdate_2.0" --hwid testupdate-device
$1/src/uptane_generator/uptane-generator addtarget --path "$TEST_INSTALL_DESTDIR/fake_root" --targetname testupdate_2.0 --hwid testupdate-device --serial 723f79763eda1c753ce565c16862c79acdde32eb922d6662f088083c51ffde66
$1/src/uptane_generator/uptane-generator signtargets --path "$TEST_INSTALL_DESTDIR/fake_root"

TEMP_DIR=$(mktemp -d)
mkdir -m 700 -p "$TEMP_DIR/import"
cp ./tests/test_data/prov_testupdate/* "$TEMP_DIR/import"
echo -e "[storage]\\npath = \"$TEMP_DIR\"\\n[import]\\nbase_path = \"$TEMP_DIR/import\"" > "$TEMP_DIR/conf.toml"
echo -e "[tls]\\nserver = \"http://localhost:$PORT\"" >> "$TEMP_DIR/conf.toml"
$1/src/aktualizr_primary/aktualizr -c ./tests/config/testupdate.toml -c "$TEMP_DIR/conf.toml" once

# check the updated file appeared in the installation directory and sha256sum matches expectation
filename=$(echo $($1/src/aktualizr_info/aktualizr-info -c ./tests/config/testupdate.toml -c "$TEMP_DIR/conf.toml" --director-target | jq '(.signed.targets["testupdate_2.0"].hashes.sha256)') | tr [a-f] [A-F] | tr -d '"')
ls $TEMP_DIR/images/$filename
if [ $? -ne 0 ];then
echo "ERROR: $filename does not exist or sha256sum does not match."
exit 1
fi

0 comments on commit 74fa9fd

Please sign in to comment.