From: Ashish Jain Date: Fri, 7 Nov 2025 11:06:30 +0000 (+0000) Subject: Add Intial Smoke Tests for MME X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=fe1b423d7f39f5c733734c154154e7ed529fa114;p=aiml-fw%2Fawmf%2Fmodelmgmtservice.git Add Intial Smoke Tests for MME The tests added are as follows: 1. Registers the model and verifies if it is retrievable using model_id. 2. Verifies if correct message and code is responsed when user tries to retrieve model but the model_id doesn't exist. Issue-id: AIMLFW-310 Change-Id: I4169a915c2b67774d203e87e6bd46bcf5ef5b246 Signed-off-by: ashishj1729 --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9145383 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +pytest_report.html +assets \ No newline at end of file diff --git a/component-testing/local-testing/run_test.sh b/component-testing/local-testing/run_test.sh new file mode 100644 index 0000000..5f1d859 --- /dev/null +++ b/component-testing/local-testing/run_test.sh @@ -0,0 +1,26 @@ +# ================================================================================== +# +# Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== + + +# Since, Kind cluster runs in a docker container, therefore it is required to port-forward the svc to connect +kubectl port-forward svc/mme-modelmgmtservice -n traininghost 32007:8082 & PF_PID=$! +sleep 1 +python3 -m pytest ../tests/ --maxfail=1 --disable-warnings -q --html=pytest_report.html + +# Stop port-forwarding +kill $PF_PID \ No newline at end of file diff --git a/component-testing/tests/requirements.txt b/component-testing/tests/requirements.txt new file mode 100644 index 0000000..06625aa --- /dev/null +++ b/component-testing/tests/requirements.txt @@ -0,0 +1,19 @@ +# ================================================================================== +# +# Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== +pytest +pytest-html \ No newline at end of file diff --git a/component-testing/tests/test_component.py b/component-testing/tests/test_component.py new file mode 100644 index 0000000..e183d9b --- /dev/null +++ b/component-testing/tests/test_component.py @@ -0,0 +1,88 @@ +# ================================================================================== +# +# Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== +import requests +import pytest + +BASE_URL = "http://localhost:32007" + +def get_model_registration_payload(): + return { + "modelId": { + "modelName": "placeholder", + "modelVersion" : "placeholder" + }, + "description": "hello world2", + "modelInformation": { + "metadata": { + "author": "someone" + }, + "inputDataType": "pdcpBytesDl,pdcpBytesUl", + "outputDataType": "c, d", + "targetEnvironment": [ + { + "platformName": "abc", + "environmentType": "env", + "dependencyList": "a,b,c" + } + ] + } + } + +def submit_model_registration(modelName, modelVersion): + ''' + Helper function to register model and returns the model_id + ''' + url = f"{BASE_URL}/ai-ml-model-registration/v1/model-registrations/" + payload = get_model_registration_payload() + payload["modelId"]["modelName"] = modelName + payload["modelId"]["modelVersion"] = modelVersion + r = requests.post(url=url, json=payload) + assert r.status_code == 201, f"Job Submission didn't returned 201 but returned {r.status_code}" + model_id = r.json().get("modelInfo").get("id") + return model_id + + +def test_model_registration_and_retrieval(): + ''' + The following test verifies that a model-registration can be successfully submitted and that its model-id is retrievable via the corresponding API. + ''' + # Submit the Model-registraion job + modelName = "test-model" + modelVersion = "10003" + model_id = submit_model_registration(modelName, modelVersion) + + # Check job Status through id + retrieval_url = f"{BASE_URL}/ai-ml-model-registration/v1/model-registrations/{model_id}" + r = requests.get(url=retrieval_url) + response_dict = r.json() + assert r.status_code == 200, f"Model Retrieval by id didn't returned 200, but returned {r.status_code}" + assert response_dict.get("id") == model_id, "model_id submitted and retrieved doesn't match" + +def test_job_status_retrieval_when_job_not_present(): + ''' + The following test verifies how model-retrieval happens when the model is not registered/present + ''' + model_id = "invalid" + expected_message = "record not found" + # Check job Status through id + retrieval_url = f"{BASE_URL}/ai-ml-model-registration/v1/model-registrations/{model_id}" + r = requests.get(url=retrieval_url) + response_dict = r.json() + assert r.status_code == 500, f"Model Retrieval by id (when id not present) didn't returned 500, but returned {r.status_code}" + assert response_dict.get("message") == expected_message, "message(in response) submitted and retrieved doesn't match" +