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 stop 'remote-installer'
64 docker rm -f 'remote-installer'
65 trap - EXIT ERR HUP INT QUIT TERM
68 trap _cleanup EXIT ERR HUP INT QUIT TERM
73 #1. Create a new directory to be used for holding the installation artifacts.
75 # Clean workspace from previous run
76 sudo chown -R jenkins:jenkins "$WORKDIR"
79 # Create the base directory structure
80 mkdir -p "$BASEDIR/images" \
81 "$BASEDIR/certificates" \
82 "$BASEDIR/installations" \
83 "$BASEDIR/user-configs/$POD_NAME"
85 #2. Get REC golden and bootcd images from REC Nexus artifacts
88 curl -sL "$REC_ISO_IMAGE_NAME" > "$(basename "$REC_ISO_IMAGE_NAME")"
89 curl -sL "$REC_PROVISIONING_ISO_NAME" > "$(basename "$REC_PROVISIONING_ISO_NAME")"
91 #3. Get the user-config.yaml file and admin_password file for the CD environment from the
92 # cd-environments repo and copy it to the user-configs sub-directory under the directory
93 # created in (1). Copy the files to a cloud-specific directory identified by the cloudname.
95 cd "$BASEDIR/user-configs/$POD_NAME"
96 curl -sL "$REC_USER_CONFIG" > user_config.yaml
97 echo "$ADMIN_PASSWD" > admin_passwd
99 FIRST_CONTROLLER_IP="$(_yaml2json < user_config.yaml | \
100 jq -r '.hosts[]|select(.service_profiles[]|contains("caas_master", "controller"))|.hwmgmt.address' | \
102 HOST_IP="$(ip route get "$FIRST_CONTROLLER_IP" | grep -Pzo 'src\s+\K([^\s]*)' )"
104 #4. Copy the sever certificates, the client certificates in addition to CA certificate to
105 # the certificates sub-directory under the directory created in (1).
106 # The following certificates are expected to be available in the directory:
108 # cacert.pem: The CA certificate
109 # servercert.pem: The server certificate signed by the CA
110 # serverkey.pem: The server key
111 # clientcert.pem: The client certificate signed by the CA
112 # clientkey.pem: The client key
115 cd "$WORKDIR/git/remote-installer/test/certificates"
117 cp -a {ca,client,server}{cert,key}.pem "${BASEDIR}/certificates/"
119 #5. Build the remote installer docker-image.
120 cd "$WORKDIR/git/remote-installer/scripts/"
121 ./build.sh "$HTTPS_PORT" "$API_PORT"
123 #6. Start the remote installer
125 cd "$WORKDIR/git/remote-installer/scripts/"
126 if ! ./start.sh -b "$BASEDIR" -e "$HOST_IP" -s "$HTTPS_PORT" -a "$API_PORT" -p "$ADMIN_PASSWD"
128 echo 'Failed to run workflow.'
132 #7. Wait for the remote installer to become running.
133 # check every 30 seconds to see if it has it has a status of "running"
137 while [ ${#DOCKER_STATUS} -eq 0 ]; do
139 DOCKER_ID=$(docker ps | grep 'remote-installer' | awk '{print $1}')
140 DOCKER_STATUS=$(docker ps -f status=running | grep "$DOCKER_ID")
143 #8. Start the installation by sending the following http request to the installer API
145 # POST url: https://localhost:$API_PORT/v1/installations
146 # REQ body json- encoded
148 # 'cloudname': $POD_NAME,
149 # 'iso': $REC_ISO_IMAGE_NAME,
150 # 'provisioning-iso': $REC_PROVISIONING_ISO_NAME
152 # REP body json-encoded
154 # 'uuid': $INSTALLATION_UUID
157 INSTALL_ISO="$(basename "$REC_ISO_IMAGE_NAME")"
158 BOOT_ISO="$(basename "$REC_PROVISIONING_ISO_NAME")"
159 cat >rec_request.json <<EOF
161 "cloud-name": "$POD_NAME",
162 "iso": "$INSTALL_ISO",
163 "provisioning-iso": "$BOOT_ISO"
167 # Get the IP address of the remote installer container
170 RESPONSE=$(curl -k --silent \
171 --header "Content-Type: application/json" \
172 -d "@rec_request.json" \
173 --cert "$BASEDIR/certificates/clientcert.pem" \
174 --key "$BASEDIR/certificates/clientkey.pem" \
175 "https://${RI_IP}:${API_PORT}/v1/installations")
176 echo "$0: RESPONSE IS $RESPONSE"
178 INSTALLATION_UUID="$(echo "$RESPONSE" | jq -r ".uuid")"
180 #9. Follow the progress of the installation by sending the following http request to the installer API
182 # GET url: https://localhost:$API_PORT/v1/installations/$INSTALLATION_UUID
184 # REP body json-encoded
186 # 'status': <ongoing|completed|failed>,
187 # 'description': <description>,
188 # 'percentage': <the progess precentage>
193 # check the status every minute until it has become "completed"
194 # (for a maximum of MAX_TIME minutes)
198 while [ "$STATUS" == "ongoing" -a $NTIMES -gt 0 ]; do
200 NTIMES=$((NTIMES - 1))
201 RESPONSE=$(curl -k --silent \
202 --cert "$BASEDIR/certificates/clientcert.pem" \
203 --key "$BASEDIR/certificates/clientkey.pem" \
204 "https://${RI_IP}:${API_PORT}/v1/installations/$INSTALLATION_UUID/state")
205 STATUS="$(echo "$RESPONSE" | jq -r ".status")"
206 PCT="$( echo "$RESPONSE" | jq -r ".percentage")"
207 DESCR="$( echo "$RESPONSE" | jq -r ".description")"
208 echo "$(date): Status is $STATUS ($PCT) $DESCR"
211 if [ "$STATUS" == "ongoing" -a $NTIMES -le 0 ]; then
212 echo "Installation failed after $MAX_TIME minutes."
213 echo "RESPONSE: $RESPONSE"
215 elif [ "$STATUS" != "completed" ]; then
216 echo "Installation failed."
217 echo "RESPONSE: $RESPONSE"
221 echo "Installation complete!"