diff options
author | 2019-03-14 16:45:23 +0000 | |
---|---|---|
committer | 2019-03-14 16:49:19 +0000 | |
commit | b4bf5da37571048d346865815984db5f6be479c1 (patch) | |
tree | 7eebf9d5a9fd423d7c6a2a11890acb53ecc9186b | |
parent | 918a0f524bc9727f3bc8d9abe041bb3087a3c766 (diff) |
Adding Policy/drools-pdp CSIT "Alive" Test
Issue-ID: POLICY-1459
Signed-off-by: Bilal A <bilal@research.att.com>
Change-Id: I2e33e18feaff5882eb45012ffab16f47f3153c41
-rwxr-xr-x | plans/policy/drools-pdp/setup.sh | 45 | ||||
-rwxr-xr-x | plans/policy/drools-pdp/teardown.sh | 36 | ||||
-rw-r--r-- | plans/policy/drools-pdp/testplan.txt | 3 | ||||
-rwxr-xr-x | scripts/policy/drools-pdp-script.sh | 208 | ||||
-rw-r--r-- | tests/policy/drools-pdp/drools-pdp-test.robot | 17 |
5 files changed, 309 insertions, 0 deletions
diff --git a/plans/policy/drools-pdp/setup.sh b/plans/policy/drools-pdp/setup.sh new file mode 100755 index 00000000..a7ed4408 --- /dev/null +++ b/plans/policy/drools-pdp/setup.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Copyright 2017 AT&T Intellectual Property. 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. +# +# Place the scripts in run order: +source ${SCRIPTS}/common_functions.sh + +docker run --name i-mock -d jamesdbloom/mockserver +MOCK_IP=`get-instance-ip.sh i-mock` +echo ${MOCK_IP} + +docker inspect i-mock + +# Wait for initialization +for i in {1..10}; do + curl -sS ${MOCK_IP}:1080 && break + echo sleep $i + sleep $i +done + +${WORKSPACE}/scripts/policy/mock-hello.sh ${MOCK_IP} + +source ${WORKSPACE}/scripts/policy/drools-pdp-script.sh + +# Pass any variables required by Robot test suites in ROBOT_VARIABLES +ROBOT_VARIABLES="-v MOCK_IP:${MOCK_IP} -v IP:${IP} -v POLICY_IP:${POLICY_IP} -v PDP_IP:${PDP_IP} -v DOCKER_IP:${DOCKER_IP}" +export PDP_IP=${PDP_IP} +export POLICY_IP=${POLICY_IP} +export DOCKER_IP=${DOCKER_IP} + +#Get current IP of VM +HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}') +export HOST_IP=${HOST_IP} diff --git a/plans/policy/drools-pdp/teardown.sh b/plans/policy/drools-pdp/teardown.sh new file mode 100755 index 00000000..f1f0b21c --- /dev/null +++ b/plans/policy/drools-pdp/teardown.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright 2017 AT&T Intellectual Property. 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. +# + +function kill_instance() { +local name=$1 +docker logs "${name}" >> "${WORKSPACE}"/archives/"${name}".log +docker kill "${name}" +docker rm -v "${name}" +} + +mkdir -p "${WORKSPACE}"/archives + +kill_instance i-mock +kill_instance drools +kill_instance pdp +kill_instance brmsgw +kill_instance pap +kill_instance nexus +kill_instance mariadb + +rm -fr "${WORK_DIR}" + diff --git a/plans/policy/drools-pdp/testplan.txt b/plans/policy/drools-pdp/testplan.txt new file mode 100644 index 00000000..ccdc8ff9 --- /dev/null +++ b/plans/policy/drools-pdp/testplan.txt @@ -0,0 +1,3 @@ +# Test suites are relative paths under [integration/csit.git]/tests/. +# Place the suites in run order. +policy/drools-pdp diff --git a/scripts/policy/drools-pdp-script.sh b/scripts/policy/drools-pdp-script.sh new file mode 100755 index 00000000..0a128faf --- /dev/null +++ b/scripts/policy/drools-pdp-script.sh @@ -0,0 +1,208 @@ +#!/bin/bash +# +# Copyright 2017-2018 AT&T Intellectual Property. 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. +# +echo "This is ${WORKSPACE}/scripts/policy/drools-pdp-script.sh" + + +# 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 .. + +ifconfig + +export IP=`ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}'` +if [ -z "$IP" ]; then + echo "Could not determine IP address" + exit 1 +fi +echo $IP + +if ! ifconfig docker0; then + export DOCKER_IP="$IP" +else + export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` +fi +echo $DOCKER_IP + +git clone http://gerrit.onap.org/r/oparent + +git clone http://gerrit.onap.org/r/policy/engine +cd engine/packages/docker +${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml +docker build -t onap/policy-pe target/policy-pe + +cd ${WORK_DIR} +git clone http://gerrit.onap.org/r/policy/drools-pdp +cd drools-pdp/packages/docker +${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml +docker build -t onap/policy-drools target/policy-drools + +cd ${WORK_DIR} +git clone http://gerrit.onap.org/r/policy/docker +cd docker + +chmod +x config/drools/drools-tweaks.sh + +echo $IP > config/pe/ip_addr.txt +ls -l config/pe/ip_addr.txt +cat config/pe/ip_addr.txt + +export MTU=9126 + +export PRELOAD_POLICIES=false +docker-compose -f docker-compose-integration.yml up -d + +if [ ! $? -eq 0 ]; then + echo "Docker compose failed" + exit 1 +fi + +docker ps + +POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools` +echo ${POLICY_IP} + +PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp` +echo ${PDP_IP} + +PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap` +echo ${PAP_IP} + +BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw` +echo ${BRMS_IP} + +NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus` +echo ${NEXUS_IP} + +MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb` +echo ${MARIADB_IP} + +sleep 3m + +docker logs mariadb 2>&1 | grep -q "mysqld: ready for connections" +if [ $? -eq 0 ]; then + # mariadb is ok - sleep a little longer for others + sleep 2m + +else + echo mariadb is not ready + echo Restarting... + + docker kill drools pdp pap brmsgw nexus mariadb + docker rm -f drools pdp pap brmsgw nexus mariadb + + docker-compose -f docker-compose-integration.yml up -d + + if [ ! $? -eq 0 ]; then + echo "Docker compose failed" + exit 1 + fi + + docker ps + + POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools` + echo ${POLICY_IP} + + PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp` + echo ${PDP_IP} + + PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap` + echo ${PAP_IP} + + BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw` + echo ${BRMS_IP} + + NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus` + echo ${NEXUS_IP} + + MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb` + echo ${MARIADB_IP} + + sleep 5m +fi + +netstat -tnl + +docker logs mariadb +${DIR}/wait_for_port.sh ${MARIADB_IP} 3306 + +docker logs pap +${DIR}/wait_for_port.sh ${PAP_IP} 9091 + +docker logs pdp +${DIR}/wait_for_port.sh ${PDP_IP} 8081 + +docker logs brmsgw +${DIR}/wait_for_port.sh ${BRMS_IP} 9989 + +docker logs nexus +${DIR}/wait_for_port.sh ${NEXUS_IP} 8081 + +docker logs drools +${DIR}/wait_for_port.sh ${POLICY_IP} 9696 + +TIME_OUT=600 +INTERVAL=20 +TIME=0 +while [ "$TIME" -lt "$TIME_OUT" ]; do + curl -k -i --user "demo@people.osaaf.org:demo123456!" -H "ContentType: application/json" -H "Accept: application/json" https://${POLICY_IP}:9696/healthcheck && break + + echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds + sleep $INTERVAL + TIME=$(($TIME+$INTERVAL)) + +done + +TIME_OUT=600 +INTERVAL=20 +TIME=0 +while [ "$TIME" -lt "$TIME_OUT" ]; do + + curl -k -i -v -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -H 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' -H 'Environment: TEST' -d '{"policyName": ".*"}' https://${PDP_IP}:8081/pdp/api/getConfig && break + +echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds + sleep $INTERVAL + TIME=$(($TIME+$INTERVAL)) + +done + +# +# Add more sleep for everything to settle +# +sleep 3m diff --git a/tests/policy/drools-pdp/drools-pdp-test.robot b/tests/policy/drools-pdp/drools-pdp-test.robot new file mode 100644 index 00000000..fdb46a92 --- /dev/null +++ b/tests/policy/drools-pdp/drools-pdp-test.robot @@ -0,0 +1,17 @@ +*** Settings *** +Library Collections +Library RequestsLibrary +Library OperatingSystem +Library json + +*** Test Cases *** +Alive + [Documentation] Runs Policy PDP Alive Check + ${auth}= Create List demo@people.osaaf.org demo123456! + Log Creating session https://${POLICY_IP}:9696 + ${session}= Create Session policy https://${POLICY_IP}:9696 auth=${auth} + ${headers}= Create Dictionary Accept=application/json Content-Type=application/json + ${resp}= Get Request policy /policy/pdp/engine headers=${headers} + Log Received response from policy ${resp.text} + Should Be Equal As Strings ${resp.status_code} 200 + Should Be Equal As Strings ${resp.json()['alive']} True |