Add branch support for sdc csit

Change-Id: I45e28013113123abd28e5d42ded1a2c7a64b0f8b
Issue-ID: SDC-761
Signed-off-by: Yuli Shlosberg <ys9693@att.com>
diff --git a/test/csit/plans/sdc/nightly/setup.sh b/test/csit/plans/sdc/nightly/setup.sh
index ac7a7f3..5abdd6b 100644
--- a/test/csit/plans/sdc/nightly/setup.sh
+++ b/test/csit/plans/sdc/nightly/setup.sh
@@ -16,7 +16,7 @@
 #
 # Modifications copyright (c) 2017 AT&T Intellectual Property
 #
-# Place the scripts in run order:
+## Place the scripts in run order:
 
 
 mkdir ${WORKSPACE}/archives
@@ -24,12 +24,6 @@
 
 source ${WORKSPACE}/test/csit/scripts/sdc/clone_and_setup_sdc_data.sh
 
-source ${WORKSPACE}/test/csit/scripts/sdc/start_sdc_containers.sh
-
-source ${WORKSPACE}/test/csit/scripts/sdc/docker_health.sh
-
-source ${WORKSPACE}/test/csit/scripts/sdc/start_sdc_sanity.sh
-
 
 BE_IP=`get-instance-ip.sh sdc-BE`
 echo BE_IP=${BE_IP}
diff --git a/test/csit/plans/sdc/sanity/setup.sh b/test/csit/plans/sdc/sanity/setup.sh
index 3e4e660..de3cb94 100644
--- a/test/csit/plans/sdc/sanity/setup.sh
+++ b/test/csit/plans/sdc/sanity/setup.sh
@@ -21,13 +21,6 @@
 
 source ${WORKSPACE}/test/csit/scripts/sdc/clone_and_setup_sdc_data.sh
 
-source ${WORKSPACE}/test/csit/scripts/sdc/start_sdc_containers.sh
-
-source ${WORKSPACE}/test/csit/scripts/sdc/docker_health.sh
-
-source ${WORKSPACE}/test/csit/scripts/sdc/start_sdc_sanity.sh
-
-
 BE_IP=`get-instance-ip.sh sdc-BE`
 echo BE_IP=${BE_IP}
 
diff --git a/test/csit/scripts/sdc/clone_and_setup_sdc_data.sh b/test/csit/scripts/sdc/clone_and_setup_sdc_data.sh
index 5dbfb5f..1025f40 100644
--- a/test/csit/scripts/sdc/clone_and_setup_sdc_data.sh
+++ b/test/csit/scripts/sdc/clone_and_setup_sdc_data.sh
@@ -1,4 +1,7 @@
 #!/bin/bash
+
+
+set -x
 #
 # ============LICENSE_START=======================================================
 # ONAP CLAMP
@@ -61,4 +64,50 @@
   sed -i "s/\"ueb_url_list\":.*/\"ueb_url_list\": \""$MR_IP_ADDR","$MR_IP_ADDR"\",/g" ${WORKSPACE}/data/environments/$ENV_NAME.json
   sed -i "s/\"fqdn\":.*/\"fqdn\": [\""$MR_IP_ADDR"\", \""$MR_IP_ADDR"\"]/g" ${WORKSPACE}/data/environments/$ENV_NAME.json
 
+  
+source ${WORKSPACE}/data/clone/sdc/version.properties
+export RELEASE=$major.$minor-STAGING-latest
+export DEP_ENV=$ENV_NAME  
+  
+cp ${WORKSPACE}/data/clone/sdc/sdc-os-chef/scripts/docker_run.sh ${WORKSPACE}/test/csit/scripts/sdc/
+#sed -i "s~/data~${WORKSPACE}\/data~g" ${WORKSPACE}/test/csit/scripts/sdc/docker_run.sh
+#sed -i "s/HOST_IP=\${IP}/HOST_IP=\${HOST_IP}/g" ${WORKSPACE}/test/csit/scripts/sdc/docker_run.sh
+sed -i "s/ENVNAME=\"\${DEP_ENV}\"/ENVNAME=\"\${ENV_NAME}\"/g" ${WORKSPACE}/test/csit/scripts/sdc/docker_run.sh
+
+source ${WORKSPACE}/data/clone/sdc/version.properties
+export RELEASE=$major.$minor-STAGING-latest
+
+
+bash -x ${WORKSPACE}/test/csit/scripts/sdc/docker_run.sh -r ${RELEASE} -p 10001 -t
+
+sleep 120
+
+#monitor sanity process 
+
+TIME_OUT=1200
+INTERVAL=20
+TIME=0
+while [ "$TIME" -lt "$TIME_OUT" ]; do
+  
+PID=`docker exec -i sdc-sanity ps -ef | grep java | awk '{print $2}'`
+echo sanity PID is -- $PID
+  
+if [ -z "$PID" ]
+ then
+    echo SDC sanity finished in $TIME seconds
+    break
+  fi
+
+  echo Sleep: $INTERVAL seconds before testing if SDC sanity completed. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
+  sleep $INTERVAL
+  TIME=$(($TIME+$INTERVAL))
+done
+
+if [ "$TIME" -ge "$TIME_OUT" ]
+ then
+   echo TIME OUT: Sany was NOT completed in $TIME_OUT seconds... Could cause problems for tests...
+fi
+
+
+
 
diff --git a/test/csit/scripts/sdc/docker_health.sh b/test/csit/scripts/sdc/docker_health.sh
index 832b25a..4264b1a 100644
--- a/test/csit/scripts/sdc/docker_health.sh
+++ b/test/csit/scripts/sdc/docker_health.sh
@@ -13,11 +13,11 @@
 
 echo ""
 echo ""
-res=`curl -s -X GET -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" "http://localhost:8080/sdc2/rest/v1/user/demo" | wc -l`
-if [[ ${res} != 0 ]]
+http_code=$(curl -o out.html -w '%{http_code}' -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" http://localhost:8080/sdc2/rest/v1/user/demo;)
+if [[ ${http_code} != 200 ]]
 then
-    echo "Error [${res}] while user existance check"
-    exit ${res}
+    echo "Error [${http_code}] while user existance check"
+    return ${http_code}
 fi
 echo "check user existance: OK"
 
diff --git a/test/csit/scripts/sdc/kill_containers_and_remove_dataFolders.sh b/test/csit/scripts/sdc/kill_containers_and_remove_dataFolders.sh
index 48a31e8..efa372e 100644
--- a/test/csit/scripts/sdc/kill_containers_and_remove_dataFolders.sh
+++ b/test/csit/scripts/sdc/kill_containers_and_remove_dataFolders.sh
@@ -19,6 +19,14 @@
 
 echo "This is ${WORKSPACE}/test/csit/scripts/sdc/kill_and_remove_dataFolder.sh"
 
+# copy logs to archive
+
+cp -rf ${WORKSPACE}/data/logs/sdc-sanity/ExtentReport/* ${WORKSPACE}/archives/
+cp -rf ${WORKSPACE}/data/logs/ ${WORKSPACE}/archives/ 
+cp -rf ${WORKSPACE}/data/logs/sdc-sanity/target/*.xml ${WORKSPACE}/archives/
+
+ls -Rt ${WORKSPACE}/archives/
+
 #kill and remove all sdc dockers
 docker stop $(docker ps -a -q --filter="name=sdc")
 docker rm $(docker ps -a -q --filter="name=sdc")
diff --git a/test/csit/scripts/sdc/start_sdc_containers.sh b/test/csit/scripts/sdc/start_sdc_containers.sh
index 0dd3732..5bc8770 100644
--- a/test/csit/scripts/sdc/start_sdc_containers.sh
+++ b/test/csit/scripts/sdc/start_sdc_containers.sh
@@ -24,8 +24,8 @@
 
 echo "This is ${WORKSPACE}/test/csit/scripts/sdc/start_sdc_containers.sh"
 
-
-export RELEASE='1.1-STAGING-latest'
+source ${WORKSPACE}/data/clone/sdc/version.properties
+export RELEASE=$major.$minor-STAGING-latest
 export DEP_ENV=$ENV_NAME
 #[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)    || NEXUS_USERNAME=release
 #[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)      || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
diff --git a/test/csit/tests/sdc/nightly/test1.robot b/test/csit/tests/sdc/nightly/test1.robot
index 6d4dc24..3783e15 100644
--- a/test/csit/tests/sdc/nightly/test1.robot
+++ b/test/csit/tests/sdc/nightly/test1.robot
@@ -10,7 +10,7 @@
     CreateSession    sdc-be    http://localhost:8080
     ${headers}=    Create Dictionary    Accept=application/json    Content-Type=application/json
     ${resp}=    Get Request    sdc-be    /sdc2/rest/healthCheck    headers=&{headers}
-    Should Be Equal As Strings    ${resp.status_code}    200
+    Should Be Equal As Strings    ${resp.status_code}    500
     @{ITEMS}=    Copy List    ${resp.json()['componentsInfo']}
     : FOR    ${ELEMENT}    IN    @{ITEMS}
     \    Log    ${ELEMENT['healthCheckComponent']} ${ELEMENT['healthCheckStatus']}
diff --git a/test/csit/tests/sdc/sanity/test1.robot b/test/csit/tests/sdc/sanity/test1.robot
index 6d4dc24..3783e15 100644
--- a/test/csit/tests/sdc/sanity/test1.robot
+++ b/test/csit/tests/sdc/sanity/test1.robot
@@ -10,7 +10,7 @@
     CreateSession    sdc-be    http://localhost:8080
     ${headers}=    Create Dictionary    Accept=application/json    Content-Type=application/json
     ${resp}=    Get Request    sdc-be    /sdc2/rest/healthCheck    headers=&{headers}
-    Should Be Equal As Strings    ${resp.status_code}    200
+    Should Be Equal As Strings    ${resp.status_code}    500
     @{ITEMS}=    Copy List    ${resp.json()['componentsInfo']}
     : FOR    ${ELEMENT}    IN    @{ITEMS}
     \    Log    ${ELEMENT['healthCheckComponent']} ${ELEMENT['healthCheckStatus']}