2 FUEL_RELEASE=$(grep release: /etc/fuel/version.yaml | cut -d: -f2 | tr -d '" ')
7 for ((i=$1-1; i>=1; i--)); do
8 printf '\b\b\b\b%04d' "$i"
14 echo "ERROR: Fuel node deployment FAILED! Check /var/log/puppet/bootstrap_admin_node.log for details" 1>&2
17 # LANG variable is a workaround for puppet-3.4.2 bug. See LP#1312758 for details
18 export LANG=en_US.UTF8
19 export ADMIN_INTERFACE=eth0
22 if [ -f /etc/fuel/bootstrap_admin_node.conf ]; then
23 . /etc/fuel/bootstrap_admin_node.conf
24 echo "Applying admin interface '$ADMIN_INTERFACE'"
27 echo "Applying default Fuel settings..."
29 fuelmenu --save-only --iface=$ADMIN_INTERFACE
33 ### OPNFV addition BEGIN
35 for script in /opt/opnfv/bootstrap/pre.d/*.sh
37 echo "Pre script: $script" >> /root/pre.log 2>&1
38 $script >> /root/pre.log 2>&1
41 ### OPNFV addition END
43 if [[ "$showmenu" == "yes" || "$showmenu" == "YES" ]]; then
46 #Give user 15 seconds to enter fuelmenu or else continue
48 echo -n "Press a key to enter Fuel Setup (or press ESC to skip)... 15"
50 if ! read -s -n 1 -t 15 key; then
51 echo -e "\nSkipping Fuel Setup..."
53 { kill "$pid"; wait $!; } 2>/dev/null
55 $'\e') echo "Skipping Fuel Setup.."
57 *) echo -e "\nEntering Fuel Setup..."
64 if [ "$wait_for_external_config" == "yes" ]; then
66 pidfile=/var/lock/wait_for_external_config
67 echo -n "Waiting for external configuration (or press ESC to skip)...
69 countdown $wait_timeout & countdown_pid=$!
70 exec -a wait_for_external_config sleep $wait_timeout & wait_pid=$!
71 echo $wait_pid > $pidfile
72 while ps -p $countdown_pid &> /dev/null && ps -p $wait_pid &>/dev/null; do
75 $'\e') echo -e "\b\b\b\b abort on user input"
81 { kill $countdown_pid $wait_pid & wait $!; }
86 #Reread /etc/sysconfig/network to inform puppet of changes
87 . /etc/sysconfig/network
90 # XXX: ssh keys which should be included into the bootstrap image are
91 # generated during containers deployment. However cobbler checkfs for
92 # a kernel and initramfs when creating a profile, which poses chicken
93 # and egg problem. Fortunately cobbler is pretty happy with empty files
94 # so it's easy to break the loop.
95 make_ubuntu_bootstrap_stub () {
96 local bootstrap_dir='/var/www/nailgun/bootstrap/ubuntu'
97 mkdir -p $bootstrap_dir
98 for item in linux initramfs.img; do
99 touch "$bootstrap_dir/$item"
103 get_bootstrap_flavor () {
104 local ASTUTE_YAML='/etc/fuel/astute.yaml'
106 from fuelmenu.fuelmenu import Settings
107 conf = Settings().read("$ASTUTE_YAML").get('BOOTSTRAP', {})
108 print(conf.get('flavor', 'centos'))
112 # Actually build the bootstrap image
113 build_ubuntu_bootstrap () {
116 local config='/etc/fuel-bootstrap-image.conf'
117 local log='/var/log/fuel-bootstrap-image-build.log'
118 if ! grep -qE '^BOOTSTRAP_SSH_KEYS' "$config"; then
119 # FIXME: config file generated by fuelmenu has no trailing newline
121 cat >> "$config" <<-EOF
122 BOOTSTRAP_SSH_KEYS=/root/.ssh/id_rsa.pub
125 for n in `seq 1 $max_attempts`; do
126 echo "Bulding bootstrap image, attempt $n" >&2
127 if fuel-bootstrap-image >>"$log" 2>&1; then
129 fuel-bootstrap-image-set "ubuntu"
133 if [ $ret -ne 0 ]; then
134 warning="WARNING: failed to build the bootstrap image, see $log for details.
135 Perhaps your Internet connection is broken. Please fix the problem and run
136 \`fuel-bootstrap-image-set ubuntu\`"
137 fuel notify --topic warning --send "$warning"
143 # Create empty files to make cobbler happy
144 # (even if we don't use Ubuntu based bootstrap)
145 make_ubuntu_bootstrap_stub
149 if [ -f /root/.build_images ]; then
154 echo "Loading Fuel base image for Docker..."
155 docker load -i /var/www/nailgun/docker/images/fuel-images.tar
157 echo "Building Fuel Docker images..."
158 WORKDIR=$(mktemp -d /tmp/docker-buildXXX)
159 SOURCE=/var/www/nailgun/docker
160 REPO_CONT_ID=$(docker -D run -d -p 80 -v /var/www/nailgun:/var/www/nailgun fuel/centos sh -c 'mkdir /var/www/html/os;ln -sf /var/www/nailgun/centos/x86_64 /var/www/html/os/x86_64;/usr/sbin/apachectl -DFOREGROUND')
161 RANDOM_PORT=$(docker port $REPO_CONT_ID 80 | cut -d':' -f2)
163 for imagesource in /var/www/nailgun/docker/sources/*; do
164 if ! [ -f "$imagesource/Dockerfile" ]; then
165 echo "Skipping ${imagesource}..."
168 image=$(basename "$imagesource")
169 cp -R "$imagesource" $WORKDIR/$image
170 mkdir -p $WORKDIR/$image/etc
171 cp -R /etc/puppet /etc/fuel $WORKDIR/$image/etc
172 sed -e "s/_PORT_/${RANDOM_PORT}/" -i $WORKDIR/$image/Dockerfile
173 sed -e 's/production:.*/production: "docker-build"/' -i $WORKDIR/$image/etc/fuel/version.yaml
174 docker build -t fuel/${image}_${FUEL_RELEASE} $WORKDIR/$image
176 docker rm -f $REPO_CONT_ID
179 #Remove trap for normal deployment
183 echo "Loading docker images. (This may take a while)"
184 docker load -i /var/www/nailgun/docker/images/fuel-images.tar
188 puppet apply --detailed-exitcodes -d -v /etc/puppet/modules/nailgun/examples/host-only.pp
193 rmdir /var/log/remote && ln -s /var/log/docker-logs/remote /var/log/remote
195 dockerctl check || fail
198 if [ "`get_bootstrap_flavor`" = "ubuntu" ]; then
199 build_ubuntu_bootstrap || true
202 ### OPNFV addition BEGIN
204 for script in /opt/opnfv/bootstrap/post.d/*.sh
206 echo "Post script: $script" >> /root/post.log 2>&1
207 $script >> /root/post.log 2>&1
210 ### OPNFV addition END
212 # Enable updates repository
213 cat > /etc/yum.repos.d/mos${FUEL_RELEASE}-updates.repo << EOF
214 [mos${FUEL_RELEASE}-updates]
215 name=mos${FUEL_RELEASE}-updates
216 baseurl=http://mirror.fuel-infra.org/mos-repos/centos/mos${FUEL_RELEASE}-centos6-fuel/updates/x86_64/
218 skip_if_unavailable=1
221 # Enable security repository
222 cat > /etc/yum.repos.d/mos${FUEL_RELEASE}-security.repo << EOF
223 [mos${FUEL_RELEASE}-security]
224 name=mos${FUEL_RELEASE}-security
225 baseurl=http://mirror.fuel-infra.org/mos-repos/centos/mos${FUEL_RELEASE}-centos6-fuel/security/x86_64/
227 skip_if_unavailable=1
230 #Check if repo is accessible
231 echo "Checking for access to updates repository..."
232 repourl=$(grep baseurl /etc/yum.repos.d/*updates* 2>/dev/null | cut -d'=' -f2- | head -1)
233 if urlaccesscheck check "$repourl" ; then
239 if [ $UPDATE_ISSUES -eq 1 ]; then
240 message="There is an issue connecting to the Fuel update repository. \
241 Please fix your connection prior to applying any updates. \
242 Once the connection is fixed, we recommend reviewing and applying \
243 Maintenance Updates for this release of Mirantis OpenStack: \
244 https://docs.mirantis.com/openstack/fuel/fuel-${FUEL_RELEASE}/\
245 release-notes.html#maintenance-updates"
248 message="We recommend reviewing and applying Maintenance Updates \
249 for this release of Mirantis OpenStack: \
250 https://docs.mirantis.com/openstack/fuel/fuel-${FUEL_RELEASE}/\
251 release-notes.html#maintenance-updates"
255 echo "*************************************************"
257 echo "*************************************************"
258 echo "Sending notification to Fuel UI..."
259 fuel notify --topic "${level}" --send "${message}"
261 # TODO(kozhukalov) If building of bootstrap image fails
262 # and if this image was supposed to be a default bootstrap image
263 # we need to warn a user about this and give her
264 # advice how to treat this.
266 echo "Fuel node deployment complete!"