CSIT Tests for PM Mapper

Change-Id: Iaa9274ba40eb8f74eb6a39e8a79a8b0d4e56a166
Issue-ID: INT-863
Signed-off-by: Rajendra Jaiswal <rajendra.jaiswal@ericsson.com>
diff --git a/plans/dcaegen2-pmmapper/pmmapper/assets/cbs.json b/plans/dcaegen2-pmmapper/pmmapper/assets/cbs.json
new file mode 100644
index 0000000..a29956f
--- /dev/null
+++ b/plans/dcaegen2-pmmapper/pmmapper/assets/cbs.json
@@ -0,0 +1,7 @@
+{
+    "ID": "cbs",
+    "Name": "config_binding_service",
+    "Tags": ["cbs"],
+    "Address": "ipaddress",
+    "Port": 10000
+}
\ No newline at end of file
diff --git a/plans/dcaegen2-pmmapper/pmmapper/assets/config.json b/plans/dcaegen2-pmmapper/pmmapper/assets/config.json
new file mode 100644
index 0000000..2fe128b
--- /dev/null
+++ b/plans/dcaegen2-pmmapper/pmmapper/assets/config.json
@@ -0,0 +1 @@
+{"pm-mapper-filter": "{ \"filters\":[]}", "3GPP.schema.file": "{\"3GPP_Schema\":\"./etc/3GPP_relaxed_schema.xsd\"}", "streams_subscribes": {}, "streams_publishes": {"pm_mapper_handle_out": {"type": "message_router", "aaf_password": null, "dmaap_info": {"topic_url": "https://we-are-message-router.us:3905/events/some-topic", "client_role": null, "location": null, "client_id": null}, "aaf_username": null}}, "streams_subscribes.pm_mapper_handle_out.message_router_topic": "unauthenticated.PM_VES_OUTPUT", "streams_subscribes.pm_mapper_handle_in.feed_id": "1", "services_calls": {}}
\ No newline at end of file
diff --git a/plans/dcaegen2-pmmapper/pmmapper/composefile/docker-compose-e2e.yml b/plans/dcaegen2-pmmapper/pmmapper/composefile/docker-compose-e2e.yml
new file mode 100644
index 0000000..af987f7
--- /dev/null
+++ b/plans/dcaegen2-pmmapper/pmmapper/composefile/docker-compose-e2e.yml
@@ -0,0 +1,61 @@
+version: '2.1'
+services:
+  datarouter-prov:
+    image: nexus3.onap.org:10001/onap/dmaap/datarouter-prov
+    container_name: datarouter-prov
+    hostname: dmaap-dr-prov
+    ports:
+     - "443:8443"
+     - "8443:8443"
+     - "8080:8080"
+    volumes:
+     - ../prov_data/provserver.properties:/opt/app/datartr/etc/provserver.properties
+     - ../prov_data/addSubscriber.txt:/opt/app/datartr/addSubscriber.txt
+     - ../prov_data/addFeed3.txt:/opt/app/datartr/addFeed3.txt
+    depends_on:
+      mariadb_container:
+        condition: service_healthy
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://dmaap-dr-prov:8080/internal/prov"]
+      interval: 10s
+      timeout: 10s
+      retries: 5
+
+  datarouter-node:
+    image: nexus3.onap.org:10001/onap/dmaap/datarouter-node
+    container_name: datarouter-node
+    hostname: dmaap-dr-node
+    ports:
+     - "9443:8443"
+     - "9090:8080"
+    volumes:
+     - ../node_data/node.properties:/opt/app/datartr/etc/node.properties
+    depends_on:
+      datarouter-prov:
+        condition: service_healthy
+
+  mariadb_container:
+    image: mariadb:10.2.14
+    container_name: mariadb
+    ports:
+      - "3306:3306"
+    environment:
+      MYSQL_ROOT_PASSWORD: datarouter
+      MYSQL_DATABASE: datarouter
+      MYSQL_USER: datarouter
+      MYSQL_PASSWORD: datarouter
+    healthcheck:
+      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "--silent"]
+      interval: 10s
+      timeout: 30s
+      retries: 5
+
+  consul:
+    container_name: consul
+    image: nexus3.onap.org:10001/consul:latest
+
+  cbs:
+    container_name: cbs
+    image: nexus3.onap.org:10001/onap/org.onap.dcaegen2.platform.configbinding.app-app:latest
+    environment:
+       CONSUL_HOST:
diff --git a/plans/dcaegen2-pmmapper/pmmapper/setup.sh b/plans/dcaegen2-pmmapper/pmmapper/setup.sh
new file mode 100644
index 0000000..326b4ac
--- /dev/null
+++ b/plans/dcaegen2-pmmapper/pmmapper/setup.sh
@@ -0,0 +1,118 @@
+#!/bin/bash
+# Place the scripts in run order:
+source ${SCRIPTS}/common_functions.sh
+
+# Clone DMaaP Message Router repo
+mkdir -p $WORKSPACE/archives/dmaapmr
+cd $WORKSPACE/archives/dmaapmr
+git clone --depth 1 http://gerrit.onap.org/r/dmaap/messagerouter/messageservice -b master
+sed -i 's/enableCadi: false/enableCadi: "false"/g' /$WORKSPACE/archives/dmaapmr/messageservice/src/main/resources/docker-compose/docker-compose.yml
+cd $WORKSPACE/archives/dmaapmr/messageservice/src/main/resources/docker-compose
+cp $WORKSPACE/archives/dmaapmr/messageservice/bundleconfig-local/etc/appprops/MsgRtrApi.properties /var/tmp/
+
+# start DMaaP MR containers with docker compose and configuration from docker-compose.yml
+docker login -u docker -p docker nexus3.onap.org:10001
+docker-compose up -d
+
+ZOOKEEPER=$(docker ps -a -q --filter="name=zookeeper_1")
+KAFKA=$(docker ps -a -q --filter="name=kafka_1")
+DMAAP=$(docker ps -a -q --filter="name=dmaap_1")
+
+# Wait for initialization of Docker contaienr for DMaaP MR, Kafka and Zookeeper
+for i in {1..10}; do
+if [ $(docker inspect --format '{{ .State.Running }}' $KAFKA) ] && \
+[ $(docker inspect --format '{{ .State.Running }}' $ZOOKEEPER) ] && \
+[ $(docker inspect --format '{{ .State.Running }}' $DMAAP) ]
+then
+   echo "DMaaP Service Running"
+   break
+else
+   echo sleep $i
+   sleep $i
+fi
+done
+
+# Get IP address of DMAAP, KAFKA, Zookeeper
+KAFKA_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $KAFKA)
+ZOOKEEPER_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $ZOOKEEPER)
+DMAAP_MR_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $DMAAP)
+
+sleep 2
+# Shutdown DMAAP Container
+docker kill $DMAAP
+
+# Initial docker-compose up and down is for populating kafka and zookeeper IPs in /var/tmp/MsgRtrApi.properites
+sed -i -e '/config.zk.servers=/ s/=.*/='$ZOOKEEPER_IP'/' /var/tmp/MsgRtrApi.properties
+sed -i -e '/kafka.metadata.broker.list=/ s/=.*/='$KAFKA_IP':9092/' /var/tmp/MsgRtrApi.properties
+
+# Start DMaaP MR containers with docker compose and configuration from docker-compose.yml
+docker login -u docker -p docker nexus3.onap.org:10001
+docker-compose up -d
+sleep 5
+
+# Clone DMaaP Data Router repo
+mkdir -p $WORKSPACE/archives/dmaapdr
+cd $WORKSPACE/archives/dmaapdr
+git clone --depth 1 https://gerrit.onap.org/r/dmaap/datarouter -b master
+cd $WORKSPACE/archives/dmaapdr/datarouter/datarouter-docker-compose/src/main/resources
+mkdir docker-compose
+cd $WORKSPACE/archives/dmaapdr/datarouter/datarouter-docker-compose/src/main/resources/docker-compose
+cp $WORKSPACE/plans/dcaegen2-pmmapper/pmmapper/composefile/docker-compose-e2e.yml $WORKSPACE/archives/dmaapdr/datarouter/datarouter-docker-compose/src/main/resources/docker-compose/docker-compose.yml
+
+docker login -u docker -p docker nexus3.onap.org:10001
+docker-compose up -d
+echo "Disregard the message ERROR: for datarouter-node  Container 1234456 is unhealthy, this is expected behaiour at this stage"
+docker kill datarouter-prov
+docker kill datarouter-node
+docker kill cbs
+CONSUL_IP=$(docker inspect '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' consul )
+sed -i -e '/CONSUL_HOST:/ s/:.*/: '$CONSUL_IP'/' docker-compose.yml
+MARIADB=$(docker inspect '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mariadb )
+sed -i 's/datarouter-mariadb/'$MARIADB'/g' $WORKSPACE/archives/dmaapdr/datarouter/datarouter-docker-compose/src/main/resources/prov_data/provserver.properties
+docker-compose up -d
+
+# Wait for initialization of Docker container for datarouter-node, datarouter-prov and mariadb
+for i in {1..10}; do
+    if [ $(docker inspect --format '{{ .State.Running }}' datarouter-node) ] && \
+        [ $(docker inspect --format '{{ .State.Running }}' datarouter-prov) ] && \
+        [ $(docker inspect --format '{{ .State.Running }}' mariadb) ]
+    then
+        echo "DR Service Running"
+        break
+    else
+        echo sleep $i
+        sleep $i
+    fi
+done
+
+sleep 5
+
+# Get IP address of datarrouger-prov, datarouter-node, fileconsumer-node.
+DR_PROV_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' datarouter-prov)
+DR_NODE_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' datarouter-node)
+DR_GATEWAY_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}' datarouter-prov)
+
+# Get IP address of DMAAP, KAFKA, Zookeeper, ConfigBindingService
+DMAAP_MR_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $DMAAP)
+KAFKA_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $KAFKA)
+ZOOKEEPER_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $ZOOKEEPER)
+CBS_IP=$(docker inspect '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cbs)
+
+# Data Router Configuration:
+# Create default feed on data router
+docker exec -i datarouter-prov sh -c "curl -k  -X PUT https://$DR_PROV_IP:8443/internal/api/NODES?val=dmaap-dr-node\|$DR_GATEWAY_IP"
+docker exec -i datarouter-prov sh -c "curl -k  -X PUT https://$DR_PROV_IP:8443/internal/api/PROV_AUTH_ADDRESSES?val=dmaap-dr-prov\|$DR_GATEWAY_IP"
+docker exec datarouter-prov /bin/sh -c "echo '${DR_NODE_IP}' dmaap-dr-node >> /etc/hosts"
+docker exec datarouter-node /bin/sh -c "echo '${DR_PROV_IP}' dmaap-dr-prov >> /etc/hosts"
+curl -v -X POST -H "Content-Type:application/vnd.att-dr.feed" -H "X-ATT-DR-ON-BEHALF-OF:dradmin" --data-ascii @$WORKSPACE/plans/dcaegen2-pmmapper/pmmapper/assets/createFeed.json --post301 --location-trusted -k https://${DR_PROV_IP}:8443
+sleep 5
+curl -k https://$DR_PROV_IP:8443/internal/prov
+
+# Consul Configuration for PM Mapper
+cp $WORKSPACE/plans/dcaegen2-pmmapper/pmmapper/assets/cbs.json /tmp/cbs.json
+sed -i 's/ipaddress/'${CBS_IP}'/g' /tmp/cbs.json
+curl --request PUT --data @/tmp/cbs.json http://$CONSUL_IP:8500/v1/agent/service/register
+curl 'http://'$CONSUL_IP':8500/v1/kv/pmmapper?dc=dc1' -X PUT -H 'Accept: application/^Con' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data @$WORKSPACE/plans/dcaegen2-pmmapper/pmmapper/assets/config.json
+
+#Pass any variables required by Robot test suites in ROBOT_VARIABLES
+ROBOT_VARIABLES="-v DR_PROV_IP:${DR_PROV_IP} -v DR_NODE_IP:${DR_NODE_IP} -v DMAAP_MR_IP:${DMAAP_MR_IP} -v CBS_IP:${CBS_IP} -v DR_SUBSCIBER_IP:${DR_SUBSCIBER_IP}"
diff --git a/plans/dcaegen2-pmmapper/pmmapper/teardown.sh b/plans/dcaegen2-pmmapper/pmmapper/teardown.sh
new file mode 100644
index 0000000..5b91012
--- /dev/null
+++ b/plans/dcaegen2-pmmapper/pmmapper/teardown.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+echo "Starting teardown script"
+kill-instance.sh $DMAAP
+kill-instance.sh $KAFKA
+kill-instance.sh $ZOOKEEPER
+kill-instance.sh datarouter-node
+kill-instance.sh datarouter-prov
+kill-instance.sh mariadb
+kill-instance.sh cbs
+kill-instance.sh consul
\ No newline at end of file
diff --git a/plans/dcaegen2-pmmapper/pmmapper/testplan.txt b/plans/dcaegen2-pmmapper/pmmapper/testplan.txt
new file mode 100644
index 0000000..f874b4d
--- /dev/null
+++ b/plans/dcaegen2-pmmapper/pmmapper/testplan.txt
@@ -0,0 +1,3 @@
+# Test suites are relative paths under [integration/csit.git]/tests/.
+# Place the suites in run order.
+dcaegen2-pmmapper/pmmapper