blob: 52ef26d2832a3d71ed6e0e758e4341e99a6f003c [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.ikramb01df8b2019-07-09 16:14:17 +000034
35MAVEN_DIR=$TEMP_DIR_PATH/maven
36INSTALLED_MAVEN_DIR=$MAVEN_DIR/$MAVEN_VERSION_DIR
37MVN=$INSTALLED_MAVEN_DIR/bin/mvn
38MVN_VERSION="$MVN -v"
39MVN_SETTINGS_XML="$SCRIPT_HOME/settings.xml"
40MVN_CLEAN_INSTALL="$MVN clean install"
41SIMULATOR_MAVEN_PROJECT_POM="$SCRIPT_HOME/so-simulators/pom.xml"
waqas.ikram5fee4482019-07-22 13:56:13 +000042WAIT_FOR_WORKAROUND_SCRIPT=$CONFIG_DIR/"wait-for-workaround-job.sh"
waqas.ikrama5aeeda2019-08-07 16:03:14 +000043WAIT_FOR_POPULATE_AAI_SCRIPT=$CONFIG_DIR/"wait-for-aai-config-job.sh"
waqas.ikramb01df8b2019-07-09 16:14:17 +000044
45echo "Running $SCRIPT_HOME/$SCRIPT_NAME ..."
46
waqas.ikram7d753292019-07-18 16:41:17 +000047export $(egrep -v '^#' $ENV_FILE | xargs)
48
waqas.ikramb01df8b2019-07-09 16:14:17 +000049if [[ ! "$TEMP_DIR_PATH" || ! -d "$TEMP_DIR_PATH" ]]; then
50 echo "Creating temporary directory $TEMP_DIR_PATH"
51 mkdir $TEMP_DIR_PATH
52
53 if [ $? -ne 0 ]; then
54 echo "Could not create $TEMP_DIR_PATH"
55 exit 1
56 fi
57
58fi
59echo "Will use ${TEMP_DIR_PATH} directory"
60
61if [[ ! "$MAVEN_DIR" || ! -d "$MAVEN_DIR" ]]; then
62 echo "Creating temporary maven directory $MAVEN_DIR"
63 mkdir $MAVEN_DIR
64
65 if [ $? -ne 0 ]; then
66 echo "Could not create $MAVEN_DIR"
67 exit 1
68 fi
69fi
70echo "Will use ${MAVEN_DIR} directory for maven install"
71
72if [[ ! "$INSTALLED_MAVEN_DIR" || ! -d "$INSTALLED_MAVEN_DIR" ]]; then
73 echo "Installing maven ..."
74 cd $MAVEN_DIR
75
76 CURL=`which curl`
77 if [[ ! "$CURL" ]]; then
78 echo "curl command is not installed"
79 echo "Unable to execute test plan"
80 exit 1
81 fi
82 curl -O $MAVEN_TAR_LOCATION
83
84 TAR=`which tar`
85 if [[ ! "$TAR" ]]; then
86 echo "tar command is not installed"
87 echo "Unable to execute test plan"
88 exit 1
89 fi
90
91 tar -xzvf apache-maven-3.3.9-bin.tar.gz
92
93 echo "Finished installing maven ..."
94fi
95
96echo "Maven installed under directory $INSTALLED_MAVEN_DIR"
97
98$MVN_VERSION
99
100if [ $? -ne 0 ]; then
101 echo "Unable to run mvn -v command"
102 exit 1
103fi
104
105cd $SCRIPT_HOME
106
107echo "Will build simulator project using $MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML"
108$MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML
109
waqas.ikram7d753292019-07-18 16:41:17 +0000110if [ $? -ne 0 ]; then
111 echo "Maven build failed"
112 exit 1
113fi
waqas.ikramb01df8b2019-07-09 16:14:17 +0000114
waqas.ikram7d753292019-07-18 16:41:17 +0000115echo "Will clone docker-config project ... "
waqas.ikramb01df8b2019-07-09 16:14:17 +0000116
waqas.ikram7d753292019-07-18 16:41:17 +0000117
118if [[ -d "$TEST_LAB_DIR_PATH" ]]; then
119 echo "$TEST_LAB_DIR_PATH already exists"
120 echo "Removing $TEST_LAB_DIR_PATH directory ..."
121 rm -rf $TEST_LAB_DIR_PATH
122fi
123
124git clone http://gerrit.onap.org/r/so/docker-config.git $TEST_LAB_DIR_PATH
125
waqas.ikram7d753292019-07-18 16:41:17 +0000126export TEST_LAB_DIR=$TEST_LAB_DIR_PATH
127export CONFIG_DIR_PATH=$CONFIG_DIR
128
129docker-compose -f $DOCKER_COMPOSE_FILE_PATH up -d
130
131echo "Sleeping for 3m"
132sleep 3m
waqas.ikramb01df8b2019-07-09 16:14:17 +0000133
waqas.ikram5fee4482019-07-22 13:56:13 +0000134echo "Will execute $WAIT_FOR_WORKAROUND_SCRIPT script"
135$WAIT_FOR_WORKAROUND_SCRIPT
136
137if [ $? -ne 0 ]; then
138 echo "ERROR: $WAIT_FOR_WORKAROUND_SCRIPT failed"
139 echo "Will stop running docker containers . . ."
140 docker-compose -f $DOCKER_COMPOSE_FILE_PATH down
141 exit 1
142fi
143
waqas.ikrama5aeeda2019-08-07 16:03:14 +0000144echo "Will execute $WAIT_FOR_POPULATE_AAI_SCRIPT script"
145$WAIT_FOR_POPULATE_AAI_SCRIPT
146
147if [ $? -ne 0 ]; then
148 echo "ERROR: $WAIT_FOR_POPULATE_AAI_SCRIPT failed"
149 echo "Will stop running docker containers . . ."
150 docker-compose -f $DOCKER_COMPOSE_FILE_PATH down
151 exit 1
152fi
waqas.ikram5fee4482019-07-22 13:56:13 +0000153
waqas.ikramb01df8b2019-07-09 16:14:17 +0000154REPO_IP='127.0.0.1'
155ROBOT_VARIABLES="-v REPO_IP:${REPO_IP}"
156
157echo "Finished executing $SCRIPT_HOME/$SCRIPT_NAME"