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