-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
6bdd64a
commit 4b6ec90
Showing
12 changed files
with
378 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ __pycache__ | |
# Pytest assets | ||
/test-dir-* | ||
tests/bdd/venv | ||
pytest.log | ||
pytest.log | ||
/tests/bdd/chart-vnext/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/usr/bin/env bash | ||
|
||
# "Fork" the local chart into a separate location and build the container images and the plugin binary | ||
# with a given TAG (or figures out the tag using $SCRIPT_DIR/build-upgrade-images.sh). | ||
# This is used by the upgrade test | ||
|
||
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")" | ||
ROOT_DIR="$SCRIPT_DIR/../.." | ||
|
||
# Imports | ||
source "$ROOT_DIR"/scripts/utils/log.sh | ||
|
||
set -euo pipefail | ||
|
||
TAG= | ||
CHART_VNEXT= | ||
CHART="$ROOT_DIR/chart" | ||
CHART_FORK="false" | ||
IMAGE_BUILD="false" | ||
IMAGE_LOAD="false" | ||
|
||
# Print usage options for this script. | ||
print_help() { | ||
cat <<EOF | ||
Usage: $(basename "${0}") [OPTIONS] | ||
Options: | ||
-h, --help Display this text. | ||
--tag <tag> The tag for the vnext chart. | ||
Default: Automatically figured out. | ||
--chart <path> The path where the chart will be copied to and modified for the vnext tag. | ||
Default: \$workspace_root/tests/python/chart_vnext. | ||
--fork Forks the vnext chart from "$CHART" into CHART_VNEXT. | ||
--build Builds the container images and the plugin binary. | ||
--load Loads the images into the kind cluster. | ||
Examples: | ||
$(basename "${0}") --fork | ||
The kubectl-mayastor binary will be built at CHART_VNEXT/kubectl-plugin/bin/kubectl-mayastor | ||
EOF | ||
} | ||
|
||
# Parse args. | ||
while test $# -gt 0; do | ||
arg="$1" | ||
case "$arg" in | ||
--tag) | ||
TAG="$1" | ||
;; | ||
--chart) | ||
CHART_VNEXT="$1" | ||
;; | ||
--fork) | ||
CHART_FORK="true" | ||
;; | ||
--build) | ||
IMAGE_BUILD="true" | ||
;; | ||
--load) | ||
IMAGE_LOAD="true" | ||
;; | ||
-h* | --help*) | ||
print_help | ||
exit 0 | ||
;; | ||
*) | ||
print_help | ||
log_fatal "unexpected argument '$arg'" 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ "$(kubectl config current-context)" != "kind-kind" ]; then | ||
log_fatal "Only Supported on Kind Clusters!" | ||
fi | ||
|
||
if [ -z "$TAG" ]; then | ||
TAG="$("$SCRIPT_DIR"/generate-test-tag.sh)" | ||
fi | ||
|
||
if [ -z "$CHART_VNEXT" ]; then | ||
CHART_VNEXT="$ROOT_DIR/tests/bdd/chart-vnext" | ||
fi | ||
KUBECTL_MAYASTOR="$CHART_VNEXT/kubectl-plugin/bin/kubectl-mayastor" | ||
|
||
# Ensure the chart vnext is created, copied from the original | ||
if [ "$CHART_FORK" = "true" ]; then | ||
mkdir -p "$CHART_VNEXT" | ||
rm -r "${CHART_VNEXT:?}"/* | ||
cp -r "$CHART/." "${CHART_VNEXT:?}" | ||
|
||
# Tag the vnext chart | ||
CHART_DIR="$CHART_VNEXT" "$SCRIPT_DIR"/tag-chart.sh "$TAG" | ||
fi | ||
|
||
# Build the vnext images and kubectl-binary (in debug mode) | ||
if [ "$IMAGE_BUILD" = "true" ]; then | ||
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 | ||
|
||
# Ensure binary is on the correct version | ||
PLUGIN_VERSION="$($KUBECTL_MAYASTOR --version)" | ||
if [[ ! "$PLUGIN_VERSION" =~ ^Kubectl\ Plugin\ \(kubectl-mayastor\).*\($TAG\+0\)$ ]]; then | ||
log_fatal "The built kubectl-plugin reports version $PLUGIN_VERSION but we want $TAG" | ||
fi | ||
fi | ||
|
||
# Load the images into the kind cluster | ||
if [ "$IMAGE_LOAD" = "true" ]; then | ||
"$ROOT_DIR"/scripts/k8s/load-images-to-kind.sh --tag "$TAG" --trim-debug-suffix | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import logging | ||
import os | ||
import subprocess | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def root_dir(): | ||
file_path = os.path.abspath(__file__) | ||
return file_path.split("tests/bdd")[0] | ||
|
||
|
||
def chart_vnext(): | ||
vnext = os.getenv("CHART_VNEXT") | ||
if vnext is not None: | ||
return vnext | ||
return os.path.join(root_dir(), "./tests/bdd/chart-vnext") | ||
|
||
|
||
def run( | ||
command: str, | ||
args: list[str] = None, | ||
absolute=False, | ||
capture_output=True, | ||
log_run=True, | ||
**kwargs, | ||
): | ||
if absolute: | ||
command = [command] | ||
else: | ||
command = [os.path.join(root_dir(), command)] | ||
if args is not None: | ||
command.extend(args) | ||
if log_run: | ||
logger.info(f"Running '{command}'") | ||
else: | ||
logger.debug(f"Running '{command}'") | ||
try: | ||
result = subprocess.run( | ||
command, capture_output=capture_output, check=True, text=True, **kwargs | ||
) | ||
logger.debug( | ||
f"Command '{command}' completed with:\nStdErr Output: {result.stderr}\nStdOut Output: {result.stdout}" | ||
) | ||
return result.stdout.strip() | ||
|
||
except subprocess.CalledProcessError as e: | ||
logger.error( | ||
f"Command '{command}' failed with exit code {e.returncode}\nStdErr Output: {e.stderr}\nStdOut Output: {e.stdout}" | ||
) | ||
raise e | ||
|
||
except Exception as e: | ||
logger.error(f"An unexpected error occurred: {e}") | ||
raise e | ||
|
||
|
||
def env_cleanup(): | ||
clean = os.getenv("CLEAN") | ||
if clean is not None and clean.lower() in ("no", "false", "f", "0"): | ||
return False | ||
return True |
Oops, something went wrong.