Skip to content

Commit 70fb69d

Browse files
authored
Add commands for testing apis (#1763)
1 parent d514901 commit 70fb69d

File tree

3 files changed

+112
-4
lines changed

3 files changed

+112
-4
lines changed

Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ tools:
239239
@go get -u -v golang.org/x/lint/golint
240240
@go get -u -v github.com/VojtechVitek/rerun/cmd/rerun
241241
@go get -u -v github.com/go-delve/delve/cmd/dlv
242-
@python3 -m pip install aiohttp black 'pydoc-markdown>=3.0.0,<4.0.0'
243242
@if [[ "$$OSTYPE" == "darwin"* ]]; then brew install parallel; elif [[ "$$OSTYPE" == "linux"* ]]; then sudo apt-get install -y parallel; else echo "your operating system is not supported"; fi
243+
@python3 -m pip install aiohttp black 'pydoc-markdown>=3.0.0,<4.0.0'
244+
@python3 -m pip install -e test/e2e
244245

245246
format:
246247
@./dev/format.sh
@@ -258,6 +259,26 @@ test-go:
258259
test-python:
259260
@./build/test.sh python
260261

262+
# run e2e tests on existing cluster
263+
# read test/e2e/README.md for instructions first
264+
test-e2e:
265+
@$(MAKE) test-e2e-aws
266+
@$(MAKE) test-e2e-gcp
267+
test-e2e-aws:
268+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && CORTEX_CLI_PATH="$$(pwd)/bin/cortex" ./build/test.sh e2e -p aws -e "$$CORTEX_CLUSTER_NAME-aws"
269+
test-e2e-gcp:
270+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && CORTEX_CLI_PATH="$$(pwd)/bin/cortex" ./build/test.sh e2e -p gcp -e "$$CORTEX_CLUSTER_NAME-gcp"
271+
272+
# run e2e tests with new clusters
273+
# read test/e2e/README.md for instructions first
274+
test-e2e-new:
275+
@$(MAKE) test-e2e-new-aws
276+
@$(MAKE) test-e2e-new-gcp
277+
test-e2e-new-aws:
278+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && CORTEX_CLI_PATH="$$(pwd)/bin/cortex" ./build/test.sh e2e "$$(pwd)/dev/config/cluster-aws.yaml" -p aws --create-cluster
279+
test-e2e-new-gcp:
280+
@eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && CORTEX_CLI_PATH="$$(pwd)/bin/cortex" ./build/test.sh e2e "$$(pwd)/dev/config/cluster-gcp.yaml" -p gcp --create-cluster
281+
261282
lint:
262283
@./build/lint.sh
263284

build/test.sh

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,64 @@ set -euo pipefail
1919

2020
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
2121

22+
provider="undefined"
23+
cluster_env="undefined"
24+
create_cluster="no"
25+
positional_args=()
26+
while [[ $# -gt 0 ]]; do
27+
key="$1"
28+
case $key in
29+
-p|--provider)
30+
provider="$2"
31+
shift
32+
;;
33+
-e|--cluster-env)
34+
cluster_env="$2"
35+
shift
36+
;;
37+
-c|--create-cluster)
38+
create_cluster="yes"
39+
shift
40+
;;
41+
*)
42+
positional_args+=("$1")
43+
shift
44+
;;
45+
esac
46+
done
47+
set -- "${positional_args[@]}"
48+
positional_args=()
49+
for i in "$@"; do
50+
case $i in
51+
-p=*|--provider=*)
52+
provider="${i#*=}"
53+
shift
54+
;;
55+
-e=*|--cluster-env=*)
56+
cluster_env="${i#*=}"
57+
shift
58+
;;
59+
-c|--create-cluster)
60+
create_cluster="yes"
61+
shift
62+
;;
63+
*)
64+
positional_args+=("$1")
65+
shift
66+
;;
67+
esac
68+
done
69+
set -- "${positional_args[@]}"
70+
for arg in "$@"; do
71+
if [[ "$arg" == -* ]]; then
72+
echo "unknown flag: $arg"
73+
exit 1
74+
fi
75+
done
76+
77+
cmd=${1:-""}
78+
sub_cmd=${2:-""}
79+
2280
function run_go_tests() {
2381
(cd $ROOT && go test ./... && echo "go tests passed")
2482
}
@@ -28,12 +86,28 @@ function run_python_tests() {
2886
docker run cortexlabs/test
2987
}
3088

31-
cmd=${1:-""}
89+
function run_e2e_tests() {
90+
if [ "$provider" = "aws" ]; then
91+
if [ "$create_cluster" = "yes" ]; then
92+
pytest $ROOT/test/e2e/tests -k aws --aws-config "$sub_cmd"
93+
else
94+
pytest $ROOT/test/e2e/tests -k aws --aws-env "$cluster_env"
95+
fi
96+
elif [ "$provider" = "gcp" ]; then
97+
if [ "$create_cluster" = "yes" ]; then
98+
pytest $ROOT/test/e2e/tests -k gcp --gcp-config "$sub_cmd"
99+
else
100+
pytest $ROOT/test/e2e/tests -k gcp --gcp-env "$cluster_env"
101+
fi
102+
fi
103+
}
32104

33105
if [ "$cmd" = "go" ]; then
34106
run_go_tests
35107
elif [ "$cmd" = "python" ]; then
36108
run_python_tests
109+
elif [ "$cmd" = "e2e" ]; then
110+
run_e2e_tests
37111
else
38112
run_go_tests
39113
run_python_tests

test/e2e/e2e/cluster.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ def create_cluster(cluster_config: str):
2828
cluster_name = config["cluster_name"]
2929
provider = config["provider"]
3030

31+
if provider == "gcp":
32+
cluster_cmd = "cluster-gcp"
33+
else:
34+
cluster_cmd = "cluster"
35+
3136
p = subprocess.run(
3237
[
3338
"cortex",
34-
"cluster",
39+
cluster_cmd,
3540
"up",
3641
"-y",
3742
"--config",
@@ -49,8 +54,16 @@ def create_cluster(cluster_config: str):
4954

5055
def delete_cluster(cluster_config: str):
5156
"""Delete a cortex cluster from a cluster config"""
57+
with open(cluster_config) as f:
58+
config = yaml.safe_load(f)
59+
60+
if config["provider"] == "gcp":
61+
cluster_cmd = "cluster-gcp"
62+
else:
63+
cluster_cmd = "cluster"
64+
5265
p = subprocess.run(
53-
["cortex", "cluster", "down", "-y", "--config", cluster_config],
66+
["cortex", cluster_cmd, "down", "-y", "--config", cluster_config],
5467
stdout=sys.stdout,
5568
stderr=sys.stderr,
5669
)

0 commit comments

Comments
 (0)