[TRAIN ONLY] Wait until DB is ready for neutron DB rename

On resource-constrainted systems, the database may take a little
extra time to come up. Currently this container fails if the
database is not immediately available.

In this patch we introduce a check to see if the database is
available, and a sleep/check cycle for up to two minutes before
timing out.

Resolves: rhbz#1851445
Change-Id: I50924f4f4d9606b6263e33dfe38b5bd37a6b56a5
This commit is contained in:
Jesse Pretorius (odyssey4me) 2020-07-06 16:16:07 +01:00
parent 1bac4f00fc
commit 6dfbdbbca6
2 changed files with 49 additions and 14 deletions

View File

@ -0,0 +1,38 @@
#!/bin/bash
# Copyright 2020 Red Hat Inc.
#
# 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.
set -e
retries=0
if [ -d /var/lib/mysql/neutron ] ; then
# check whether the database is available and returning responses
until mysql -e "SELECT 1;" &>/dev/null; do
retries=$(( retries + 1 ))
# 12 retries = 12 x 10sec = 2 minutes
if [ $retries -ge 12 ]; then
echo "Database still not available. Terminating ..."
exit 1
else
echo "$retries: Waiting for database availability ..."
sleep 10
fi
done
mysql -e "CREATE DATABASE IF NOT EXISTS \`ovs_neutron\`;"
for table in `mysql -B -N -e "SHOW TABLES;" neutron`; do
mysql -e "RENAME TABLE \`neutron\`.\`$table\` to \`ovs_neutron\`.\`$table\`"
done
mysql -e "DROP DATABASE \`neutron\`;"
fi

View File

@ -58,6 +58,9 @@ conditions:
resources:
ContainersCommon:
type: ../containers-common.yaml
MysqlBase:
type: ./mysql-base.yaml
properties:
@ -119,6 +122,12 @@ outputs:
- path: /etc/pki/tls/private/mysql.key
owner: mysql:mysql
optional: true
container_config_scripts:
map_merge:
- {get_attr: [ContainersCommon, container_config_scripts]}
- neutron_db_rename.sh:
mode: "0755"
content: { get_file: ../../container_config_scripts/neutron_db_rename.sh }
docker_config:
# Kolla_bootstrap runs before permissions set by kolla_config
step_1:
@ -207,25 +216,13 @@ outputs:
# required for bootstrap_host_exec
- /etc/puppet:/etc/puppet:ro
- /var/lib/config-data/puppet-generated/mysql/root:/root:rw #provides .my.cnf for puppet, changed on password update
- /var/lib/container-config-scripts/:/container-config-scripts/:ro
environment:
KOLLA_CONFIG_STRATEGY: COPY_ALWAYS
net: host
user: root
# Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
command:
- 'bash'
- '-ec'
-
list_join:
- "\n"
- - 'if [ -d /var/lib/mysql/neutron ] ; then'
- 'mysql -e "CREATE DATABASE IF NOT EXISTS \`ovs_neutron\`;"'
- 'for table in `mysql -B -N -e "SHOW TABLES;" neutron`'
- 'do'
- 'mysql -e "RENAME TABLE \`neutron\`.\`$table\` to \`ovs_neutron\`.\`$table\`"'
- 'done'
- 'mysql -e "DROP DATABASE \`neutron\`;"'
- 'fi'
- '/container-config-scripts/neutron_db_rename.sh'
step_3:
# sync credentials config on the running container if it was
# changed by the docker_puppet_task during step 2