Skip to content

Commit

Permalink
Creating specific rest script for tls
Browse files Browse the repository at this point in the history
This commit introduces istio-tls- rest.sh script which is specific to the istio-tls deployment
It adds the certs/ to gitignore
It makes changes to the oci-model-registry-istio-tls-deploy.sh script to point to the correct rest.sh

Signed-off-by: tonyxrmdavidson <tonyxrmdavidson@yahoo.co.uk>
  • Loading branch information
tonyxrmdavidson committed Jun 26, 2024
1 parent c37e964 commit 414a75c
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ __pycache__
# Protoc files
include/
readme.txt

# do not send certs
certs/
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ check_route_status() {

# Function to source the rest api tests and run them.
run_api_tests() {
./test/scripts/rest.sh "-n istio-system" "$TOKEN" ../certs/domain.crt
./test/scripts/istio-tls-rest.sh "-n istio-system" "$TOKEN" ../certs/domain.crt
}

# Run the deployment tests.
Expand Down
126 changes: 126 additions & 0 deletions test/scripts/istio-tls-rest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/bash
FLAG_WITH_NAMESPACE=$1
TOKEN=$2
CERT="certs/domain.crt"
MR_HOSTNAME="https://$(oc get route odh-model-registries-modelregistry-sample-rest $FLAG_WITH_NAMESPACE --template='{{.spec.host}}')"

# Function to send data and extract ID from response
make_post_extract_id() {
local url="$1"
local data="$2"
local id=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" --cacert certs/domain.crt "$url" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "$data" | jq -r '.id')

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

# 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"'"
}')

if [ $? -ne 0 ]; then
echo -e "Error: Registered Model ID not returned"
exit 1
else
echo -e "Success: 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"'"
}')

if [ $? -ne 0 ]; then
echo -e "Error: Model Version ID not returned"
exit 1
else
echo -e "Success: 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"
}')

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

# 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"
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
inference_service() {
iss_mr=$(curl -s -X 'GET' "$MR_HOSTNAME/api/model_registry/v1alpha3/inference_services" \
-H 'accept: application/json')

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

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

# Execute main function
main
8 changes: 3 additions & 5 deletions test/scripts/rest.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/bin/bash
FLAG_WITH_NAMESPACE=$1
TOKEN=$2
CERT="certs/domain.crt"
MR_HOSTNAME="https://$(oc get route odh-model-registries-modelregistry-sample-rest $FLAG_WITH_NAMESPACE --template='{{.spec.host}}')"
MR_HOSTNAME="http://$(oc get route modelregistry-sample-http $FLAG_WITH_NAMESPACE --template='{{.spec.host}}')"

# Function to send data and extract ID from response
make_post_extract_id() {
local url="$1"
local data="$2"
local id=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" --cacert certs/domain.crt "$url" \
local id=$(curl -s -X POST "$url" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "$data" | jq -r '.id')
Expand Down Expand Up @@ -123,4 +121,4 @@ main() {
}

# Execute main function
main
main

0 comments on commit 414a75c

Please sign in to comment.