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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 python -c 'import json,sys,yaml; json.dump(yaml.safe_load(sys.stdin.read()), sys.stdout)'
25 #0. Get values for the environment variables
27 # The following must be provided.
28 REC_ISO_IMAGE_NAME="${REC_ISO_IMAGE_NAME:?'Must be defined!'}"
29 REC_PROVISIONING_ISO_NAME="${REC_PROVISIONING_ISO_NAME:?'Must be defined!'}"
30 REC_USER_CONFIG="${REC_USER_CONFIG:?'Must be defined!'}"
32 # The next set may be modified if necessary but are best left as-is
34 POD_NAME="REC-$BUILD_ID"
37 # Max time (in minutes) to wait for the remote-installer to return completed
41 # These should probably not be changed
43 BASEDIR="$WORKDIR/rec_basedir"
47 --------------------------------------------
51 REC_ISO_IMAGE_NAME is $REC_ISO_IMAGE_NAME
52 REC_PROVISIONING_ISO_NAME is $REC_PROVISIONING_ISO_NAME
53 REC_USER_CONFIG is $REC_USER_CONFIG
54 --------------------------------------------
61 sudo chown -R jenkins:jenkins "$WORKDIR"
62 docker cp 'remote-installer':/var/log/remote-installer.log "$BASEDIR/"
63 docker rm -f 'remote-installer'
64 trap - EXIT ERR HUP INT QUIT TERM
67 trap _cleanup EXIT ERR HUP INT QUIT TERM
72 #1. Create a new directory to be used for holding the installation artifacts.
74 # Clean workspace from previous run
75 sudo chown -R jenkins:jenkins "$WORKDIR"
78 # Create the base directory structure
79 mkdir -p "$BASEDIR/images" \
80 "$BASEDIR/certificates" \
81 "$BASEDIR/installations" \
82 "$BASEDIR/user-configs/$POD_NAME"
84 #2. Get REC golden and bootcd images from REC Nexus artifacts
87 curl -sL "$REC_ISO_IMAGE_NAME" > "$(basename "$REC_ISO_IMAGE_NAME")"
88 curl -sL "$REC_PROVISIONING_ISO_NAME" > "$(basename "$REC_PROVISIONING_ISO_NAME")"
90 #3. Get the user-config.yaml file and admin_password file for the CD environment from the
91 # cd-environments repo and copy it to the user-configs sub-directory under the directory
92 # created in (1). Copy the files to a cloud-specific directory identified by the cloudname.
94 cd "$BASEDIR/user-configs/$POD_NAME"
95 curl -sL "$REC_USER_CONFIG" > user_config.yaml
96 echo "$ADMIN_PASSWD" > admin_passwd
98 FIRST_CONTROLLER_IP="$(_yaml2json < user_config.yaml | \
99 jq -r '.hosts[]|select(.service_profiles[]|contains("caas_master", "controller"))|.hwmgmt.address' | \
101 HOST_IP="$(ip route get "$FIRST_CONTROLLER_IP" | grep -Pzo 'src\s+\K([^\s]*)' )"
103 #4. Copy the sever certificates, the client certificates in addition to CA certificate to
104 # the certificates sub-directory under the directory created in (1).
105 # The following certificates are expected to be available in the directory:
107 # cacert.pem: The CA certificate
108 # servercert.pem: The server certificate signed by the CA
109 # serverkey.pem: The server key
110 # clientcert.pem: The client certificate signed by the CA
111 # clientkey.pem: The client key
114 cd "$WORKDIR/git/remote-installer/test/certificates"
116 cp -a {ca,client,server}{cert,key}.pem "${BASEDIR}/certificates/"
118 #5. Build the remote installer docker-image.
119 cd "$WORKDIR/git/remote-installer/scripts/"
120 ./build.sh "$HTTPS_PORT" "$API_PORT"
122 #6. Start the remote installer
124 cd "$WORKDIR/git/remote-installer/scripts/"
125 if ! ./start.sh -b "$BASEDIR" -e "$HOST_IP" -s "$HTTPS_PORT" -a "$API_PORT" -p "$ADMIN_PASSWD"
127 echo 'Failed to run workflow.'
131 #7. Wait for the remote installer to become running.
132 # check every 30 seconds to see if it has it has a status of "running"
136 while [ ${#DOCKER_STATUS} -eq 0 ]; do
138 DOCKER_ID=$(docker ps | grep 'remote-installer' | awk '{print $1}')
139 DOCKER_STATUS=$(docker ps -f status=running | grep "$DOCKER_ID")
142 #8. Start the installation by sending the following http request to the installer API
144 # POST url: https://localhost:$API_PORT/v1/installations
145 # REQ body json- encoded
147 # 'cloudname': $POD_NAME,
148 # 'iso': $REC_ISO_IMAGE_NAME,
149 # 'provisioning-iso': $REC_PROVISIONING_ISO_NAME
151 # REP body json-encoded
153 # 'uuid': $INSTALLATION_UUID
156 INSTALL_ISO="$(basename "$REC_ISO_IMAGE_NAME")"
157 BOOT_ISO="$(basename "$REC_PROVISIONING_ISO_NAME")"
158 cat >rec_request.json <<EOF
160 "cloud-name": "$POD_NAME",
161 "iso": "$INSTALL_ISO",
162 "provisioning-iso": "$BOOT_ISO"
166 # Get the IP address of the remote installer container
169 RESPONSE=$(curl -k --silent \
170 --header "Content-Type: application/json" \
171 -d "@rec_request.json" \
172 --cert "$BASEDIR/certificates/clientcert.pem" \
173 --key "$BASEDIR/certificates/clientkey.pem" \
174 "https://${RI_IP}:${API_PORT}/v1/installations")
175 echo "$0: RESPONSE IS $RESPONSE"
177 INSTALLATION_UUID="$(echo "$RESPONSE" | jq -r ".uuid")"
179 #9. Follow the progress of the installation by sending the following http request to the installer API
181 # GET url: https://localhost:$API_PORT/v1/installations/$INSTALLATION_UUID
183 # REP body json-encoded
185 # 'status': <ongoing|completed|failed>,
186 # 'description': <description>,
187 # 'percentage': <the progess precentage>
192 # check the status every minute until it has become "completed"
193 # (for a maximum of MAX_TIME minutes)
197 while [ "$STATUS" == "ongoing" -a $NTIMES -gt 0 ]; do
199 NTIMES=$((NTIMES - 1))
200 RESPONSE=$(curl -k --silent \
201 --cert "$BASEDIR/certificates/clientcert.pem" \
202 --key "$BASEDIR/certificates/clientkey.pem" \
203 "https://${RI_IP}:${API_PORT}/v1/installations/$INSTALLATION_UUID/state")
204 STATUS="$(echo "$RESPONSE" | jq -r ".status")"
205 PCT="$( echo "$RESPONSE" | jq -r ".percentage")"
206 DESCR="$( echo "$RESPONSE" | jq -r ".description")"
207 echo "$(date): Status is $STATUS ($PCT) $DESCR"
210 if [ "$STATUS" == "ongoing" -a $NTIMES -le 0 ]; then
211 echo "Installation failed after $MAX_TIME minutes."
212 echo "RESPONSE: $RESPONSE"
214 elif [ "$STATUS" != "completed" ]; then
215 echo "Installation failed."
216 echo "RESPONSE: $RESPONSE"
220 echo "Installation complete!"