aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2023-03-16 10:38:50 +0000
committerwaqas.ikram <waqas.ikram@est.tech>2023-03-16 12:02:18 +0000
commiteeea948482f30782bde5c06dad1b008b9ea7dbdc (patch)
tree25a3d11d08ff28178646a620bf8440811c25b82d
parent0ca039c5f7d9339607f138d560c553159b0092e2 (diff)
Adding verification of kube resources
after instantiation and delete Change-Id: Id50bcc5e863bbc4300d79b2885dc464372a09c9e Issue-ID: SO-4087 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
-rwxr-xr-xplans/so/integration-cnfm-testing/config/distribution-test-zip/zipped_cnf_csar.tar.gz (renamed from plans/so/integration-cnfm-testing/config/distribution-test-zip/unzipped/unzipped_cnf_csar/v1/catalog/services/EricssonDemoService1/1.0/artifacts/service-EricssonDemoService1-csar.csar)bin332839 -> 330829 bytes
-rwxr-xr-xplans/so/integration-cnfm-testing/setup.sh4
-rw-r--r--tests/so/integration-cnfm-testing/cnf_lcm_tests.robot45
-rw-r--r--tests/so/integration-cnfm-testing/libraries/KubernetesClient.py61
4 files changed, 105 insertions, 5 deletions
diff --git a/plans/so/integration-cnfm-testing/config/distribution-test-zip/unzipped/unzipped_cnf_csar/v1/catalog/services/EricssonDemoService1/1.0/artifacts/service-EricssonDemoService1-csar.csar b/plans/so/integration-cnfm-testing/config/distribution-test-zip/zipped_cnf_csar.tar.gz
index 7c8223e8..30d606fa 100755
--- a/plans/so/integration-cnfm-testing/config/distribution-test-zip/unzipped/unzipped_cnf_csar/v1/catalog/services/EricssonDemoService1/1.0/artifacts/service-EricssonDemoService1-csar.csar
+++ b/plans/so/integration-cnfm-testing/config/distribution-test-zip/zipped_cnf_csar.tar.gz
Binary files differ
diff --git a/plans/so/integration-cnfm-testing/setup.sh b/plans/so/integration-cnfm-testing/setup.sh
index 66a7cde9..28b0fc60 100755
--- a/plans/so/integration-cnfm-testing/setup.sh
+++ b/plans/so/integration-cnfm-testing/setup.sh
@@ -216,6 +216,10 @@ if [ $? -ne 0 ] || [ ! -f "$KIND_CLUSTER_KUBE_CONFIG_FILE" ]; then
exit 1
fi
+# install required libraries
+echo "Installing kubernetes python client library"
+pip install kubernetes
+
# Pass variables required in robot test suites in ROBOT_VARIABLES
REPO_IP='127.0.0.1'
ROBOT_VARIABLES="-v REPO_IP:${REPO_IP} -v KIND_CLUSTER_KUBE_CONFIG_FILE:${KIND_CLUSTER_KUBE_CONFIG_FILE}"
diff --git a/tests/so/integration-cnfm-testing/cnf_lcm_tests.robot b/tests/so/integration-cnfm-testing/cnf_lcm_tests.robot
index 85838861..98531973 100644
--- a/tests/so/integration-cnfm-testing/cnf_lcm_tests.robot
+++ b/tests/so/integration-cnfm-testing/cnf_lcm_tests.robot
@@ -3,6 +3,7 @@ Library Collections
Library RequestsLibrary
Library OperatingSystem
Library json
+Library libraries/KubernetesClient.py
Documentation Test cases for CNF lifecycle management operations
... Note, relies on:
@@ -17,6 +18,14 @@ ${CNF_RESOURCE_INSTANTIATION_TEMPLATE}= ${CURDIR}${/}data${/}cnfResourceInsta
${CNF_RESOURCE_DELETE_TEMPLATE}= ${CURDIR}${/}data${/}cnfResourceDeleteRequest.json
${SERVICE_DELETE_TEMPLATE}= ${CURDIR}${/}data${/}serviceDeleteRequest.json
+${LABEL_NAME}= app.kubernetes.io/instance
+${MARIADB_LABEL_SELECTOR}= ${LABEL_NAME}=democnfinstance-mariadb-db-1
+${EXPECTED_NUM_OF_RESOURCES_AFTER_INSTANTIATION}= 1
+
+${NGINX_LABEL_SELECTOR}= ${LABEL_NAME}=democnfinstance-nginx-services-2
+${EXPECTED_NUM_OF_RESOURCES_AFTER_DELETE}= 0
+
+
*** Test Cases ***
Invoke Service Instantiation
Create Session api_handler_session http://${REPO_IP}:8080
@@ -30,7 +39,6 @@ Invoke Service Instantiation
${service_instantiation_json_response}= Evaluate json.loads(r"""${service_instantiation_request.content}""", strict=False) json
${request_ID}= Set Variable ${service_instantiation_json_response}[requestReferences][requestId]
${service_instance_Id}= Set Variable ${service_instantiation_json_response}[requestReferences][instanceId]
- Set Global Variable ${service_instance_Id}
${actual_request_state}= Set Variable ""
FOR ${INDEX} IN RANGE ${MAXIMUM_ATTEMPTS_BEFORE_TIMEOUT}
@@ -47,6 +55,7 @@ Invoke Service Instantiation
Log To Console Final repsonse status received: ${actual_request_state}
Should Be Equal As Strings '${actual_request_state}' 'COMPLETE'
+ Set Global Variable ${service_instance_Id}
Invoke CNF Instantiation
Run Keyword If "${service_instance_Id}"!="${EMPTY}" Log to Console Service Instance ID :${service_instance_Id} received
@@ -68,7 +77,6 @@ Invoke CNF Instantiation
${request_ID}= Set Variable ${cnf_instantiate_json_response}[requestReferences][requestId]
${actual_request_state}= Set Variable ""
${cnf_instance_Id}= Set Variable ${cnf_instantiate_json_response}[requestReferences][instanceId]
- SET GLOBAL VARIABLE ${cnf_instance_Id}
FOR ${INDEX} IN RANGE ${MAXIMUM_ATTEMPTS_BEFORE_TIMEOUT}
${orchestration_status_request}= Get On Session api_handler_session /onap/so/infra/orchestrationRequests/v7/${request_ID}
@@ -85,6 +93,9 @@ Invoke CNF Instantiation
Log To Console Final repsonse status received: ${actual_request_state}
Should Be Equal As Strings '${actual_request_state}' 'COMPLETE'
+ Verify Kubernetes Resources ${EXPECTED_NUM_OF_RESOURCES_AFTER_INSTANTIATION}
+ Set Global Variable ${cnf_instance_Id}
+
Invoke CNF Delete
Run Keyword If "${cnf_instance_Id}" != "${EMPTY}" Log to Console CNF Instance ID :${cnf_instance_Id} received
... ELSE Fail Log to Console Invalid CNF Instance ID :${cnf_instance_Id} recieved
@@ -109,7 +120,7 @@ Invoke CNF Delete
Log To Console ${orchestration_status_request.content}
${orchestration_json_response}= Evaluate json.loads(r"""${orchestration_status_request.content}""") json
${actual_request_state}= Set Variable ${orchestration_json_response}[request][requestStatus][requestState]
- RUN KEYWORD IF '${actual_request_state}' == 'COMPLETE' or '${actual_request_state}' == 'FAILED' Exit For Loop
+ Run Keyword If '${actual_request_state}' == 'COMPLETE' or '${actual_request_state}' == 'FAILED' Exit For Loop
Log To Console Will try again after ${SLEEP_INTERVAL_SEC} seconds
SLEEP ${SLEEP_INTERVAL_SEC}s
END
@@ -117,6 +128,8 @@ Invoke CNF Delete
Log To Console Final repsonse status received: ${actual_request_state}
Should Be Equal As Strings '${actual_request_state}' 'COMPLETE'
+ Verify Kubernetes Resources ${EXPECTED_NUM_OF_RESOURCES_AFTER_DELETE}
+
Delete Service Instance
Run Keyword If "${service_instance_Id}" != "${EMPTY}" Log to Console CNF Instance ID :${service_instance_Id} received
... ELSE Fail Log to Console Invalid Service Instance ID :${service_instance_Id} recieved
@@ -139,10 +152,32 @@ Delete Service Instance
Log To Console ${orchestration_status_request.content}
${orchestration_json_response}= Evaluate json.loads(r"""${orchestration_status_request.content}""") json
${actual_request_state}= Set Variable ${orchestration_json_response}[request][requestStatus][requestState]
- RUN KEYWORD IF '${actual_request_state}' == 'COMPLETE' or '${actual_request_state}' == 'FAILED' Exit For Loop
+ Run Keyword If '${actual_request_state}' == 'COMPLETE' or '${actual_request_state}' == 'FAILED' Exit For Loop
Log To Console Will try again after ${SLEEP_INTERVAL_SEC} seconds
SLEEP ${SLEEP_INTERVAL_SEC}s
END
Log To Console Final repsonse status received: ${actual_request_state}
- Should Be Equal As Strings '${actual_request_state}' 'COMPLETE' \ No newline at end of file
+ Should Be Equal As Strings '${actual_request_state}' 'COMPLETE'
+
+*** Keywords ***
+Verify Kubernetes Resources
+ [Arguments] ${expected_number_resources}
+
+ Create Api Client ${KIND_CLUSTER_KUBE_CONFIG_FILE}
+
+ Log To Console Retrieving number of services using selector '${MARIADB_LABEL_SELECTOR}'
+ ${no_of_mariadb_services}= Get Number Of Services In Namespace label_selector=${MARIADB_LABEL_SELECTOR}
+ Should Be Equal As Integers ${no_of_mariadb_services} ${expected_number_resources} Unexpected number of services received for ${MARIADB_LABEL_SELECTOR}
+
+ Log To Console Retrieving number of stateful set using selector '${MARIADB_LABEL_SELECTOR}'
+ ${no_of_mariadb_stateful_set}= Get Number Of Stateful Set In Namespace label_selector=${MARIADB_LABEL_SELECTOR}
+ Should Be Equal As Integers ${no_of_mariadb_stateful_set} ${expected_number_resources} Unexpected number of stateful sets received for ${MARIADB_LABEL_SELECTOR}
+
+ Log To Console Retrieving number of services using selector '${NGINX_LABEL_SELECTOR}'
+ ${no_of_nginx_services}= Get Number Of Services In Namespace label_selector=${NGINX_LABEL_SELECTOR}
+ Should Be Equal As Integers ${no_of_nginx_services} ${expected_number_resources} Unexpected number of services received for ${NGINX_LABEL_SELECTOR}
+
+ Log To Console Retrieving number of deployments using selector '${NGINX_LABEL_SELECTOR}'
+ ${no_of_nginx_deployments}= Get Number Of Deployments In Namespace label_selector=${NGINX_LABEL_SELECTOR}
+ Should Be Equal As Integers ${no_of_nginx_deployments} ${expected_number_resources} Unexpected number of deployments received for ${NGINX_LABEL_SELECTOR} \ No newline at end of file
diff --git a/tests/so/integration-cnfm-testing/libraries/KubernetesClient.py b/tests/so/integration-cnfm-testing/libraries/KubernetesClient.py
new file mode 100644
index 00000000..7145c04c
--- /dev/null
+++ b/tests/so/integration-cnfm-testing/libraries/KubernetesClient.py
@@ -0,0 +1,61 @@
+# ============LICENSE_START=======================================================
+# Copyright (C) 2023 Nordix Foundation.
+# ================================================================================
+# 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.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+#
+# @author Waqas Ikram (waqas.ikram@est.tech)
+
+from robot.api import logger
+from kubernetes import client, config
+from robot.api.deco import library
+
+
+@library(scope="GLOBAL", auto_keywords=True)
+class KubernetesClient:
+ def __init__(self):
+ self.api_client = None
+
+ def create_api_client(self, config_file):
+ logger.console("Initializing api client ..")
+ self.api_client = config.new_client_from_config(config_file)
+
+ def get_number_of_stateful_set_in_namespace(self, namespace="default", label_selector=""):
+ self.check_if_api_client_is_initialized()
+ api_client = client.AppsV1Api(api_client=self.api_client)
+ result = api_client.list_namespaced_stateful_set(namespace, watch=False, label_selector=label_selector)
+ if result.items is None:
+ return 0
+ return len(result.items)
+
+ def get_number_of_services_in_namespace(self, namespace="default", label_selector=""):
+ self.check_if_api_client_is_initialized()
+ api_client = client.CoreV1Api(api_client=self.api_client)
+ result = api_client.list_namespaced_service(namespace, watch=False, label_selector=label_selector)
+ if result.items is None:
+ return 0
+ return len(result.items)
+
+ def get_number_of_deployments_in_namespace(self, namespace="default", label_selector=""):
+ self.check_if_api_client_is_initialized()
+ api_client = client.AppsV1Api(api_client=self.api_client)
+ result = api_client.list_namespaced_deployment(namespace, watch=False, label_selector=label_selector)
+ if result.items is None:
+ return 0
+ return len(result.items)
+
+ def check_if_api_client_is_initialized(self):
+ if self.api_client is None:
+ raise TypeError("'api_client' is null")