Added bootstrap replacement support

In order to support Infiniband network, the bootstrap image
is changed when installing Mellanox plugin in Fuel 6.1.

The replacement is done in the post installation section of Mellanox
Plugin RPM.

The new bootstrap files and a script to reboot the discovered nodes with
the old bootstrap, are added to the plugin.

Partially-implements: blueprint support-infiniband-network

Change-Id: I092677a69bc3a3ad5db068d91252ba69f46ea400
This commit is contained in:
Aviram Bar-Haim 2015-03-29 17:55:55 +03:00
parent 909322cdbf
commit 310d79ef7c
4 changed files with 138 additions and 0 deletions

View File

@ -1,4 +1,18 @@
#!/bin/bash
# Copyright 2015 Mellanox Technologies, Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
readonly PLUGIN_DIR="$(dirname $0)"
readonly DEFAULT_REPOSITORY_HOST="10.212.14.8" #TODO: Change to MLNX public repo
@ -11,6 +25,10 @@ function download {
FILE_TYPE=$1
FILE_NAME=$2
case ${FILE_TYPE} in
'bootstrap')
PREFIX_URL=mellanox_plugin/bootstrap
BUILD_DIR=bootstrap
;;
*)
echo "Can't download ${FILE_NAME}. File of type ${FILE_TYPE} is not supported."
exit 1
@ -18,4 +36,10 @@ function download {
wget http://${REPOSITORY_HOST}/${PREFIX_URL}/${FILE_NAME} -P ${PLUGIN_DIR}/${BUILD_DIR}
}
# download bootstrap files
rm -rf ${PLUGIN_DIR}/bootstrap/*
for f in `cat ${PLUGIN_DIR}/requirements-bootstrap.txt`; do
download bootstrap $f
done
exit 0

View File

@ -0,0 +1,4 @@
initramfs.img
linux
.ofed
.kernel

92
scripts/reboot_bootstrap_nodes Executable file
View File

@ -0,0 +1,92 @@
#!/bin/bash
# Copyright 2015 Mellanox Technologies, Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
readonly LOG_FILE=/var/log/reboot_bootstrap_nodes.log
usage() {
echo "Usage: `basename $0` [-e environment_id] [-h] [-a]"
echo " This script is used to trigger reboot for nodes in 'discover' status,"
echo " of a given environment (if given) or of all environments. "
echo " Please wait for nodes to boot again after triggering this script."
echo "
Options:
-h Display the help message.
-e <env> Reboot all nodes in state 'discover' of the given environment.
-a Reboot all nodes in state 'discover' of all environments."
}
log() {
echo $1 | tee -a $LOG_FILE
}
while getopts "e:ha" opt; do
case $opt in
a)
env=''
log "Starting reboot cycle on env ${OPTARG} at `date`"
;;
h)
usage
exit 0
;;
e)
env="--env ${OPTARG}"
log "Starting reboot cycle on env ${OPTARG} at `date`"
;;
\?)
usage
exit 1
esac
done
if [ $OPTIND -eq 1 ]; then usage && exit 1; fi
shift $((OPTIND-1))
tmpjson=`mktemp`
trap "\rm -f $tmpjson; exit 1" SIGINT SIGTERM
fuel node $env --json > $tmpjson 2>/dev/null
ips=`python -c "import json; print '\n'.join([str(node['ip']) for node in json.load(open('$tmpjson')) if node['status'] == 'discover'])"`
if [ ${#ips} -eq 0 ];then
log "No nodes with state discover found for the given environments."
exit 0
fi
log "Rebooting nodes with IPs $ips"
for ip in $ips;
do
id=`python -c "import json; print '\n'.join([str(node['id']) for node in json.load(open('$tmpjson')) if node['ip'] == '$ip'])"`
ping -c 2 $ip &> /dev/null
if [ $? -eq 0 ];then
ssh $ip -o BatchMode=yes -o StrictHostKeyChecking=no reboot &> /dev/null
trials=10
log "waiting for node-$id to go offline."
while ping -c 2 $ip &> /dev/null && [ $trials -ne 0 ];do
((trials=$trials-1))
sleep 1;
done
if [ $trials -eq 0 ];then
log "node-$id reboot failed."
else
log "node-$id reboot succeeded. please wait for it to boot again."
fi
else
log "node-$id is already offline. please wait a few minutes or verify it is powered on."
fi
done
\rm -f $tmpjson

View File

@ -0,0 +1,18 @@
%%post
if [ -d "/var/www/nailgun/bootstrap/" ]; then
if [ ! -d "/opt/old_bootstrap_image/" ]; then
mkdir -p /opt/old_bootstrap_image/
mv /var/www/nailgun/bootstrap/* /opt/old_bootstrap_image/
fi
\cp $(ls /var/www/nailgun/plugins/mellanox_plugin*/bootstrap/initramfs.img) /var/www/nailgun/bootstrap/
\cp $(ls /var/www/nailgun/plugins/mellanox_plugin*/bootstrap/linux) /var/www/nailgun/bootstrap/
command -v dockerctl >/dev/null 2>&1
if [ $? -eq 0 ];then
dockerctl copy /var/www/nailgun/bootstrap/initramfs.img cobbler:/var/lib/tftpboot/images/bootstrap/initramfs.img
dockerctl copy /var/www/nailgun/bootstrap/linux cobbler:/var/lib/tftpboot/images/bootstrap/linux
\cp $(ls /var/www/nailgun/plugins/mellanox_plugin*/scripts/reboot_bootstrap_nodes) /sbin/
echo " `tput bold`Bootstrap discovery image has been replaced for detecting Mellanox Infiniband HW."
echo " please reboot your old bootstrap nodes ('reboot_bootstrap_nodes [environment_id|--help]' can be used).`tput sgr0`"
fi
fi