blob: 440eae9fc34165512a87afc46ca426f841ea3ef3 [file] [log] [blame]
waqas.ikramb01df8b2019-07-09 16:14:17 +00001#!/bin/bash
2#
3# ============LICENSE_START=======================================================
4# Copyright (C) 2019 Nordix Foundation.
5# ================================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# SPDX-License-Identifier: Apache-2.0
19# ============LICENSE_END=========================================================
20
21# @author Waqas Ikram (waqas.ikram@est.tech)
22
23MAVEN_VERSION_DIR="apache-maven-3.3.9"
24MAVEN_TAR_FILE="$MAVEN_VERSION_DIR-bin.tar.gz"
25MAVEN_TAR_LOCATION="http://apache.claz.org/maven/maven-3/3.3.9/binaries/$MAVEN_TAR_FILE"
26
27SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
28SCRIPT_NAME=$(basename $0)
waqas.ikram7d753292019-07-18 16:41:17 +000029CONFIG_DIR=$SCRIPT_HOME/config
30ENV_FILE=$CONFIG_DIR/env
waqas.ikramb01df8b2019-07-09 16:14:17 +000031TEMP_DIR_PATH=$SCRIPT_HOME/temp
waqas.ikram7d753292019-07-18 16:41:17 +000032TEST_LAB_DIR_PATH=$TEMP_DIR_PATH/test_lab
33DOCKER_COMPOSE_FILE_PATH=$SCRIPT_HOME/docker-compose.yml
waqas.ikram8c6cd4f2019-08-30 18:55:48 +000034TEAR_DOWN_SCRIPT=$SCRIPT_HOME/teardown.sh
waqas.ikramb01df8b2019-07-09 16:14:17 +000035
36MAVEN_DIR=$TEMP_DIR_PATH/maven
37INSTALLED_MAVEN_DIR=$MAVEN_DIR/$MAVEN_VERSION_DIR
38MVN=$INSTALLED_MAVEN_DIR/bin/mvn
39MVN_VERSION="$MVN -v"
40MVN_SETTINGS_XML="$SCRIPT_HOME/settings.xml"
41MVN_CLEAN_INSTALL="$MVN clean install"
42SIMULATOR_MAVEN_PROJECT_POM="$SCRIPT_HOME/so-simulators/pom.xml"
waqas.ikram5fee4482019-07-22 13:56:13 +000043WAIT_FOR_WORKAROUND_SCRIPT=$CONFIG_DIR/"wait-for-workaround-job.sh"
waqas.ikrama5aeeda2019-08-07 16:03:14 +000044WAIT_FOR_POPULATE_AAI_SCRIPT=$CONFIG_DIR/"wait-for-aai-config-job.sh"
eHanan75c11712019-08-13 15:44:16 +000045WAIT_FOR_CONTAINER_SCRIPT=$CONFIG_DIR/"wait-for-container.sh"
waqas.ikramb01df8b2019-07-09 16:14:17 +000046
47echo "Running $SCRIPT_HOME/$SCRIPT_NAME ..."
48
waqas.ikram7d753292019-07-18 16:41:17 +000049export $(egrep -v '^#' $ENV_FILE | xargs)
50
waqas.ikram50e7ec92019-08-14 14:27:41 +000051MANDATORY_VARIABLES_NAMES=( "NEXUS_DOCKER_REPO_MSO" "TAG" "TIME_OUT_DEFAULT_VALUE_SEC" "PROJECT_NAME" "DEFAULT_NETWORK_NAME")
52
53for var in "${MANDATORY_VARIABLES_NAMES[@]}"
54 do
55 if [ -z "${!var}" ]; then
56 echo "Missing mandatory attribute $var in $ENV_FILE"
57 exit 1
58 fi
59done
60
waqas.ikramb01df8b2019-07-09 16:14:17 +000061if [[ ! "$TEMP_DIR_PATH" || ! -d "$TEMP_DIR_PATH" ]]; then
62 echo "Creating temporary directory $TEMP_DIR_PATH"
63 mkdir $TEMP_DIR_PATH
64
65 if [ $? -ne 0 ]; then
66 echo "Could not create $TEMP_DIR_PATH"
67 exit 1
68 fi
69
70fi
71echo "Will use ${TEMP_DIR_PATH} directory"
72
73if [[ ! "$MAVEN_DIR" || ! -d "$MAVEN_DIR" ]]; then
74 echo "Creating temporary maven directory $MAVEN_DIR"
75 mkdir $MAVEN_DIR
76
77 if [ $? -ne 0 ]; then
78 echo "Could not create $MAVEN_DIR"
79 exit 1
80 fi
81fi
82echo "Will use ${MAVEN_DIR} directory for maven install"
83
84if [[ ! "$INSTALLED_MAVEN_DIR" || ! -d "$INSTALLED_MAVEN_DIR" ]]; then
85 echo "Installing maven ..."
86 cd $MAVEN_DIR
87
88 CURL=`which curl`
89 if [[ ! "$CURL" ]]; then
90 echo "curl command is not installed"
91 echo "Unable to execute test plan"
92 exit 1
93 fi
94 curl -O $MAVEN_TAR_LOCATION
95
96 TAR=`which tar`
97 if [[ ! "$TAR" ]]; then
98 echo "tar command is not installed"
99 echo "Unable to execute test plan"
100 exit 1
101 fi
102
103 tar -xzvf apache-maven-3.3.9-bin.tar.gz
104
105 echo "Finished installing maven ..."
106fi
107
108echo "Maven installed under directory $INSTALLED_MAVEN_DIR"
109
110$MVN_VERSION
111
112if [ $? -ne 0 ]; then
113 echo "Unable to run mvn -v command"
114 exit 1
115fi
116
117cd $SCRIPT_HOME
118
119echo "Will build simulator project using $MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML"
120$MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML
121
waqas.ikram7d753292019-07-18 16:41:17 +0000122if [ $? -ne 0 ]; then
123 echo "Maven build failed"
124 exit 1
125fi
waqas.ikramb01df8b2019-07-09 16:14:17 +0000126
waqas.ikram7d753292019-07-18 16:41:17 +0000127echo "Will clone docker-config project ... "
waqas.ikramb01df8b2019-07-09 16:14:17 +0000128
waqas.ikram7d753292019-07-18 16:41:17 +0000129
130if [[ -d "$TEST_LAB_DIR_PATH" ]]; then
131 echo "$TEST_LAB_DIR_PATH already exists"
132 echo "Removing $TEST_LAB_DIR_PATH directory ..."
133 rm -rf $TEST_LAB_DIR_PATH
134fi
135
136git clone http://gerrit.onap.org/r/so/docker-config.git $TEST_LAB_DIR_PATH
137
waqas.ikram7d753292019-07-18 16:41:17 +0000138export TEST_LAB_DIR=$TEST_LAB_DIR_PATH
139export CONFIG_DIR_PATH=$CONFIG_DIR
140
waqas.ikram4d813752019-08-13 11:24:45 +0000141docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME up -d
waqas.ikram7d753292019-07-18 16:41:17 +0000142
143echo "Sleeping for 3m"
144sleep 3m
waqas.ikramb01df8b2019-07-09 16:14:17 +0000145
waqas.ikram5fee4482019-07-22 13:56:13 +0000146echo "Will execute $WAIT_FOR_WORKAROUND_SCRIPT script"
147$WAIT_FOR_WORKAROUND_SCRIPT
148
149if [ $? -ne 0 ]; then
150 echo "ERROR: $WAIT_FOR_WORKAROUND_SCRIPT failed"
151 echo "Will stop running docker containers . . ."
waqas.ikram8c6cd4f2019-08-30 18:55:48 +0000152 $TEAR_DOWN_SCRIPT
waqas.ikram5fee4482019-07-22 13:56:13 +0000153 exit 1
154fi
155
waqas.ikrama5aeeda2019-08-07 16:03:14 +0000156echo "Will execute $WAIT_FOR_POPULATE_AAI_SCRIPT script"
157$WAIT_FOR_POPULATE_AAI_SCRIPT
158
159if [ $? -ne 0 ]; then
160 echo "ERROR: $WAIT_FOR_POPULATE_AAI_SCRIPT failed"
161 echo "Will stop running docker containers . . ."
waqas.ikram8c6cd4f2019-08-30 18:55:48 +0000162 $TEAR_DOWN_SCRIPT
eHanan75c11712019-08-13 15:44:16 +0000163 exit 1
164fi
165
166API_INFRA_CONTAINER_NAME="api-handler-infra"
167echo "Will execute $WAIT_FOR_CONTAINER_SCRIPT to wait for $API_INFRA_CONTAINER_NAME container to start up"
waqas.ikram50e7ec92019-08-14 14:27:41 +0000168$WAIT_FOR_CONTAINER_SCRIPT -c "$API_INFRA_CONTAINER_NAME" -t "300" -n "$DEFAULT_NETWORK_NAME"
eHanan75c11712019-08-13 15:44:16 +0000169
170if [ $? -ne 0 ]; then
171 echo "ERROR: $WAIT_FOR_CONTAINER_SCRIPT failed"
172 echo "Will stop running docker containers . . ."
waqas.ikram8c6cd4f2019-08-30 18:55:48 +0000173 $TEAR_DOWN_SCRIPT
waqas.ikrama5aeeda2019-08-07 16:03:14 +0000174 exit 1
175fi
waqas.ikram5fee4482019-07-22 13:56:13 +0000176
waqas.ikramb01df8b2019-07-09 16:14:17 +0000177REPO_IP='127.0.0.1'
178ROBOT_VARIABLES="-v REPO_IP:${REPO_IP}"
179
180echo "Finished executing $SCRIPT_HOME/$SCRIPT_NAME"