Skip to content

Commit eb454cc

Browse files
test(bdd): add vnext builtin the bdd tests
Allows the bdd tests to run and setup the vnext chart on their own We can still pre-deploy the kind cluster on CI for time tracking Signed-off-by: Tiago Castro <[email protected]>
1 parent 6bdd64a commit eb454cc

File tree

11 files changed

+376
-201
lines changed

11 files changed

+376
-201
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ __pycache__
2424
# Pytest assets
2525
/test-dir-*
2626
tests/bdd/venv
27-
pytest.log
27+
pytest.log
28+
/tests/bdd/chart-vnext/

nix/pkgs/images/default.nix

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let
2626
} // config;
2727
};
2828
build-exporter-image = { buildType }: {
29-
io-engine = build-extensions-image rec{
29+
io-engine = build-extensions-image rec {
3030
inherit buildType;
3131
package = extensions.${buildType}.metrics.exporter.io-engine;
3232
pname = package.pname;
@@ -54,10 +54,12 @@ let
5454
# todo: handle this properly?
5555
# Script doesn't need to be used with main branch `--alias-tag <main-branch-style-tag>`.
5656
# The repo chart is already prepared.
57-
if [[ "$(semver validate ${tag})" == "valid" ]] &&
58-
[[ ! ${tag} =~ ^(v?[0-9]+\.[0-9]+\.[0-9]+-0-(main|release)-unstable(-[0-9]+){6}-0)$ ]]; then
59-
CHART_FILE=build/chart/Chart.yaml build/scripts/helm/publish-chart-yaml.sh --app-tag ${tag} --override-index ""
60-
fi
57+
# if [[ "$(semver validate ${tag})" == "valid" ]] &&
58+
# [[ ! ${tag} =~ ^(v?[0-9]+\.[0-9]+\.[0-9]+-0-(main|release)-unstable(-[0-9]+){6}-0)$ ]]; then
59+
# CHART_FILE=build/chart/Chart.yaml build/scripts/helm/publish-chart-yaml.sh --app-tag ${tag} --override-index ""
60+
# fi
61+
# TODO: add chart source override or just reuse existing chart and git restore...
62+
CHART_FILE=build/chart/Chart.yaml build/scripts/helm/publish-chart-yaml.sh --app-tag ${tag} --override-index ""
6163
6264
# This modifies the build helm chart in-place with missing values of the
6365
# dependent charts, i.e. the values from the dependent helm charts which

scripts/k8s/deployer.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ KUBECTL="kubectl"
1616
DOCKER="docker"
1717
HUGE_PAGES=1800
1818
LABEL=
19+
CLEANUP="false"
1920
SUDO=${SUDO:-"sudo"}
2021

2122
help() {
@@ -31,6 +32,7 @@ Options:
3132
--dry-run Don't do anything, just output steps.
3233
--hugepages <num> Add <num> 2MiB hugepages (Default: $HUGE_PAGES).
3334
--label Label worker nodes with the io-engine selector.
35+
--cleanup Prior to starting, stops the running instance of the deployer.
3436
3537
Command:
3638
start Start the k8s cluster.
@@ -90,6 +92,9 @@ while [ "$#" -gt 0 ]; do
9092
--label)
9193
LABEL="true"
9294
shift;;
95+
--cleanup)
96+
CLEANUP="true"
97+
shift;;
9398
--hugepages)
9499
shift
95100
test $# -lt 1 && die "Missing hugepage number"
@@ -115,12 +120,14 @@ if [ -z "$COMMAND" ]; then
115120
die "No command specified!"
116121
fi
117122

118-
if [ "$COMMAND" = "stop" ]; then
119-
if command -v nvme 2>dev/null; then
123+
if [ "$COMMAND" = "stop" ] || [ "$CLEANUP" = "true" ]; then
124+
if command -v nvme &>/dev/null; then
120125
$SUDO nvme disconnect-all
121126
fi
122127
$KIND delete cluster
123-
exit 0
128+
if [ "$COMMAND" = "stop" ]; then
129+
exit 0
130+
fi
124131
fi
125132

126133
"$SCRIPT_DIR"/setup-io-prereq.sh --hugepages "$HUGE_PAGES" --nvme-tcp $DRY_RUN

scripts/python/tag-chart.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515

1616
CHART_VERSION=${1#v}
1717
IMAGE_TAG="v$CHART_VERSION"
18-
CHART_DIR="$ROOT_DIR/chart"
18+
CHART_DIR=${CHART_DIR:-"$ROOT_DIR/chart"}
1919
# TODO: tests should work with its own copy of the chart. Shouldn't modify the chart.
2020
# chart/Chart.yaml
2121
yq_ibl "

scripts/python/upgrade-test-helper.sh

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
3+
# "Fork" the local chart into a separate location and build the container images and the plugin binary
4+
# with a given TAG (or figures out the tag using $SCRIPT_DIR/build-upgrade-images.sh).
5+
# This is used by the upgrade test
6+
7+
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
8+
ROOT_DIR="$SCRIPT_DIR/../.."
9+
10+
# Imports
11+
source "$ROOT_DIR"/scripts/utils/log.sh
12+
13+
set -euo pipefail
14+
15+
TAG=
16+
CHART_VNEXT=
17+
CHART="$ROOT_DIR/chart"
18+
CHART_FORK="false"
19+
IMAGE_BUILD="false"
20+
IMAGE_LOAD="false"
21+
22+
# Print usage options for this script.
23+
print_help() {
24+
cat <<EOF
25+
Usage: $(basename "${0}") [OPTIONS]
26+
27+
Options:
28+
-h, --help Display this text.
29+
--tag <tag> The tag for the vnext chart.
30+
Default: Automatically figured out.
31+
--chart <path> The path where the chart will be copied to and modified for the vnext tag.
32+
Default: \$workspace_root/tests/python/chart_vnext.
33+
--fork Forks the vnext chart from "$CHART" into CHART_VNEXT.
34+
--build Builds the container images and the plugin binary.
35+
--load Loads the images into the kind cluster.
36+
37+
Examples:
38+
$(basename "${0}") --fork
39+
40+
The kubectl-mayastor binary will be built at CHART_VNEXT/kubectl-plugin/bin/kubectl-mayastor
41+
EOF
42+
}
43+
44+
# Parse args.
45+
while test $# -gt 0; do
46+
arg="$1"
47+
case "$arg" in
48+
--tag)
49+
TAG="$1"
50+
;;
51+
--chart)
52+
CHART_VNEXT="$1"
53+
;;
54+
--fork)
55+
CHART_FORK="true"
56+
;;
57+
--build)
58+
IMAGE_BUILD="true"
59+
;;
60+
--load)
61+
IMAGE_LOAD="true"
62+
;;
63+
-h* | --help*)
64+
print_help
65+
exit 0
66+
;;
67+
*)
68+
print_help
69+
log_fatal "unexpected argument '$arg'" 1
70+
;;
71+
esac
72+
shift
73+
done
74+
75+
if [ "$(kubectl config current-context)" != "kind-kind" ]; then
76+
log_fatal "Only Supported on Kind Clusters!"
77+
fi
78+
79+
if [ -z "$TAG" ]; then
80+
TAG="$("$SCRIPT_DIR"/generate-test-tag.sh)"
81+
fi
82+
83+
if [ -z "$CHART_VNEXT" ]; then
84+
CHART_VNEXT="$ROOT_DIR/tests/bdd/chart-vnext"
85+
fi
86+
KUBECTL_MAYASTOR="$CHART_VNEXT/kubectl-plugin/bin/kubectl-mayastor"
87+
88+
# Ensure the chart vnext is created, copied from the original
89+
if [ "$CHART_FORK" = "true" ]; then
90+
mkdir -p "$CHART_VNEXT"
91+
rm -r "${CHART_VNEXT:?}"/*
92+
cp -r "$CHART/." "${CHART_VNEXT:?}"
93+
94+
# Tag the vnext chart
95+
CHART_DIR="$CHART_VNEXT" "$SCRIPT_DIR"/tag-chart.sh "$TAG"
96+
fi
97+
98+
# Build the vnext images and kubectl-binary (in debug mode)
99+
if [ "$IMAGE_BUILD" = "true" ]; then
100+
RUSTFLAGS="-C debuginfo=0 -C strip=debuginfo" "$ROOT_DIR"/scripts/release.sh --tag "$TAG" --build-binary-out "$CHART_VNEXT" --no-static-linking --skip-publish --debug
101+
102+
# Ensure binary is on the correct version
103+
PLUGIN_VERSION="$($KUBECTL_MAYASTOR --version)"
104+
if [[ ! "$PLUGIN_VERSION" =~ ^Kubectl\ Plugin\ \(kubectl-mayastor\).*\($TAG\+0\)$ ]]; then
105+
log_fatal "The built kubectl-plugin reports version $PLUGIN_VERSION but we want $TAG"
106+
fi
107+
fi
108+
109+
# Load the images into the kind cluster
110+
if [ "$IMAGE_LOAD" = "true" ]; then
111+
"$ROOT_DIR"/scripts/k8s/load-images-to-kind.sh --tag "$TAG" --trim-debug-suffix
112+
fi

tests/bdd/common/__init__.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import logging
2+
import os
3+
import subprocess
4+
5+
logger = logging.getLogger(__name__)
6+
7+
8+
def root_dir():
9+
file_path = os.path.abspath(__file__)
10+
return file_path.split("tests/bdd")[0]
11+
12+
13+
def chart_vnext():
14+
vnext = os.getenv("CHART_VNEXT")
15+
if vnext is not None:
16+
return vnext
17+
return os.path.join(root_dir(), "./tests/bdd/chart-vnext")
18+
19+
20+
def run(
21+
command: str,
22+
args: list[str] = None,
23+
absolute=False,
24+
capture_output=True,
25+
log_run=True,
26+
**kwargs,
27+
):
28+
if absolute:
29+
command = [command]
30+
else:
31+
command = [os.path.join(root_dir(), command)]
32+
if args is not None:
33+
command.extend(args)
34+
if log_run:
35+
logger.info(f"Running '{command}'")
36+
else:
37+
logger.debug(f"Running '{command}'")
38+
try:
39+
result = subprocess.run(
40+
command, capture_output=capture_output, check=True, text=True, **kwargs
41+
)
42+
logger.debug(
43+
f"Command '{command}' completed with:\nStdErr Output: {result.stderr}\nStdOut Output: {result.stdout}"
44+
)
45+
return result.stdout.strip()
46+
47+
except subprocess.CalledProcessError as e:
48+
logger.error(
49+
f"Command '{command}' failed with exit code {e.returncode}\nStdErr Output: {e.stderr}\nStdOut Output: {e.stdout}"
50+
)
51+
raise e
52+
53+
except Exception as e:
54+
logger.error(f"An unexpected error occurred: {e}")
55+
raise e
56+
57+
58+
def env_cleanup():
59+
clean = os.getenv("CLEAN")
60+
if clean is not None and clean.lower() in ("no", "false", "f", "0"):
61+
return False
62+
return True

0 commit comments

Comments
 (0)