Skip to content

Commit

Permalink
Merge pull request kubeflow#43 from tonyxrmdavidson/updateRestScript
Browse files Browse the repository at this point in the history
This commit adds rest api testing to the openshift-ci deployment
  • Loading branch information
tonyxrmdavidson authored Apr 12, 2024
2 parents 76e7721 + dc30932 commit 77fc4a9
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 78 deletions.
27 changes: 19 additions & 8 deletions openshift-ci/scripts/oci-model-registry-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MODEL_REGISTRY_CRDS="modelregistries.modelregistry.opendatahub.io"
source "openshift-ci/scripts/colour_text_variables.sh"

# Function to monitor CRDS creation and deployment.

# The function takes two arguments, reference to manifest and a wait time in seconds.
monitoring_crds_installation() {
IFS=',' read -ra crds_array <<< "$1"
local timeout=$2
Expand All @@ -28,7 +28,7 @@ monitoring_crds_installation() {

# Check if timeout has been reached
if [ "$elapsed_time" -ge "$timeout" ]; then
echo "Timeout reached. Installation of CRDs failed."
echo -e "${RED}X Error:${NC} Timeout reached. Installation of CRDs failed."
return 1
fi

Expand All @@ -46,7 +46,7 @@ monitoring_crds_installation() {

# If all CRDs are installed, break out of the loop
if [ "$all_installed" = true ]; then
echo "All specified CRDs are installed."
echo -e "${GREEN}✔ Success:${NC} All specified CRDs are installed."
return 0
fi

Expand All @@ -65,6 +65,7 @@ monitoring_crds_installation() {
}

# Function to deploy and wait for deployment
# The function takes two arguments, reference to manifest and a wait time in seconds.
deploy_and_wait() {
local manifest=$1
local resource_name=$(basename -s .yaml $manifest)
Expand All @@ -77,7 +78,7 @@ deploy_and_wait() {
if oc apply -f $manifest --wait=true --timeout=300s; then
echo -e "${GREEN}✔ Success:${NC} Deployment of $resource_name succeeded."
else
echo -e "${RED}Error:${NC} Deployment of $resource_name failed or timed out." >&2
echo -e "${RED}X Error:${NC} Deployment of $resource_name failed or timed out." >&2
return 1
fi
}
Expand All @@ -102,10 +103,12 @@ check_deployment_availability() {
sleep 5 # Wait for 5 seconds before checking again
done

echo -e "${RED}Error:${NC} Timeout reached. Deployment $deployment did not become available within $timeout seconds"
echo -e "${RED}X Error:${NC} Timeout reached. Deployment $deployment did not become available within $timeout seconds"
return 1 # Failure
}

# Function to check the status of deploying pods
# The function takes three arguments, namespace, descriptor to identify the component and number of containers expected.
check_pod_status() {
local namespace="$1"
local pod_selector="$2"
Expand Down Expand Up @@ -145,6 +148,8 @@ check_pod_status() {
return 1 # Failure
}

# Function to check the status of a route
# The function takes two arguments, namespace and route name.
check_route_status() {
local namespace="$1"
local route_name="$2"
Expand All @@ -159,7 +164,7 @@ check_route_status() {
local route_url="http://$route"

if [[ -z "$route_url" ]]; then
echo -e "${RED}Error:${NC} Route '$route_name' does not exist in namespace '$namespace'"
echo -e "${RED}X Error:${NC} Route '$route_name' does not exist in namespace '$namespace'"
return 1
else
echo -e "${GREEN}✔ Success:${NC} Route '$route_name' exists in namespace '$namespace'"
Expand All @@ -176,16 +181,21 @@ check_route_status() {
echo -e "${GREEN}✔ Success:${NC} Route server is reachable. Status code: 404 Not Found"
return 0
else
echo -e "${RED}Error:${NC} Route server is unreachable. Status code: $response"
echo -e "${RED}X Error:${NC} Route server is unreachable. Status code: $response"
fi

sleep "$interval"
done

echo -e "${RED}Error:${NC} Timeout reached. Route '$route_name' did not become live within $timeout seconds."
echo -e "${RED}X Error:${NC} Timeout reached. Route '$route_name' did not become live within $timeout seconds."
return 1
}

# Function to source the rest api tests and run them.
run_api_tests() {
source "test/scripts/rest.sh"
}

# Run the deployment tests.
run_deployment_tests() {
check_deployment_availability default model-registry-db
Expand All @@ -207,6 +217,7 @@ main() {
monitoring_crds_installation $MODEL_REGISTRY_CRDS 120
deploy_and_wait $MODEL_REGISTRY_DB_MANIFEST 20
run_deployment_tests
run_api_tests
}

# Execute main function
Expand Down
167 changes: 97 additions & 70 deletions test/scripts/rest.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
MR_HOSTNAME="http://$(oc get route modelregistry-sample-http --template='{{.spec.host}}')"
source "openshift-ci/scripts/colour_text_variables.sh"

# Function to send data and extract ID from response
make_post_extract_id() {
local url="$1"
local data="$2"
Expand All @@ -9,89 +12,113 @@ make_post_extract_id() {
-d "$data" | jq -r '.id')

if [ -z "$id" ]; then
echo "Error: Failed to extract ID from response"
echo -e "${RED}Error:${NC} Error: Failed to extract ID from response"
exit 1
else
echo "$id"
fi

echo "$id"
}

# TODO: finalize using openshift-ci values.
OCP_CLUSTER_NAME="PROVIDE OCP CLUSTER NAME FOR OPENSHIFT-CI"
MR_NAMESPACE="shared-modelregistry-ns"
MR_HOSTNAME="http://modelregistry-sample-http-$MR_NAMESPACE.apps.$OCP_CLUSTER_NAME"

timestamp=$(date +"%Y%m%d%H%M%S")
rm_name="demo-$timestamp"
# Function to post model registry data
post_model_registry_data() {
timestamp=$(date +"%Y%m%d%H%M%S")
rm_name="demo-$timestamp"

rm_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha3/registered_models" '{
"description": "lorem ipsum registered model",
"name": "'"$rm_name"'"
}')
rm_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha2/registered_models" '{
"description": "lorem ipsum registered model",
"name": "'"$rm_name"'"
}')

if [ $? -ne 0 ]; then
exit 1
fi
echo "Registered Model ID: $rm_id"
if [ $? -ne 0 ]; then
echo -e "${RED}Error:${NC} Registered Model ID not returned"
exit 1
else
echo -e "${GREEN}✔ Success:${NC} Registered Model ID: $rm_id"
fi

mv_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha3/model_versions" '{
"description": "lorem ipsum model version",
"name": "v1",
"author": "John Doe",
"registeredModelId": "'"$rm_id"'"
}')
mv_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha2/model_versions" '{
"description": "lorem ipsum model version",
"name": "v1",
"author": "John Doe",
"registeredModelId": "'"$rm_id"'"
}')

if [ $? -ne 0 ]; then
exit 1
fi
echo "Model Version ID: $mv_id"
if [ $? -ne 0 ]; then
echo -e "${RED}Error:${NC} Model Version ID not returned"
exit 1
else
echo -e "${GREEN}✔ Success:${NC} Model Version ID: $mv_id"
fi

RAW_ML_MODEL_URI='https://huggingface.co/tarilabs/mnist/resolve/v1.nb20231206162408/mnist.onnx'
ma_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha3/model_versions/$mv_id/artifacts" '{
"description": "lorem ipsum model artifact",
"uri": "'"$RAW_ML_MODEL_URI"'",
"name": "mnist",
"modelFormatName": "onnx",
"modelFormatVersion": "1",
"storageKey": "aws-connection-unused",
"storagePath": "unused just demo",
"artifactType": "model-artifact"
}')
RAW_ML_MODEL_URI='https://huggingface.co/tarilabs/mnist/resolve/v1.nb20231206162408/mnist.onnx'
ma_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha2/model_versions/$mv_id/artifacts" '{
"description": "lorem ipsum model artifact",
"uri": "'"$RAW_ML_MODEL_URI"'",
"name": "mnist",
"modelFormatName": "onnx",
"modelFormatVersion": "1",
"storageKey": "aws-connection-unused",
"storagePath": "unused just demo",
"artifactType": "model-artifact"
}')

if [ $? -ne 0 ]; then
exit 1
fi
echo "Model Artifact ID: $ma_id"
if [ $? -ne 0 ]; then
echo -e "${RED}Error:${NC} Model Artifact ID not returned"
exit 1
else
echo -e "${GREEN}✔ Success:${NC} Model Artifact ID: $ma_id"
fi
}

ISVC_TARGET_NS=odh-project-b
MODEL_SERVER_NAME=modelserverb
# Function to test deployment of second odh-project
odh_project_b() {
ISVC_TARGET_NS=odh-project-b
MODEL_SERVER_NAME=modelserverb

oc apply -n $ISVC_TARGET_NS -f - <<EOF
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "$rm_name"
annotations:
"openshift.io/display-name": "$rm_name"
"serving.kserve.io/deploymentMode": "ModelMesh"
labels:
"mr-registered-model-id": "$rm_id"
"mr-model-version-id": "$mv_id"
"mr-namespace": "$MR_NAMESPACE"
"opendatahub.io/dashboard": "true"
spec:
predictor:
model:
modelFormat:
name: "onnx"
version: "1"
runtime: "$MODEL_SERVER_NAME"
storageUri: "$RAW_ML_MODEL_URI"
oc apply -n $ISVC_TARGET_NS -f - <<EOF
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "$rm_name"
annotations:
"openshift.io/display-name": "$rm_name"
"serving.kserve.io/deploymentMode": "ModelMesh"
labels:
"mr-registered-model-id": "$rm_id"
"mr-model-version-id": "$mv_id"
"mr-namespace": "$MR_NAMESPACE"
"opendatahub.io/dashboard": "true"
spec:
predictor:
model:
modelFormat:
name: "onnx"
version: "1"
runtime: "$MODEL_SERVER_NAME"
storageUri: "$RAW_ML_MODEL_URI"
EOF
}

# Function to test Inference Service
# TODO this will continue once we have MC PR merged from: https://github.com/opendatahub-io/odh-model-controller/pull/135
iss_mr=$(curl -s -X 'GET' "$MR_HOSTNAME/api/model_registry/v1alpha3/inference_services" \
-H 'accept: application/json')
inference_service() {
iss_mr=$(curl -s -X 'GET' "$MR_HOSTNAME/api/model_registry/v1alpha2/inference_services" \
-H 'accept: application/json')

if [ $? -ne 0 ]; then
echo -e "${RED}Error:${NC} InferenceService entities on MR not returned"
exit 1
else
echo -e "${GREEN}✔ Success:${NC} InferenceService entities on MR: $iss_mr"
fi
}

# Main function for orchestrating test
main() {
post_model_registry_data
# odh_project_b
# inference_service
}

echo "InferenceService entities on MR:"
echo "$iss_mr"
# Execute main function
main

0 comments on commit 77fc4a9

Please sign in to comment.