Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Determine initial version from filename #142

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
MICROOVN_SNAP=microovn.snap
export MICROOVN_SNAP_PATH := $(CURDIR)/$(MICROOVN_SNAP)

ifndef MICROOVN_SNAP_CHANNEL
export MICROOVN_SNAP_CHANNEL="22.03/stable"
endif

.DEFAULT_GOAL := $(MICROOVN_SNAP)

ALL_TESTS := $(wildcard tests/*.bats)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_helper/bats/ovsdb_schema_upgrade.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# This is a bash shell fragment -*- bash -*-

# Define test filename prefix that helps to determine from which version should
# the upgrade be tested.
export TEST_NAME_PREFIX="ovsdb_schema_upgrade"

load "test_helper/setup_teardown/$(basename "${BATS_TEST_FILENAME//.bats/.bash}")"

setup() {
Expand Down
4 changes: 4 additions & 0 deletions tests/test_helper/bats/upgrade.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# This is a bash shell fragment -*- bash -*-

# Define test filename prefix that helps to determine from which version should
# the upgrade be tested.
export TEST_NAME_PREFIX="upgrade"

# Instruct the ``setup_file`` function to perform the upgrade.
export UPGRADE_DO_UPGRADE=1
load "test_helper/setup_teardown/$(basename "${BATS_TEST_FILENAME//.bats/.bash}")"
Expand Down
40 changes: 40 additions & 0 deletions tests/test_helper/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,43 @@ function test_snap_is_stable_base() {

[ "$version_info" != "--" ]
}


# get_upgrade_test_version TEST_FILE_NAME TEST_PREFIX
#
# Parse test filename of an "upgrade" test to determine which version should the
# test upgrade from.
#
# MicroOVN upgrade tests need to define initial MicroOVN version to be deployed, so that
# the tests can verify if the upgrade is possible. Initial version is defined in filename.
#
# For example, by passing "upgrade_22.03.bats" TEST_FILE_NAME and "upgrade" TEST_PREFIX into
# this function, it returns "22.03/stable".
#
# If there's no version defined in the test filename, (e.g. TEST_FILE_NAME is "upgrade.bats"
# and TEST_PREFIX is "upgrade"), an empty string is returned.
#
# If filename does not match expected formats "<TEST_PREFIX>_<MAJOR_VERSION>.<MINOR_VERSION>.bats",
# or "<TEST_PREFIX>.bats", this function returns with error code.
function get_upgrade_test_version() {
local test_name=$1; shift
local test_prefix=$1; shift

upgrade_from_version=""

if [ "$test_name" != "${test_prefix}.bats" ]; then
upgrade_from_version=$(sed -nr 's/^'"$test_prefix"'_([0-9]+\.[0-9]+)\.bats/\1/p' <<< "$test_name")

if [ -z "$upgrade_from_version" ]; then
echo "Failed to determine MicroOVN upgrade version for this test: '$test_name'." >&2
echo "" >&2
echo "Expected test name is '${test_prefix}_<major_version>.<minor_version>.bats'" >&2
echo "where '<major_version>.<minor_version>' determine MicroOVN track from which" >&2
echo "the test will be performed." >&2
exit 1
fi

upgrade_from_version="${upgrade_from_version}/stable"
fi
echo "$upgrade_from_version"
}
13 changes: 10 additions & 3 deletions tests/test_helper/microovn.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ function install_microovn() {

# install_microovn_from_store CHANNEL CONTAINER1 [CONTAINER2 ...]
#
# Install MicroOVN snap from specified CHANNEL from Snap store in all CONTAINERs.
# Install MicroOVN snap from specified CHANNEL from Snap store in all CONTAINERs. If
# the CHANNEL argument is an empty string, a default channel will be used.
function install_microovn_from_store() {
local channel=$1; shift
local containers=$*
local source_channel=""
local channel_pretty_name="default"

if [ -n "$channel" ]; then
channel_pretty_name="$channel"
source_channel="--channel $channel"
fi
for container in $containers; do
echo "# Installing MicroOVN from SnapStore in container $container" >&3
lxc_exec "$container" "snap install microovn --channel $channel"
echo "# Installing MicroOVN from SnapStore ('$channel_pretty_name' channel) in container $container" >&3
lxc_exec "$container" "snap install microovn $source_channel"
done
}

Expand Down
7 changes: 4 additions & 3 deletions tests/test_helper/setup_teardown/upgrade.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ setup_file() {
ABS_TOP_TEST_DIRNAME="${BATS_TEST_DIRNAME}/"
export ABS_TOP_TEST_DIRNAME

# Env variable MICROOVN_SNAP_CHANNEL must be specified for tests to know
# from which channel should be MicroOVN installed before upgrading
assert [ -n "$MICROOVN_SNAP_CHANNEL" ]
# Determine MicroOVN channel from which we are upgrading
test_name=$(basename "$BATS_TEST_FILENAME")
MICROOVN_SNAP_CHANNEL=$(get_upgrade_test_version "$test_name" "$TEST_NAME_PREFIX")

# Create test deployment
TEST_CONTAINERS=$(container_names "$BATS_TEST_FILENAME" 4)
CENTRAL_CONTAINERS=""
CHASSIS_CONTAINERS=""
Expand Down
Loading