From fc332c16dd83b76f31010ee5922bacdb568970e4 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Thu, 8 Feb 2024 14:47:02 +0100 Subject: [PATCH] add Shell script openshift-ci make some REST call to MR In the scope of testing of Model Registry in openshift-ci: - make a Shell script which invokes some REST calls to MR, - so to make sure the REST endpoint is responsive, - then create a K8s ISVC on the cluster, - and display the MR InferenceService entities. Later, in a subsequent issue/PR, once: opendatahub-io/odh-model-controller#135 is merged, the last bulletpoint can be automated and placed under test in the final part of this script so to make sure the K8s ISVC on the cluster reflected as a precise MR InferenceService entity. --- test/scripts/rest.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 test/scripts/rest.sh diff --git a/test/scripts/rest.sh b/test/scripts/rest.sh new file mode 100755 index 0000000..5397147 --- /dev/null +++ b/test/scripts/rest.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +make_post_extract_id() { + local url="$1" + local data="$2" + local id=$(curl -s -X POST "$url" \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d "$data" | jq -r '.id') + + if [ -z "$id" ]; then + echo "Error: Failed to extract ID from response" + exit 1 + fi + + echo "$id" +} + +# TODO: finalize using openshift-ci values. +OCP_CLUSTER_NAME="rosa.mmortari-rosa-h.w0x4.p3.openshiftapps.com" +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" + +rm_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha1/registered_models" '{ + "description": "lorem ipsum registered model", + "name": "'"$rm_name"'" +}') + +if [ $? -ne 0 ]; then + exit 1 +fi +echo "Registered Model ID: $rm_id" + +mv_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha1/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" + +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/v1alpha1/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" + +ISVC_TARGET_NS=odh-project-b +MODEL_SERVER_NAME=modelserverb + +oc apply -n $ISVC_TARGET_NS -f - <