From: a.sreekumar Date: Thu, 29 Aug 2019 13:24:04 +0000 (+0000) Subject: Change policy-distribution csit test cases X-Git-Tag: 6.0.0-ONAP~170^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=df7d47f59562eea8cc541f6751465cd4563df679;p=integration%2Fcsit.git Change policy-distribution csit test cases Change policy-distribution csit test cases to support ToscaPolicyType and ToscaPolicy. Change-Id: Ic6539a2c6f3d2a5b0a4a0b66ce456512d909a320 Issue-ID: POLICY-1893 Signed-off-by: a.sreekumar --- diff --git a/plans/policy/distribution/setup.sh b/plans/policy/distribution/setup.sh index a7c0a8da..399df0e6 100644 --- a/plans/policy/distribution/setup.sh +++ b/plans/policy/distribution/setup.sh @@ -1,6 +1,9 @@ #!/bin/bash # ============LICENSE_START======================================================= # Copyright (C) 2018 Ericsson. All rights reserved. +# +# Modifications copyright (c) 2019 Nordix Foundation. +# Modifications Copyright (C) 2019 AT&T Intellectual Property. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,24 +19,93 @@ # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= -# Select branch + source ${SCRIPTS}/policy/config/policy-csit.conf +export POLICY_MARIADB_VER echo ${GERRIT_BRANCH} +echo ${POLICY_MARIADB_VER} + +echo "Uninstall docker-py and reinstall docker." +pip uninstall -y docker-py +pip uninstall -y docker +pip install -U docker==2.7.0 + +# the directory of the script +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +echo ${DIR} + +# the temp directory used, within $DIR +# omit the -p parameter to create a temporal directory in the default location +WORK_DIR=`mktemp -d -p "$DIR"` +echo ${WORK_DIR} + +cd ${WORK_DIR} + +# check if tmp dir was created +if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then + echo "Could not create temp dir" + exit 1 +fi + +# bring down maven +mkdir maven +cd maven +curl -O http://apache.claz.org/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz +tar -xzvf apache-maven-3.3.9-bin.tar.gz +ls -l +export PATH=${PATH}:${WORK_DIR}/maven/apache-maven-3.3.9/bin +${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn -v +cd .. + +git clone http://gerrit.onap.org/r/oparent +git clone --depth 1 https://gerrit.onap.org/r/policy/models -b ${GERRIT_BRANCH} +cd models/models-sim/models-sim-dmaap +${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn clean install -DskipTests --settings ${WORK_DIR}/oparent/settings.xml +bash ./src/main/package/docker/docker_build.sh +cd ${WORKSPACE} +rm -rf ${WORK_DIR} +sleep 3 sudo apt-get -y install libxml2-utils +export POLICY_API_VERSION="$(curl -q --silent https://git.onap.org/policy/api/plain/pom.xml?h=${GERRIT_BRANCH} | xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' -)" +export POLICY_PAP_VERSION="$(curl -q --silent https://git.onap.org/policy/pap/plain/pom.xml?h=${GERRIT_BRANCH} | xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' -)" +export POLICY_APEX_PDP_VERSION="$(curl -q --silent https://git.onap.org/policy/apex-pdp/plain/pom.xml?h=${GERRIT_BRANCH} | xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' -)" export POLICY_DISTRIBUTION_VERSION="$(curl -q --silent https://git.onap.org/policy/distribution/plain/pom.xml?h=${GERRIT_BRANCH} | xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' -)" + +echo ${POLICY_API_VERSION} +echo ${POLICY_PAP_VERSION} +echo ${POLICY_APEX_PDP_VERSION} echo ${POLICY_DISTRIBUTION_VERSION} -docker run -d --name policy-distribution -p 6969:6969 -it nexus3.onap.org:10001/onap/policy-distribution:${POLICY_DISTRIBUTION_VERSION} +SCRIPT_DIR=${WORKSPACE}/scripts/policy/policy-distribution + +# Remaking the csar file in case if the file got corrupted +zip -F ${SCRIPT_DIR}/config/distribution/csar/sample_csar_with_apex_policy.csar --out ${SCRIPT_DIR}/config/distribution/csar/csar_temp.csar + +# Adding this waiting container due to race condition between pap and mariadb +docker-compose -f ${SCRIPT_DIR}/docker-compose-distribution.yml run --rm start_dependencies + +#Configure the database +docker exec -it mariadb chmod +x /docker-entrypoint-initdb.d/db.sh +docker exec -it mariadb /docker-entrypoint-initdb.d/db.sh + +# now bring everything else up +docker-compose -f ${SCRIPT_DIR}/docker-compose-distribution.yml run --rm start_all + +unset http_proxy https_proxy + +POLICY_API_IP=`get-instance-ip.sh policy-api` +POLICY_PAP_IP=`get-instance-ip.sh policy-pap` +MARIADB_IP=`get-instance-ip.sh mariadb` +APEX_IP=`get-instance-ip.sh policy-apex-pdp` +DMAAP_IP=`get-instance-ip.sh dmaap-simulator` POLICY_DISTRIBUTION_IP=`get-instance-ip.sh policy-distribution` -echo DISTRIBUTION IP IS ${POLICY_DISTRIBUTION_IP} - -${SCRIPTS}/policy/wait_for_port.sh ${POLICY_DISTRIBUTION_IP} 6969 -rc=$? -if [[ $rc != 0 ]]; then - echo "cannot open ${POLICY_DISTRIBUTION_IP} 6969" - docker logs policy-distribution - exit $rc -fi -ROBOT_VARIABLES="-v POLICY_DISTRIBUTION_IP:${POLICY_DISTRIBUTION_IP}" +echo PAP IP IS ${POLICY_PAP_IP} +echo MARIADB IP IS ${MARIADB_IP} +echo API IP IS ${POLICY_API_IP} +echo APEX IP IS ${APEX_IP} +echo DMAAP_IP IS ${DMAAP_IP} +echo POLICY_DISTRIBUTION_IP IS ${POLICY_DISTRIBUTION_IP} + +ROBOT_VARIABLES="-v APEX_IP:${APEX_IP} -v SCRIPT_DIR:${SCRIPT_DIR} -v POLICY_DISTRIBUTION_IP:${POLICY_DISTRIBUTION_IP}" diff --git a/plans/policy/distribution/teardown.sh b/plans/policy/distribution/teardown.sh index 562df6b3..fbbf1de5 100644 --- a/plans/policy/distribution/teardown.sh +++ b/plans/policy/distribution/teardown.sh @@ -1,6 +1,8 @@ #!/bin/bash # ============LICENSE_START======================================================= # Copyright (C) 2018 Ericsson. All rights reserved. +# +# Modifications copyright (c) 2019 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,4 +19,9 @@ # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= +kill-instance.sh policy-apex-pdp +kill-instance.sh policy-pap +kill-instance.sh policy-api +kill-instance.sh mariadb +kill-instance.sh dmaap-simulator kill-instance.sh policy-distribution diff --git a/scripts/policy/policy-distribution/config/db/db.conf b/scripts/policy/policy-distribution/config/db/db.conf new file mode 100644 index 00000000..4768bfc4 --- /dev/null +++ b/scripts/policy/policy-distribution/config/db/db.conf @@ -0,0 +1,16 @@ +# Copyright (C) 2019 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. +MYSQL_ROOT_PASSWORD=secret +MYSQL_USER=policy_user +MYSQL_PASSWORD=policy_user diff --git a/scripts/policy/policy-distribution/config/db/db.sh b/scripts/policy/policy-distribution/config/db/db.sh new file mode 100644 index 00000000..660f2c5a --- /dev/null +++ b/scripts/policy/policy-distribution/config/db/db.sh @@ -0,0 +1,22 @@ +#!/bin/bash -xv +# Copyright (C) 2019 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. + +for db in policyadmin +do + mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "CREATE DATABASE IF NOT EXISTS ${db};" + mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "GRANT ALL PRIVILEGES ON \`${db}\`.* TO '${MYSQL_USER}'@'%' ;" +done + +mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "FLUSH PRIVILEGES;" diff --git a/scripts/policy/policy-distribution/config/distribution/csar/sample_csar_with_apex_policy.csar b/scripts/policy/policy-distribution/config/distribution/csar/sample_csar_with_apex_policy.csar new file mode 100644 index 00000000..f2436cb6 Binary files /dev/null and b/scripts/policy/policy-distribution/config/distribution/csar/sample_csar_with_apex_policy.csar differ diff --git a/scripts/policy/policy-distribution/config/distribution/defaultConfig.json b/scripts/policy/policy-distribution/config/distribution/defaultConfig.json new file mode 100644 index 00000000..facee9bc --- /dev/null +++ b/scripts/policy/policy-distribution/config/distribution/defaultConfig.json @@ -0,0 +1,72 @@ +{ + "name":"SDCDistributionGroup", + "restServerParameters":{ + "host":"0.0.0.0", + "port":6969, + "userName":"healthcheck", + "password":"zb!XztG34", + "https": true + }, + "receptionHandlerParameters":{ + "FileReceptionHandler":{ + "receptionHandlerType":"File", + "receptionHandlerClassName":"org.onap.policy.distribution.reception.handling.file.FileSystemReceptionHandler", + "receptionHandlerConfigurationName":"fileConfiguration", + "pluginHandlerParameters":{ + "policyDecoders":{ + "ApexDecoder":{ + "decoderType":"ApexDecoder", + "decoderClassName":"org.onap.policy.distribution.reception.decoding.policy.file.PolicyDecoderFileInCsarToPolicy", + "decoderConfigurationName": "apexDecoderConfiguration" + } + }, + "policyForwarders":{ + "LifeCycleApiForwarder":{ + "forwarderType":"LifeCycleAPI", + "forwarderClassName":"org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiPolicyForwarder", + "forwarderConfigurationName": "lifecycleApiConfiguration" + } + } + } + } + }, + "receptionHandlerConfigurationParameters":{ + "fileConfiguration":{ + "parameterClassName":"org.onap.policy.distribution.reception.handling.file.FileSystemReceptionHandlerConfigurationParameterGroup", + "parameters":{ + "watchPath": "/opt/app/policy/distribution/etc/temp/", + "maxThread": 1 + } + } + }, + "policyDecoderConfigurationParameters":{ + "apexDecoderConfiguration":{ + "parameterClassName":"org.onap.policy.distribution.reception.decoding.policy.file.PolicyDecoderFileInCsarToPolicyParameterGroup", + "parameters":{ + "policyFileName": "apex_policy.json", + "policyTypeFileName": "apex_policy_type.json" + } + } + }, + "policyForwarderConfigurationParameters":{ + "lifecycleApiConfiguration":{ + "parameterClassName":"org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiForwarderParameters", + "parameters":{ + "apiParameters": { + "hostName": "policy-api", + "port": 6969, + "userName": "healthcheck", + "password": "zb!XztG34" + }, + "papParameters": { + "hostName": "policy-pap", + "port": 6969, + "userName": "healthcheck", + "password": "zb!XztG34" + }, + "isHttps": true, + "deployPolicies": true + } + } + } +} diff --git a/scripts/policy/policy-distribution/config/distribution/temp/sample_csar_with_apex_policy.csar b/scripts/policy/policy-distribution/config/distribution/temp/sample_csar_with_apex_policy.csar new file mode 100644 index 00000000..f2436cb6 Binary files /dev/null and b/scripts/policy/policy-distribution/config/distribution/temp/sample_csar_with_apex_policy.csar differ diff --git a/scripts/policy/policy-distribution/docker-compose-distribution.yml b/scripts/policy/policy-distribution/docker-compose-distribution.yml new file mode 100644 index 00000000..f2398908 --- /dev/null +++ b/scripts/policy/policy-distribution/docker-compose-distribution.yml @@ -0,0 +1,109 @@ +# Copyright (C) 2019 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. +version: '2' +networks: + default: + driver: bridge +services: + mariadb: + image: mariadb:${POLICY_MARIADB_VER} + container_name: mariadb + hostname: mariadb + command: ['--lower-case-table-names=1', '--wait_timeout=28800'] + env_file: config/db/db.conf + volumes: + - ./config/db:/docker-entrypoint-initdb.d + ports: + - "3306:3306" + message-router: + image: dmaap/simulator + container_name: dmaap-simulator + hostname: dmaap-simulator + ports: + - "3904:3904" + policy-pap: + image: nexus3.onap.org:10001/onap/policy-pap:${POLICY_PAP_VERSION} + container_name: policy-pap + depends_on: + - mariadb + - message-router + hostname: policy-pap + + + policy-api: + image: nexus3.onap.org:10001/onap/policy-api:${POLICY_API_VERSION} + container_name: policy-api + depends_on: + - mariadb + hostname: policy-api + + + distribution: + image: nexus3.onap.org:10001/onap/policy-distribution:${POLICY_DISTRIBUTION_VERSION} + container_name: policy-distribution + hostname: policy-distribution + volumes: + - ./config/distribution/defaultConfig.json:/opt/app/policy/distribution/etc/defaultConfig.json + - ./config/distribution/temp/:/opt/app/policy/distribution/etc/temp/ + depends_on: + - mariadb + - message-router + - policy-pap + - policy-api + - apex + + apex: + image: nexus3.onap.org:10001/onap/policy-apex-pdp:${POLICY_APEX_PDP_VERSION} + container_name: policy-apex-pdp + depends_on: + - mariadb + - message-router + - policy-pap + hostname: policy-apex-pdp + command: ['/opt/app/policy/apex-pdp/bin/apexOnapPf.sh', '-c', '/opt/app/policy/apex-pdp/etc/onappf/config/OnapPfConfig.json'] + ports: + - "6969:6969" + - "23324:23324" + start_dependencies: + image: dadarek/wait-for-dependencies + environment: + TIMEOUT_LENGTH: 60 + container_name: policy-wait + depends_on: + - mariadb + - message-router + hostname: policy-wait + command: + mariadb:3306 + message-router:3904 + start_all: + image: dadarek/wait-for-dependencies + environment: + TIMEOUT_LENGTH: 60 + container_name: policy-wait-all + depends_on: + - mariadb + - message-router + - policy-api + - policy-pap + - apex + - distribution + hostname: policy-wait-all + command: + mariadb:3306 + message-router:3904 + policy-api:6969 + policy-pap:6969 + apex:6969 + distribution:6969 diff --git a/tests/policy/distribution/data/event.json b/tests/policy/distribution/data/event.json new file mode 100644 index 00000000..9dbf2790 --- /dev/null +++ b/tests/policy/distribution/data/event.json @@ -0,0 +1,11 @@ +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "REST_0", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1536363522018, + "TestTemperature": 9080.866 +} diff --git a/tests/policy/distribution/distribution-test.robot b/tests/policy/distribution/distribution-test.robot index 34dd169c..2b1c6d64 100644 --- a/tests/policy/distribution/distribution-test.robot +++ b/tests/policy/distribution/distribution-test.robot @@ -5,9 +5,10 @@ Library OperatingSystem Library json *** Test Cases *** + Healthcheck [Documentation] Runs Policy Distribution Health check - ${auth}= Create List healthcheck zb!XztG34 + ${auth}= Create List healthcheck zb!XztG34 Log Creating session https://${POLICY_DISTRIBUTION_IP}:6969 ${session}= Create Session policy https://${POLICY_DISTRIBUTION_IP}:6969 auth=${auth} ${headers}= Create Dictionary Accept=application/json Content-Type=application/json @@ -15,9 +16,10 @@ Healthcheck Log Received response from policy ${resp.text} Should Be Equal As Strings ${resp.status_code} 200 Should Be Equal As Strings ${resp.json()['code']} 200 + Statistics [Documentation] Runs Policy Distribution Statistics - ${auth}= Create List healthcheck zb!XztG34 + ${auth}= Create List healthcheck zb!XztG34 Log Creating session https://${POLICY_DISTRIBUTION_IP}:6969 ${session}= Create Session policy https://${POLICY_DISTRIBUTION_IP}:6969 auth=${auth} ${headers}= Create Dictionary Accept=application/json Content-Type=application/json @@ -25,3 +27,19 @@ Statistics Log Received response from policy ${resp.text} Should Be Equal As Strings ${resp.status_code} 200 Should Be Equal As Strings ${resp.json()['code']} 200 + +InvokeDistributionAndRunEventOnEngine + Wait Until Keyword Succeeds 5 min 30 sec InvokeDistributionUsingFile And RunEventOnApexEngine + +*** Keywords *** + +InvokeDistributionUsingFile And RunEventOnApexEngine + Copy File ${SCRIPT_DIR}/config/distribution/csar/csar_temp.csar ${SCRIPT_DIR}/config/distribution/csar/temp.csar + Move File ${SCRIPT_DIR}/config/distribution/csar/temp.csar ${SCRIPT_DIR}/config/distribution/temp/sample_csar_with_apex_policy.csar + Sleep 20 seconds "Waiting for the Policy Distribution to call Policy API and PAP" + Create Session apexSession http://${APEX_IP}:23324 max_retries=1 + ${data}= Get Binary File ${CURDIR}${/}data${/}event.json + &{headers}= Create Dictionary Content-Type=application/json Accept=application/json + ${resp}= Put Request apexSession /apex/FirstConsumer/EventIn data=${data} headers=${headers} + Should Be Equal As Strings ${resp.status_code} 200 + Remove Files ${SCRIPT_DIR}/config/distribution/temp/sample_csar_with_apex_policy.csar