From d44fceebbd37108a15f45fbf5813d413efeb2ac6 Mon Sep 17 00:00:00 2001 From: Ruslan Kashapov Date: Fri, 26 Feb 2021 11:42:29 +0200 Subject: CSIT: Integration tests for CPS Core + also fixes issue with fragment_id sequence not reflecting data loaded Issue-ID: CPS-261 Change-Id: If590d6a0859a1acc9005dd2da952b7dd93a23059 Signed-off-by: Ruslan Kashapov --- .../changelog/db/changes/05-loadData-fragment.yaml | 10 ++++ csit/data/test-tree.json | 28 +++++++++++ csit/data/test-tree.yang | 24 ++++++++++ csit/data/yang-resources.zip | Bin 0 -> 17598 bytes csit/plans/default/setup.sh | 16 +++++-- csit/plans/default/teardown.sh | 4 +- csit/plans/default/testplan.txt | 2 + csit/prepare-csit.sh | 9 +--- csit/run-csit.sh | 3 +- csit/run-project-csit.sh | 3 +- csit/scripts/actuator/check_endpoint.sh | 33 ------------- csit/tests/actuator/__init__.robot | 2 - csit/tests/actuator/actuator.robot | 23 ++++----- csit/tests/cps-admin/cps-admin.robot | 53 +++++++++++++++++++++ csit/tests/cps-data/cps-data.robot | 31 ++++++++++++ 15 files changed, 179 insertions(+), 62 deletions(-) create mode 100644 csit/data/test-tree.json create mode 100644 csit/data/test-tree.yang create mode 100644 csit/data/yang-resources.zip delete mode 100755 csit/scripts/actuator/check_endpoint.sh delete mode 100644 csit/tests/actuator/__init__.robot create mode 100644 csit/tests/cps-admin/cps-admin.robot create mode 100644 csit/tests/cps-data/cps-data.robot diff --git a/cps-ri/src/main/resources/changelog/db/changes/05-loadData-fragment.yaml b/cps-ri/src/main/resources/changelog/db/changes/05-loadData-fragment.yaml index 1a31f424a..8abf980d8 100644 --- a/cps-ri/src/main/resources/changelog/db/changes/05-loadData-fragment.yaml +++ b/cps-ri/src/main/resources/changelog/db/changes/05-loadData-fragment.yaml @@ -40,3 +40,13 @@ databaseChangeLog: header: schema_node_id name: schema_node_id type: NUMERIC + + - changeSet: + author: cps + label: xnf-data-preload + id: 5.1 + changes: + - sql: + comment: Fixes the id sequence after data insert with predefined ids + dbms: postgresql + sql: ALTER SEQUENCE IF EXISTS fragment_id_seq RESTART WITH 200 \ No newline at end of file diff --git a/csit/data/test-tree.json b/csit/data/test-tree.json new file mode 100644 index 000000000..bc9cbd7ce --- /dev/null +++ b/csit/data/test-tree.json @@ -0,0 +1,28 @@ +{ + "test-tree": { + "branch": [ + { + "name": "Left", + "nest": { + "name": "Small", + "birds": [ + "Sparrow", + "Robin", + "Finch" + ] + } + }, + { + "name": "Right", + "nest": { + "name": "Big", + "birds": [ + "Owl", + "Raven", + "Crow" + ] + } + } + ] + } +} \ No newline at end of file diff --git a/csit/data/test-tree.yang b/csit/data/test-tree.yang new file mode 100644 index 000000000..faba8a11d --- /dev/null +++ b/csit/data/test-tree.yang @@ -0,0 +1,24 @@ +module test-tree { + yang-version 1.1; + + namespace "org:onap:cps:test:test-tree"; + prefix tree; + revision "2020-02-02"; + + container test-tree { + list branch { + key "name"; + leaf name { + type string; + } + container nest { + leaf name { + type string; + } + leaf-list birds { + type string; + } + } + } + } +} diff --git a/csit/data/yang-resources.zip b/csit/data/yang-resources.zip new file mode 100644 index 000000000..8e5808662 Binary files /dev/null and b/csit/data/yang-resources.zip differ diff --git a/csit/plans/default/setup.sh b/csit/plans/default/setup.sh index e7e8f4bfc..4d5d1c85c 100755 --- a/csit/plans/default/setup.sh +++ b/csit/plans/default/setup.sh @@ -18,6 +18,8 @@ # Modifications copyright (c) 2020-2021 Samsung Electronics Co., Ltd. # Modifications Copyright (C) 2021 Pantheon.tech # +# Branched from ccsdk/distribution to this repository Feb 23, 2021 +# # Copy docker-compose.yml and application.yml to archives mkdir -p $WORKSPACE/archives/docker-compose @@ -31,18 +33,22 @@ export DB_PASSWORD=cps # Use latest image version export VERSION=latest +# download docker-compose of a required version (1.25.0 supports configuration of version 3.7) +curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > docker-compose +chmod +x docker-compose + # start CPS and PostgreSQL containers with docker compose -docker-compose up -d +./docker-compose up -d # Validate CPS service initialization completed via periodic log checking for line like below: # org.onap.cps.Application ... Started Application in X.XXX seconds TIME_OUT=300 -INTERVAL=10 +INTERVAL=5 TIME=0 while [ "$TIME" -le "$TIME_OUT" ]; do - LOG_FOUND=$( docker-compose logs --tail="all" | grep "org.onap.cps.Application" | egrep -c "Started Application in" ) + LOG_FOUND=$( ./docker-compose logs --tail="all" | grep "org.onap.cps.Application" | egrep -c "Started Application in" ) if [ "$LOG_FOUND" -gt 0 ]; then echo "CPS Service started" @@ -59,9 +65,9 @@ if [ "$TIME" -gt "$TIME_OUT" ]; then exit 1; fi -# TODO localhost works on a local environment, check if it's ok on jenkins +# The CPS host according to docker-compose.yml CPS_HOST="http://localhost:8883" # Pass variables required for Robot test suites in ROBOT_VARIABLES -ROBOT_VARIABLES="-v SCRIPTS:$SCRIPTS -v CPS_HOST:$CPS_HOST" +ROBOT_VARIABLES="-v CPS_HOST:$CPS_HOST -v DATADIR:$WORKSPACE/data" diff --git a/csit/plans/default/teardown.sh b/csit/plans/default/teardown.sh index 90280259c..f9368f9df 100755 --- a/csit/plans/default/teardown.sh +++ b/csit/plans/default/teardown.sh @@ -18,6 +18,8 @@ # Modifications copyright (c) 2020 Samsung Electronics Co., Ltd. # Modifications Copyright (C) 2021 Pantheon.tech # +# Branched from ccsdk/distribution to this repository Feb 23, 2021 +# cd $WORKSPACE/archives/docker-compose -docker-compose down -v +./docker-compose down -v diff --git a/csit/plans/default/testplan.txt b/csit/plans/default/testplan.txt index edcad0dfd..e4e875988 100644 --- a/csit/plans/default/testplan.txt +++ b/csit/plans/default/testplan.txt @@ -1,4 +1,6 @@ # Test suites are relative paths under csit/tests/. # Place the suites in run order. actuator +cps-admin +cps-data diff --git a/csit/prepare-csit.sh b/csit/prepare-csit.sh index 05d99a732..d46b17ae0 100755 --- a/csit/prepare-csit.sh +++ b/csit/prepare-csit.sh @@ -1,6 +1,7 @@ #!/bin/bash -x # # Copyright 2019-2021 © Samsung Electronics Co., Ltd. +# Modifications Copyright (C) 2021 Pantheon.tech # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +17,7 @@ # # This script installs common libraries required by CSIT tests # - -# Branched from integration/csit to this repository 18.2.2021 +# Branched from ccsdk/distribution to this repository Feb 23, 2021 # if [ -z "$WORKSPACE" ]; then @@ -43,10 +43,5 @@ else source /tmp/ci-management/jjb/integration/include-raw-integration-install-robotframework.sh fi -# install eteutils -mkdir -p ${ROBOT_VENV}/src/onap -rm -rf ${ROBOT_VENV}/src/onap/testsuite -#pip install --upgrade --extra-index-url="https://nexus3.onap.org/repository/PyPi.staging/simple" 'robotframework-onap==0.5.1.*' --pre - pip freeze diff --git a/csit/run-csit.sh b/csit/run-csit.sh index e23e84a3f..9220ef9cb 100755 --- a/csit/run-csit.sh +++ b/csit/run-csit.sh @@ -18,8 +18,7 @@ # $1 project/functionality # $2 robot options -# Branched from integration/csit to this repository 18.2.2021 -# +# Branched from ccsdk/distribution to this repository Feb 23, 2021 # # functions diff --git a/csit/run-project-csit.sh b/csit/run-project-csit.sh index 1df826722..a231c5e16 100755 --- a/csit/run-project-csit.sh +++ b/csit/run-project-csit.sh @@ -1,6 +1,7 @@ #!/bin/bash -x # # Copyright 2020-2021 © Samsung Electronics Co., Ltd. +# Modifications Copyright (C) 2021 Pantheon.tech # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# Modifications Copyright (C) 2021 Pantheon.tech +# Branched from ccsdk/distribution to this repository Feb 23, 2021 # # $1 test options (passed on to run-csit.sh as such) diff --git a/csit/scripts/actuator/check_endpoint.sh b/csit/scripts/actuator/check_endpoint.sh deleted file mode 100755 index 7a8cac796..000000000 --- a/csit/scripts/actuator/check_endpoint.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -# -# ============LICENSE_START======================================================= -# Copyright (C) 2021 Pantheon.tech -# ================================================================================ -# 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========================================================= -# - -# $1 is endpoint for GET request - -echo "Testing CPS actuator endpoint $1" - -response=$(curl -o /dev/null -s -w "%{http_code}\n" -H "Accept: application/json" -H "Content-Type: application/json" -X GET $1) - -if [ "$response" == "200" ]; then - echo "CPS Actuator endpoint check successful." - exit 0; -fi - -echo "CPS Actuator endpoint check failed with response code ${response}." -exit 1 diff --git a/csit/tests/actuator/__init__.robot b/csit/tests/actuator/__init__.robot deleted file mode 100644 index 714f3c3c8..000000000 --- a/csit/tests/actuator/__init__.robot +++ /dev/null @@ -1,2 +0,0 @@ -*** Settings *** -Documentation CPS - Actuator endpoints diff --git a/csit/tests/actuator/actuator.robot b/csit/tests/actuator/actuator.robot index 59c76073a..1253dffbf 100644 --- a/csit/tests/actuator/actuator.robot +++ b/csit/tests/actuator/actuator.robot @@ -1,18 +1,19 @@ *** Settings *** -Library OperatingSystem -Library Process +Documentation CPS - Actuator endpoints + +Library Collections +Library RequestsLibrary + +Suite Setup Create Session CPS_HOST ${CPS_HOST} *** Variables *** -${check} ${SCRIPTS}/actuator/check_endpoint.sh *** Test Cases *** -Liveness Probe for CPS - [Documentation] Liveness Probe - ${result}= Run Process bash ${check} ${CPS_HOST}/manage/health/liveness >> actuator-test.log shell=yes - Should Be Equal As Integers ${result.rc} 0 +Test Liveness Probe Endpoint + ${response}= GET On Session CPS_HOST /manage/health/liveness expected_status=200 + Should Be Equal As Strings ${response.json()['status']} UP -Readiness Probe for CPS - [Documentation] Readiness Probe - ${result}= Run Process bash ${check} ${CPS_HOST}/manage/health/readiness >> actuator-test.log shell=yes - Should Be Equal As Integers ${result.rc} 0 +Test Readiness Probe Endpoint + ${response}= GET On Session CPS_HOST /manage/health/readiness expected_status=200 + Should Be Equal As Strings ${response.json()['status']} UP \ No newline at end of file diff --git a/csit/tests/cps-admin/cps-admin.robot b/csit/tests/cps-admin/cps-admin.robot new file mode 100644 index 000000000..446a59b86 --- /dev/null +++ b/csit/tests/cps-admin/cps-admin.robot @@ -0,0 +1,53 @@ +*** Settings *** +Documentation CPS Core - Admin REST API + +Library Collections +Library OperatingSystem +Library RequestsLibrary + +Suite Setup Create Session CPS_HOST ${CPS_HOST} + +*** Variables *** + +${basePath} /cps/api +${dataspaceName} CSIT-Dataspace +${schemaSetName} CSIT-SchemaSet +${anchorName} CSIT-Anchor + +*** Test Cases *** +Create Dataspace + ${uri}= Set Variable ${basePath}/v1/dataspaces + ${params}= Create Dictionary dataspace-name=${dataspaceName} + ${response}= POST On Session CPS_HOST ${uri} params=${params} + Should Be Equal As Strings ${response.status_code} 201 + +Create Schema Set from YANG file + ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/schema-sets + ${params}= Create Dictionary schema-set-name=${schemaSetName} + ${fileData}= Get Binary File ${DATADIR}${/}test-tree.yang + ${fileTuple}= Create List test.yang ${fileData} application/zip + &{files}= Create Dictionary file=${fileTuple} + ${response}= POST On Session CPS_HOST ${uri} files=${files} params=${params} + Should Be Equal As Strings ${response.status_code} 201 + +Create Schema Set from ZIP file + ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/schema-sets + ${params}= Create Dictionary schema-set-name=ZipTestSchemaSet + ${fileData}= Get Binary File ${DATADIR}${/}yang-resources.zip + ${fileTuple}= Create List test.zip ${fileData} application/zip + &{files}= Create Dictionary file=${fileTuple} + ${response}= POST On Session CPS_HOST ${uri} files=${files} params=${params} + Should Be Equal As Strings ${response.status_code} 201 + +Get Schema Set info + ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/schema-sets/${schemaSetName} + ${response}= Get On Session CPS_HOST ${uri} expected_status=200 + ${responseJson}= Set Variable ${response.json()} + Should Be Equal As Strings ${responseJson['name']} ${schemaSetName} + Should Be Equal As Strings ${responseJson['dataspaceName']} ${dataspaceName} + +Create Anchor + ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors + ${params}= Create Dictionary schema-set-name=${schemaSetName} anchor-name=${anchorName} + ${response}= POST On Session CPS_HOST ${uri} params=${params} + Should Be Equal As Strings ${response.status_code} 201 \ No newline at end of file diff --git a/csit/tests/cps-data/cps-data.robot b/csit/tests/cps-data/cps-data.robot new file mode 100644 index 000000000..8b0202b3b --- /dev/null +++ b/csit/tests/cps-data/cps-data.robot @@ -0,0 +1,31 @@ +*** Settings *** +Documentation CPS Core - Data REST API + +Library Collections +Library OperatingSystem +Library RequestsLibrary + +Suite Setup Create Session CPS_HOST ${CPS_HOST} + +*** Variables *** + +${basePath} /cps/api +${dataspaceName} CSIT-Dataspace +${anchorName} CSIT-Anchor + +*** Test Cases *** +Create Data Node + ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/nodes + ${headers} Create Dictionary Content-Type=application/json + ${jsonData}= Get Binary File ${DATADIR}${/}test-tree.json + ${response}= POST On Session CPS_HOST ${uri} headers=${headers} data=${jsonData} + Should Be Equal As Strings ${response.status_code} 201 + +Get Data Node by XPath + ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/node + ${params}= Create Dictionary xpath=/test-tree/branch[@name='Left']/nest + ${response}= Get On Session CPS_HOST ${uri} params=${params} expected_status=200 + ${responseJson}= Set Variable ${response.json()} + Should Be Equal As Strings ${responseJson['name']} Small + + -- cgit 1.2.3-korg