From b86853bc0d1e9a8621e0647a0cb7f0ab904eeb1b Mon Sep 17 00:00:00 2001
From: =?utf8?q?Petr=20Ospal=C3=BD?= 
Date: Mon, 23 Sep 2019 17:01:09 +0200
Subject: [PATCH] Add support for https tests for SDC-DCAE-D
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit
This commit introduces a new set of variables for sdc-dcae-d test in the
same style as was for sdc tests. Some refactor had to be done to make it
work and make it less copy-pasted.
Issue-ID: SDC-2564
Change-Id: Ic0725dbc4643d0563594f28d2a772968e291f788
Signed-off-by: Petr Ospalý 
---
 plans/sdc-dcae-d/dcaed/setup.sh                  | 25 +++++++++++++
 scripts/sdc-dcae-d/setup_sdc_dcaed.sh            | 40 ++++++++------------
 scripts/sdc/setup_sdc_for_sanity.sh              | 47 ++++++++++++++++++------
 tests/sdc-dcae-d/dcaed/sdc_dcaed_interface.robot |  2 +-
 tests/sdc-dcae-d/dcaed/sdc_interface.robot       |  2 +-
 5 files changed, 77 insertions(+), 39 deletions(-)
diff --git a/plans/sdc-dcae-d/dcaed/setup.sh b/plans/sdc-dcae-d/dcaed/setup.sh
index 5a94a939..6672a201 100644
--- a/plans/sdc-dcae-d/dcaed/setup.sh
+++ b/plans/sdc-dcae-d/dcaed/setup.sh
@@ -15,4 +15,29 @@
 # limitations under the License.
 #
 
+# It can enable HTTPS for SDC component
+export SDC_TEST_HTTPS="${SDC_TEST_HTTPS:-false}"
+
+# By default all images are from remote upstream registry, this option
+# provides the chance to test locally built images
+export SDC_LOCAL_IMAGES="${SDC_LOCAL_IMAGES:-false}"
+
+# For this to take effect SDC_LOCAL_IMAGES must be enabled...
+#
+# The path to the local sdc git repo from which the local images have
+# been built - it also affects the tag used - if left empty *AND*
+# local images are used *AND* SDC_LOCAL_TAG is unset then the tag
+# will be set to: 'latest'
+#
+# BEWARE: Using local images with an incorrect git repo could lead to
+# problems...set SDC_LOCAL_GITREPO or GERRIT_BRANCH properly...
+export SDC_LOCAL_GITREPO="${SDC_LOCAL_GITREPO}"
+
+# For this to take effect SDC_LOCAL_IMAGES must be enabled...
+#
+# This will set the tag for local images - leaving this empty *AND*
+# with unset SDC_LOCAL_GITREPO the local images will fallback to the
+# tag: 'latest'
+export SDC_LOCAL_TAG="${SDC_LOCAL_TAG}"
+
 source ${WORKSPACE}/scripts/sdc-dcae-d/setup_sdc_dcaed.sh
diff --git a/scripts/sdc-dcae-d/setup_sdc_dcaed.sh b/scripts/sdc-dcae-d/setup_sdc_dcaed.sh
index 0bfc7e01..9abc0818 100644
--- a/scripts/sdc-dcae-d/setup_sdc_dcaed.sh
+++ b/scripts/sdc-dcae-d/setup_sdc_dcaed.sh
@@ -15,43 +15,33 @@
 # limitations under the License.
 #
 
-set -x
-
 echo "This is ${WORKSPACE}/scripts/sdc-dcae-d/setup_sdc_dcaed.sh"
 
-# Clone sdc enviroment template
-mkdir -p ${WORKSPACE}/data/environments/
-mkdir -p ${WORKSPACE}/data/clone/
-cd ${WORKSPACE}/data/clone
-git clone --depth 1 http://gerrit.onap.org/r/sdc/dcae-d/dt-be-main
-git clone --depth 1 http://gerrit.onap.org/r/sdc
-
-chmod -R 777 ${WORKSPACE}/data/clone
-
-# set enviroment variables
-
+# I am leaving this here for explicity - but the same is already set inside setup sdc...
 export ENV_NAME='CSIT'
-export MR_IP_ADDR='10.0.0.1'
-export TEST_SUITE=$1
 
-ifconfig
-IP_ADDRESS=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
-export HOST_IP=$IP_ADDRESS
+# run sdc deployment
+set -- # to wipe out arguments...
+source ${WORKSPACE}/scripts/sdc/setup_sdc_for_sanity.sh
+export ROBOT_VARIABLES
 
-# setup enviroment json
+# fail quick if error
+set -exo pipefail
 
-cat ${WORKSPACE}/data/clone/sdc/sdc-os-chef/environments/Template.json | sed "s/yyy/"$IP_ADDRESS"/g" > ${WORKSPACE}/data/environments/$ENV_NAME.json
+# prepare dcae-d
+mkdir -p "${WORKSPACE}/data/clone/"
+cd "${WORKSPACE}/data/clone"
+git clone --depth 1 "https://gerrit.onap.org/r/sdc/dcae-d/dt-be-main"
 
-source ${WORKSPACE}/data/clone/sdc/version.properties
-export RELEASE=$major.$minor-STAGING-latest
+# set enviroment variables
 source ${WORKSPACE}/data/clone/dt-be-main/version.properties
 export DCAE_RELEASE=$major.$minor-STAGING-latest
-export DEP_ENV=$ENV_NAME
 
-cp ${WORKSPACE}/data/clone/sdc/sdc-os-chef/scripts/docker_run.sh ${WORKSPACE}/scripts/sdc-dcae-d/
 cp ${WORKSPACE}/data/clone/dt-be-main/docker/scripts/docker_run.sh ${WORKSPACE}/scripts/sdc-dcae-d/dcaed_docker_run.sh
 
-${WORKSPACE}/scripts/sdc-dcae-d/docker_run.sh -r ${RELEASE} -e ${ENV_NAME} -p 10001
 ${WORKSPACE}/scripts/sdc-dcae-d/dcaed_docker_run.sh -r ${DCAE_RELEASE} -e ${ENV_NAME} -p 10001
 
+# This file is sourced in another script which is out of our control...
+set +e
+set +o pipefail
 
diff --git a/scripts/sdc/setup_sdc_for_sanity.sh b/scripts/sdc/setup_sdc_for_sanity.sh
index dba6eb50..c5a923d8 100644
--- a/scripts/sdc/setup_sdc_for_sanity.sh
+++ b/scripts/sdc/setup_sdc_for_sanity.sh
@@ -1,9 +1,20 @@
 #!/bin/bash
 
 function usage {
-    echo "usage: setup_sdc_for_sanity.sh {tad|tud}"
-    echo "setup sdc and run api test suite: setup_sdc_for_sanity.sh tad"
-    echo "setup sdc and run ui test suite: setup_sdc_for_sanity.sh tud"
+cat <
@@ -38,11 +49,24 @@ set -exo pipefail
 
 echo "This is ${WORKSPACE}/scripts/sdc/setup_sdc_for_sanity.sh"
 
-
-if [ "$1" != "tad" ] && [ "$1" != "tud" ]; then
-    usage
-    exit 1
-fi
+ENABLE_SIMULATOR=
+case "$1" in
+    tad|tud)
+        # enable test
+        export TEST_SUITE="-${1}"
+        ;;
+    '')
+        # we will just setup sdc - no tests
+        export TEST_SUITE=""
+
+        # this is mandatory
+        ENABLE_SIMULATOR="--simulator"
+        ;;
+    *)
+        usage
+        exit 1
+        ;;
+esac
 
 # Clone sdc enviroment template
 mkdir -p "${WORKSPACE}/data/environments/"
@@ -59,7 +83,7 @@ if using_local_images && [ -n "$SDC_LOCAL_GITREPO" ] ; then
         exit 1
     fi
 else
-    git clone --depth 1 http://gerrit.onap.org/r/sdc -b ${GERRIT_BRANCH}
+    git clone --depth 1 "https://gerrit.onap.org/r/sdc" -b ${GERRIT_BRANCH}
 fi
 
 # TODO: why?
@@ -69,7 +93,6 @@ chmod -R 777 "${WORKSPACE}/data/clone"
 
 export ENV_NAME='CSIT'
 export MR_IP_ADDR='10.0.0.1'
-export TEST_SUITE="$1"
 
 ifconfig
 IP_ADDRESS=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
@@ -111,13 +134,13 @@ if using_local_images ; then
         --local \
         -r "${RELEASE}" \
         -e "${ENV_NAME}" \
-        -p 10001 "-${TEST_SUITE}"
+        -p 10001 ${TEST_SUITE} ${ENABLE_SIMULATOR}
 else
     echo "[INFO]: We will download images from the default registry (tag: ${RELEASE})"
     ${WORKSPACE}/scripts/sdc/docker_run.sh \
         -r "${RELEASE}" \
         -e "${ENV_NAME}" \
-        -p 10001 "-${TEST_SUITE}"
+        -p 10001 ${TEST_SUITE} ${ENABLE_SIMULATOR}
 fi
 
 # final step if the robot test needs to be adjusted
diff --git a/tests/sdc-dcae-d/dcaed/sdc_dcaed_interface.robot b/tests/sdc-dcae-d/dcaed/sdc_dcaed_interface.robot
index 6f95ebc5..98e02519 100644
--- a/tests/sdc-dcae-d/dcaed/sdc_dcaed_interface.robot
+++ b/tests/sdc-dcae-d/dcaed/sdc_dcaed_interface.robot
@@ -11,7 +11,7 @@ ${DCAE_CREATE_BLUEPRINT_PATH}   /SERVICE/createBluePrint
 ${DCAE_VFCMT_TEMPLATE}   create_vfcmt.jinja
 ${DCAE_COMPOSITION_TEMPLATE}   dcae_composition.jinja
 ${DCAE_MONITORING_CONFIGURATION_TEMPLATE}   dcae_monitoring_configuration.jinja
-${DCAE_BE_ENDPOINT}   http://localhost:8082
+${DCAE_BE_ENDPOINT}   https://localhost:8444
 
 *** Keywords ***
 Create Monitoring Template
diff --git a/tests/sdc-dcae-d/dcaed/sdc_interface.robot b/tests/sdc-dcae-d/dcaed/sdc_interface.robot
index c1ceca44..6853fcca 100755
--- a/tests/sdc-dcae-d/dcaed/sdc_interface.robot
+++ b/tests/sdc-dcae-d/dcaed/sdc_interface.robot
@@ -22,7 +22,7 @@ ${SDC_ARTIFACT_UPLOAD_TEMPLATE}    artifact_upload.jinja
 ${SDC_USER_REMARKS_TEMPLATE}    user_remarks.jinja
 ${SDC_RESOURCE_INSTANCE_TEMPLATE}    resource_instance.jinja
 
-${SDC_BE_ENDPOINT}  http://localhost:8080
+${SDC_BE_ENDPOINT}  ${SDC_BE_PROTOCOL}://localhost:${SDC_BE_PORT}
 
 *** Keywords ***
 Onboard DCAE Microservice
-- 
2.16.6