waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 1 | #!/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 | |
| 23 | MAVEN_VERSION_DIR="apache-maven-3.3.9" |
| 24 | MAVEN_TAR_FILE="$MAVEN_VERSION_DIR-bin.tar.gz" |
| 25 | MAVEN_TAR_LOCATION="http://apache.claz.org/maven/maven-3/3.3.9/binaries/$MAVEN_TAR_FILE" |
| 26 | |
| 27 | SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 28 | SCRIPT_NAME=$(basename $0) |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 29 | CONFIG_DIR=$SCRIPT_HOME/config |
| 30 | ENV_FILE=$CONFIG_DIR/env |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 31 | TEMP_DIR_PATH=$SCRIPT_HOME/temp |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 32 | TEST_LAB_DIR_PATH=$TEMP_DIR_PATH/test_lab |
| 33 | DOCKER_COMPOSE_FILE_PATH=$SCRIPT_HOME/docker-compose.yml |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 34 | |
| 35 | MAVEN_DIR=$TEMP_DIR_PATH/maven |
| 36 | INSTALLED_MAVEN_DIR=$MAVEN_DIR/$MAVEN_VERSION_DIR |
| 37 | MVN=$INSTALLED_MAVEN_DIR/bin/mvn |
| 38 | MVN_VERSION="$MVN -v" |
| 39 | MVN_SETTINGS_XML="$SCRIPT_HOME/settings.xml" |
| 40 | MVN_CLEAN_INSTALL="$MVN clean install" |
| 41 | SIMULATOR_MAVEN_PROJECT_POM="$SCRIPT_HOME/so-simulators/pom.xml" |
waqas.ikram | 5fee448 | 2019-07-22 13:56:13 +0000 | [diff] [blame] | 42 | WAIT_FOR_WORKAROUND_SCRIPT=$CONFIG_DIR/"wait-for-workaround-job.sh" |
waqas.ikram | a5aeeda | 2019-08-07 16:03:14 +0000 | [diff] [blame] | 43 | WAIT_FOR_POPULATE_AAI_SCRIPT=$CONFIG_DIR/"wait-for-aai-config-job.sh" |
eHanan | 75c1171 | 2019-08-13 15:44:16 +0000 | [diff] [blame] | 44 | WAIT_FOR_CONTAINER_SCRIPT=$CONFIG_DIR/"wait-for-container.sh" |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 45 | |
| 46 | echo "Running $SCRIPT_HOME/$SCRIPT_NAME ..." |
| 47 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 48 | export $(egrep -v '^#' $ENV_FILE | xargs) |
| 49 | |
waqas.ikram | 50e7ec9 | 2019-08-14 14:27:41 +0000 | [diff] [blame^] | 50 | MANDATORY_VARIABLES_NAMES=( "NEXUS_DOCKER_REPO_MSO" "TAG" "TIME_OUT_DEFAULT_VALUE_SEC" "PROJECT_NAME" "DEFAULT_NETWORK_NAME") |
| 51 | |
| 52 | for var in "${MANDATORY_VARIABLES_NAMES[@]}" |
| 53 | do |
| 54 | if [ -z "${!var}" ]; then |
| 55 | echo "Missing mandatory attribute $var in $ENV_FILE" |
| 56 | exit 1 |
| 57 | fi |
| 58 | done |
| 59 | |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 60 | if [[ ! "$TEMP_DIR_PATH" || ! -d "$TEMP_DIR_PATH" ]]; then |
| 61 | echo "Creating temporary directory $TEMP_DIR_PATH" |
| 62 | mkdir $TEMP_DIR_PATH |
| 63 | |
| 64 | if [ $? -ne 0 ]; then |
| 65 | echo "Could not create $TEMP_DIR_PATH" |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | fi |
| 70 | echo "Will use ${TEMP_DIR_PATH} directory" |
| 71 | |
| 72 | if [[ ! "$MAVEN_DIR" || ! -d "$MAVEN_DIR" ]]; then |
| 73 | echo "Creating temporary maven directory $MAVEN_DIR" |
| 74 | mkdir $MAVEN_DIR |
| 75 | |
| 76 | if [ $? -ne 0 ]; then |
| 77 | echo "Could not create $MAVEN_DIR" |
| 78 | exit 1 |
| 79 | fi |
| 80 | fi |
| 81 | echo "Will use ${MAVEN_DIR} directory for maven install" |
| 82 | |
| 83 | if [[ ! "$INSTALLED_MAVEN_DIR" || ! -d "$INSTALLED_MAVEN_DIR" ]]; then |
| 84 | echo "Installing maven ..." |
| 85 | cd $MAVEN_DIR |
| 86 | |
| 87 | CURL=`which curl` |
| 88 | if [[ ! "$CURL" ]]; then |
| 89 | echo "curl command is not installed" |
| 90 | echo "Unable to execute test plan" |
| 91 | exit 1 |
| 92 | fi |
| 93 | curl -O $MAVEN_TAR_LOCATION |
| 94 | |
| 95 | TAR=`which tar` |
| 96 | if [[ ! "$TAR" ]]; then |
| 97 | echo "tar command is not installed" |
| 98 | echo "Unable to execute test plan" |
| 99 | exit 1 |
| 100 | fi |
| 101 | |
| 102 | tar -xzvf apache-maven-3.3.9-bin.tar.gz |
| 103 | |
| 104 | echo "Finished installing maven ..." |
| 105 | fi |
| 106 | |
| 107 | echo "Maven installed under directory $INSTALLED_MAVEN_DIR" |
| 108 | |
| 109 | $MVN_VERSION |
| 110 | |
| 111 | if [ $? -ne 0 ]; then |
| 112 | echo "Unable to run mvn -v command" |
| 113 | exit 1 |
| 114 | fi |
| 115 | |
| 116 | cd $SCRIPT_HOME |
| 117 | |
| 118 | echo "Will build simulator project using $MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML" |
| 119 | $MVN_CLEAN_INSTALL -f $SIMULATOR_MAVEN_PROJECT_POM --settings $MVN_SETTINGS_XML |
| 120 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 121 | if [ $? -ne 0 ]; then |
| 122 | echo "Maven build failed" |
| 123 | exit 1 |
| 124 | fi |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 125 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 126 | echo "Will clone docker-config project ... " |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 127 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 128 | |
| 129 | if [[ -d "$TEST_LAB_DIR_PATH" ]]; then |
| 130 | echo "$TEST_LAB_DIR_PATH already exists" |
| 131 | echo "Removing $TEST_LAB_DIR_PATH directory ..." |
| 132 | rm -rf $TEST_LAB_DIR_PATH |
| 133 | fi |
| 134 | |
| 135 | git clone http://gerrit.onap.org/r/so/docker-config.git $TEST_LAB_DIR_PATH |
| 136 | |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 137 | export TEST_LAB_DIR=$TEST_LAB_DIR_PATH |
| 138 | export CONFIG_DIR_PATH=$CONFIG_DIR |
| 139 | |
waqas.ikram | 4d81375 | 2019-08-13 11:24:45 +0000 | [diff] [blame] | 140 | docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME up -d |
waqas.ikram | 7d75329 | 2019-07-18 16:41:17 +0000 | [diff] [blame] | 141 | |
| 142 | echo "Sleeping for 3m" |
| 143 | sleep 3m |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 144 | |
waqas.ikram | 5fee448 | 2019-07-22 13:56:13 +0000 | [diff] [blame] | 145 | echo "Will execute $WAIT_FOR_WORKAROUND_SCRIPT script" |
| 146 | $WAIT_FOR_WORKAROUND_SCRIPT |
| 147 | |
| 148 | if [ $? -ne 0 ]; then |
| 149 | echo "ERROR: $WAIT_FOR_WORKAROUND_SCRIPT failed" |
| 150 | echo "Will stop running docker containers . . ." |
eHanan | 75c1171 | 2019-08-13 15:44:16 +0000 | [diff] [blame] | 151 | docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME down |
waqas.ikram | 5fee448 | 2019-07-22 13:56:13 +0000 | [diff] [blame] | 152 | exit 1 |
| 153 | fi |
| 154 | |
waqas.ikram | a5aeeda | 2019-08-07 16:03:14 +0000 | [diff] [blame] | 155 | echo "Will execute $WAIT_FOR_POPULATE_AAI_SCRIPT script" |
| 156 | $WAIT_FOR_POPULATE_AAI_SCRIPT |
| 157 | |
| 158 | if [ $? -ne 0 ]; then |
| 159 | echo "ERROR: $WAIT_FOR_POPULATE_AAI_SCRIPT failed" |
| 160 | echo "Will stop running docker containers . . ." |
eHanan | 75c1171 | 2019-08-13 15:44:16 +0000 | [diff] [blame] | 161 | docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME down |
| 162 | exit 1 |
| 163 | fi |
| 164 | |
| 165 | API_INFRA_CONTAINER_NAME="api-handler-infra" |
| 166 | echo "Will execute $WAIT_FOR_CONTAINER_SCRIPT to wait for $API_INFRA_CONTAINER_NAME container to start up" |
waqas.ikram | 50e7ec9 | 2019-08-14 14:27:41 +0000 | [diff] [blame^] | 167 | $WAIT_FOR_CONTAINER_SCRIPT -c "$API_INFRA_CONTAINER_NAME" -t "300" -n "$DEFAULT_NETWORK_NAME" |
eHanan | 75c1171 | 2019-08-13 15:44:16 +0000 | [diff] [blame] | 168 | |
| 169 | if [ $? -ne 0 ]; then |
| 170 | echo "ERROR: $WAIT_FOR_CONTAINER_SCRIPT failed" |
| 171 | echo "Will stop running docker containers . . ." |
| 172 | docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME down |
waqas.ikram | a5aeeda | 2019-08-07 16:03:14 +0000 | [diff] [blame] | 173 | exit 1 |
| 174 | fi |
waqas.ikram | 5fee448 | 2019-07-22 13:56:13 +0000 | [diff] [blame] | 175 | |
waqas.ikram | b01df8b | 2019-07-09 16:14:17 +0000 | [diff] [blame] | 176 | REPO_IP='127.0.0.1' |
| 177 | ROBOT_VARIABLES="-v REPO_IP:${REPO_IP}" |
| 178 | |
| 179 | echo "Finished executing $SCRIPT_HOME/$SCRIPT_NAME" |