blob: 8c94452f448ecbeff0ae1fa5fe715e7edefbdf31 [file] [log] [blame]
tragait9bbcb1b2020-02-24 16:33:50 +00001#!/bin/bash
2#
3# ============LICENSE_START=======================================================
4# Copyright (C) 2020 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="https://archive.apache.org/dist/maven/maven-3/3.3.9/binaries/$MAVEN_TAR_FILE"
26
27SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
28SCRIPT_NAME=$(basename $0)
29CONFIG_DIR=$SCRIPT_HOME/config
30ENV_FILE=$CONFIG_DIR/env
31TEMP_DIR_PATH=$SCRIPT_HOME/temp
32TEST_LAB_DIR_PATH=$TEMP_DIR_PATH/test_lab
33DOCKER_COMPOSE_FILE_PATH=$SCRIPT_HOME/docker-compose.yml
34DOCKER_COMPOSE_LOCAL_OVERRIDE_FILE=$SCRIPT_HOME/docker-compose.local.yml
35TEAR_DOWN_SCRIPT=$SCRIPT_HOME/teardown.sh
36
37MAVEN_DIR=$TEMP_DIR_PATH/maven
38INSTALLED_MAVEN_DIR=$MAVEN_DIR/$MAVEN_VERSION_DIR
39MVN=$INSTALLED_MAVEN_DIR/bin/mvn
40MVN_VERSION="$MVN -v"
41MVN_SETTINGS_XML="$SCRIPT_HOME/settings.xml"
42MVN_CLEAN_INSTALL="$MVN clean install"
43SIMULATOR_MAVEN_PROJECT_POM="$SCRIPT_HOME/simulator/pom.xml"
44WAIT_FOR_WORKAROUND_SCRIPT=$CONFIG_DIR/"wait-for-workaround-job.sh"
45WAIT_FOR_POPULATE_AAI_SCRIPT=$CONFIG_DIR/"wait-for-aai-config-job.sh"
46WAIT_FOR_CONTAINER_SCRIPT=$CONFIG_DIR/"wait-for-container.sh"
47PNF_PAYLOAD_PATH=$CONFIG_DIR/aai-simulator-populate-data/pnf.json
48
49echo "Running $SCRIPT_HOME/$SCRIPT_NAME ..."
50
51export $(egrep -v '^#' $ENV_FILE | xargs)
52
53MANDATORY_VARIABLES_NAMES=( "NEXUS_DOCKER_REPO_MSO" "DOCKER_ENVIRONMENT" "TAG" "TIME_OUT_DEFAULT_VALUE_SEC" "PROJECT_NAME" "DEFAULT_NETWORK_NAME")
54
55for var in "${MANDATORY_VARIABLES_NAMES[@]}"
56 do
57 if [ -z "${!var}" ]; then
58 echo "Missing mandatory attribute $var in $ENV_FILE"
59 exit 1
60 fi
61done
62
63if [[ ! "$TEMP_DIR_PATH" || ! -d "$TEMP_DIR_PATH" ]]; then
64 echo "Creating temporary directory $TEMP_DIR_PATH"
65 mkdir $TEMP_DIR_PATH
66
67 if [ $? -ne 0 ]; then
68 echo "Could not create $TEMP_DIR_PATH"
69 exit 1
70 fi
71
72fi
73echo "Will use ${TEMP_DIR_PATH} directory"
74
75if [[ ! "$MAVEN_DIR" || ! -d "$MAVEN_DIR" ]]; then
76 echo "Creating temporary maven directory $MAVEN_DIR"
77 mkdir $MAVEN_DIR
78
79 if [ $? -ne 0 ]; then
80 echo "Could not create $MAVEN_DIR"
81 exit 1
82 fi
83fi
84echo "Will use ${MAVEN_DIR} directory for maven install"
85
86if [[ ! "$INSTALLED_MAVEN_DIR" || ! -d "$INSTALLED_MAVEN_DIR" ]]; then
87 echo "Installing maven ..."
88 cd $MAVEN_DIR
89
90 CURL=`which curl`
91 if [[ ! "$CURL" ]]; then
92 echo "curl command is not installed"
93 echo "Unable to execute test plan"
94 exit 1
95 fi
96 curl -O $MAVEN_TAR_LOCATION
97
98 TAR=`which tar`
99 if [[ ! "$TAR" ]]; then
100 echo "tar command is not installed"
101 echo "Unable to execute test plan"
102 exit 1
103 fi
104
105 tar -xzvf $MAVEN_TAR_FILE
106
107 echo "Finished installing maven ..."
108fi
109
110echo "Maven installed under directory $INSTALLED_MAVEN_DIR"
111
112$MVN_VERSION
113
114if [ $? -ne 0 ]; then
115 echo "Unable to run mvn -v command"
116 exit 1
117fi
118
119cd $SCRIPT_HOME
120
121echo "Will build simulator project using $MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML"
122$MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML
123
124if [ $? -ne 0 ]; then
125 echo "Maven build failed"
126 exit 1
127fi
128
129echo "Will clone docker-config project ... "
130
131
132if [[ -d "$TEST_LAB_DIR_PATH" ]]; then
133 echo "$TEST_LAB_DIR_PATH already exists"
134 echo "Removing $TEST_LAB_DIR_PATH directory ..."
135 rm -rf $TEST_LAB_DIR_PATH
136fi
137
138git clone http://gerrit.onap.org/r/so/docker-config.git $TEST_LAB_DIR_PATH
139
140export TEST_LAB_DIR=$TEST_LAB_DIR_PATH
141export CONFIG_DIR_PATH=$CONFIG_DIR
142
143if [ "$DOCKER_ENVIRONMENT" == "remote" ]; then
144 echo "Starting docker containers with remote images ..."
145 docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME up -d mariadb
146 sleep 1m
147 docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME up -d
148elif [ "$DOCKER_ENVIRONMENT" == "local" ]; then
149 echo "Starting docker containers with local images ..."
150 docker-compose -f $DOCKER_COMPOSE_FILE_PATH -f $DOCKER_COMPOSE_LOCAL_OVERRIDE_FILE -p $PROJECT_NAME up -d mariadb
151 sleep 1m
152 docker-compose -f $DOCKER_COMPOSE_FILE_PATH -f $DOCKER_COMPOSE_LOCAL_OVERRIDE_FILE -p $PROJECT_NAME up -d
153else
154 echo "DOCKER_ENVIRONMENT not set correctly in $ENV_FILE. Allowed values: local | remote"
155 exit 1
156fi
157
158echo "Sleeping for 2m"
159sleep 2m
160
161echo "updating PNF ip-address in pnf.json"
162sed -i "s/pnfaddr/$LOCAL_IP/g" $PNF_PAYLOAD_PATH
163
164echo "Will execute $WAIT_FOR_WORKAROUND_SCRIPT script"
165$WAIT_FOR_WORKAROUND_SCRIPT
166
167if [ $? -ne 0 ]; then
168 echo "ERROR: $WAIT_FOR_WORKAROUND_SCRIPT failed"
169 echo "Will stop running docker containers . . ."
170 $TEAR_DOWN_SCRIPT
171 exit 1
172fi
173
174
175echo "Will execute $WAIT_FOR_POPULATE_AAI_SCRIPT script"
176$WAIT_FOR_POPULATE_AAI_SCRIPT
177
178if [ $? -ne 0 ]; then
179 echo "ERROR: $WAIT_FOR_POPULATE_AAI_SCRIPT failed"
180 echo "Will stop running docker containers . . ."
181 $TEAR_DOWN_SCRIPT
182 exit 1
183fi
184
185API_INFRA_CONTAINER_NAME="api-handler-infra"
186echo "Will execute $WAIT_FOR_CONTAINER_SCRIPT to wait for $API_INFRA_CONTAINER_NAME container to start up"
187$WAIT_FOR_CONTAINER_SCRIPT -c "$API_INFRA_CONTAINER_NAME" -t "300" -n "$DEFAULT_NETWORK_NAME"
188
189if [ $? -ne 0 ]; then
190 echo "ERROR: $WAIT_FOR_CONTAINER_SCRIPT failed"
191 echo "Will stop running docker containers . . ."
192 $TEAR_DOWN_SCRIPT
193 exit 1
194fi
195
196echo "Finished executing $SCRIPT_HOME/$SCRIPT_NAME"