From f624e57b58aebbd0a17ea2b0007b1279e2a380e6 Mon Sep 17 00:00:00 2001 From: tonyxrmdavidson Date: Wed, 10 Apr 2024 15:32:13 +0100 Subject: [PATCH] This commit adds rest api testing to the openshift-ci deployment --- .../scripts/oci-model-registry-deploy.sh | 27 ++- test/scripts/rest.sh | 167 ++++++++++-------- 2 files changed, 116 insertions(+), 78 deletions(-) diff --git a/openshift-ci/scripts/oci-model-registry-deploy.sh b/openshift-ci/scripts/oci-model-registry-deploy.sh index 2746a68d..a7406aff 100755 --- a/openshift-ci/scripts/oci-model-registry-deploy.sh +++ b/openshift-ci/scripts/oci-model-registry-deploy.sh @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 } @@ -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" @@ -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" @@ -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'" @@ -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 @@ -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 diff --git a/test/scripts/rest.sh b/test/scripts/rest.sh index 81e36f44..8b304b1c 100755 --- a/test/scripts/rest.sh +++ b/test/scripts/rest.sh @@ -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" @@ -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 - <