[openstack-glance/f17] Use MySQL by default, add openstack-glance-db-setup.
Russell Bryant
russellb at fedoraproject.org
Wed Mar 28 01:12:22 UTC 2012
commit d6405ca868296671d3b7aa1649a83b46ada11a71
Author: Russell Bryant <rbryant at redhat.com>
Date: Tue Mar 27 15:23:14 2012 -0400
Use MySQL by default, add openstack-glance-db-setup.
openstack-glance-db-setup | 239 +++++++++++++++++++++++++++++++++++++++++++++
openstack-glance.spec | 14 +++-
2 files changed, 251 insertions(+), 2 deletions(-)
---
diff --git a/openstack-glance-db-setup b/openstack-glance-db-setup
new file mode 100755
index 0000000..3dc2a34
--- /dev/null
+++ b/openstack-glance-db-setup
@@ -0,0 +1,239 @@
+#!/bin/bash
+#
+# Copyright (C) 2011 - 2012, Red Hat, Inc.
+# Russell Bryant <rbryant at redhat.com>
+#
+# 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.
+#
+
+#
+# Print --help output and exit.
+#
+usage() {
+
+cat << EOF
+Set up a local MySQL database for use with openstack-glance.
+This script will create a 'glance' database that is accessible
+only on localhost by user 'glance' with password 'glance'.
+The setup of MySQL with a multi-server OpenStack installation
+is outside of the scope of this simple helper script.
+
+Usage: openstack-glance-db-setup [options]
+Options:
+ --help | -h
+ Print usage information.
+ --glancepw <pw> | -n <pw>
+ Specify the password for the 'glance' MySQL user that glance will
+ use to connect to the 'glance' MySQL database. By default,
+ the password 'glance' will be used.
+ --rootpw <pw> | -r <pw>
+ Specify the root MySQL password. If the script installs
+ the MySQL server, it will set the root password to this value
+ instead of prompting for a password. If the MySQL server is
+ already installed, this password will be used to connect to the
+ database instead of having to prompt for it.
+ --yes | -y
+ In cases where the script would normally ask for confirmation
+ before doing something, such as installing mysql-server,
+ just assume yes. This is useful if you want to run the script
+ non-interactively.
+EOF
+
+ exit 0
+}
+
+install_mysql_server() {
+ if [ -z "${ASSUME_YES}" ] ; then
+ yum install mysql-server
+ else
+ yum install -y mysql-server
+ fi
+}
+
+start_mysql_server() {
+ systemctl start mysqld.service
+}
+
+MYSQL_GLANCE_PW_DEFAULT="glance"
+MYSQL_GLANCE_PW=${MYSQL_GLANCE_PW_DEFAULT}
+GLANCE_CONFIG="/etc/glance/glance.conf"
+ASSUME_YES=""
+
+while [ $# -gt 0 ]
+do
+ case "$1" in
+ -h|--help)
+ usage
+ ;;
+ -n|--glancepw)
+ shift
+ MYSQL_GLANCE_PW=${1}
+ ;;
+ -r|--rootpw)
+ shift
+ MYSQL_ROOT_PW=${1}
+ ;;
+ -y|--yes)
+ ASSUME_YES="yes"
+ ;;
+ *)
+ # ignore
+ shift
+ ;;
+ esac
+ shift
+done
+
+
+# Make sure MySQL is installed.
+
+NEW_MYSQL_INSTALL=0
+if ! rpm -q mysql-server > /dev/null
+then
+ if [ -z "${ASSUME_YES}" ] ; then
+ printf "mysql-server is not installed. Would you like to install it now? (y/n): "
+ read response
+ case "$response" in
+ y|Y)
+ ;;
+ n|N)
+ echo "mysql-server must be installed. Please install it before proceeding."
+ exit 0
+ ;;
+ *)
+ echo "Invalid response."
+ exit 1
+ esac
+ fi
+
+ NEW_MYSQL_INSTALL=1
+ install_mysql_server
+fi
+
+
+# Make sure mysqld is running.
+
+if ! systemctl status mysqld.service > /dev/null
+then
+ if [ -z "${ASSUME_YES}" ] ; then
+ printf "mysqld is not running. Would you like to start it now? (y/n): "
+ read response
+ case "$response" in
+ y|Y)
+ ;;
+ n|N)
+ echo "mysqld must be running. Please start it before proceeding."
+ exit 0
+ ;;
+ *)
+ echo "Invalid response."
+ exit 1
+ esac
+ fi
+
+ start_mysql_server
+
+ # If we both installed and started, ensure it starts at boot
+ [ $NEW_MYSQL_INSTALL -eq 1 ] && chkconfig mysqld on
+fi
+
+
+# Get MySQL root access.
+
+if [ $NEW_MYSQL_INSTALL -eq 1 ]
+then
+ if [ ! "${MYSQL_ROOT_PW+defined}" ] ; then
+ echo "Since this is a fresh installation of MySQL, please set a password for the 'root' mysql user."
+
+ PW_MATCH=0
+ while [ $PW_MATCH -eq 0 ]
+ do
+ printf "Enter new password for 'root' mysql user: "
+ read -s MYSQL_ROOT_PW
+ echo
+ printf "Enter new password again: "
+ read -s PW2
+ echo
+ if [ "${MYSQL_ROOT_PW}" = "${PW2}" ] ; then
+ PW_MATCH=1
+ else
+ echo "Passwords did not match."
+ fi
+ done
+ fi
+
+ echo "UPDATE mysql.user SET password = password('${MYSQL_ROOT_PW}') WHERE user = 'root'; DELETE FROM mysql.user WHERE user = ''; flush privileges;" | mysql -u root
+ if ! [ $? -eq 0 ] ; then
+ echo "Failed to set password for 'root' MySQL user."
+ exit 1
+ fi
+elif [ ! "${MYSQL_ROOT_PW+defined}" ] ; then
+ printf "Please enter the password for the 'root' MySQL user: "
+ read -s MYSQL_ROOT_PW
+ echo
+fi
+
+
+# Sanity check MySQL credentials.
+
+MYSQL_ROOT_PW_ARG=""
+if [ "${MYSQL_ROOT_PW+defined}" ]
+then
+ MYSQL_ROOT_PW_ARG="--password=${MYSQL_ROOT_PW}"
+fi
+echo "SELECT 1;" | mysql -u root ${MYSQL_ROOT_PW_ARG} > /dev/null
+if ! [ $? -eq 0 ]
+then
+ echo "Failed to connect to the MySQL server. Please check your root user credentials."
+ exit 1
+fi
+echo "Verified connectivity to MySQL."
+
+
+# Now create the db.
+
+echo "Creating 'glance' database."
+cat << EOF | mysql -u root ${MYSQL_ROOT_PW_ARG}
+CREATE DATABASE glance;
+CREATE USER 'glance'@'localhost' IDENTIFIED BY '${MYSQL_GLANCE_PW}';
+CREATE USER 'glance'@'%' IDENTIFIED BY '${MYSQL_GLANCE_PW}';
+GRANT ALL ON glance.* TO 'glance'@'localhost';
+GRANT ALL ON glance.* TO 'glance'@'%';
+flush privileges;
+EOF
+
+
+# Make sure glance configuration has the right MySQL password.
+
+if [ "${MYSQL_GLANCE_PW}" != "${MYSQL_GLANCE_PW_DEFAULT}" ] ; then
+ echo "Updating 'glance' database password in ${GLANCE_CONFIG}"
+ sed -i -e "s/mysql:\/\/glance:\(.*\)@/mysql:\/\/glance:${MYSQL_GLANCE_PW}@/" ${GLANCE_CONFIG}
+fi
+
+
+# Ask openstack-glance to sync the db.
+
+echo "Asking openstack-glance to sync the database."
+glance-manage db_sync
+
+
+# Do a final sanity check on the database.
+
+echo "SELECT * FROM migrate_version;" | mysql -u glance --password=${MYSQL_GLANCE_PW} glance > /dev/null
+if ! [ $? -eq 0 ]
+then
+ echo "Final sanity check failed. File a bug report on bugzilla.redhat.com against the openstack-glance package."
+ exit 1
+fi
+
+echo "Complete!"
diff --git a/openstack-glance.spec b/openstack-glance.spec
index ff80696..c9745d5 100644
--- a/openstack-glance.spec
+++ b/openstack-glance.spec
@@ -1,6 +1,6 @@
Name: openstack-glance
Version: 2012.1
-Release: 0.8.rc1%{?dist}
+Release: 0.9.rc1%{?dist}
Summary: OpenStack Image Service
Group: Applications/System
@@ -10,6 +10,7 @@ Source0: http://launchpad.net/glance/essex/essex-rc1/+download/glance-2
Source1: openstack-glance-api.service
Source2: openstack-glance-registry.service
Source3: openstack-glance.logrotate
+Source4: openstack-glance-db-setup
#
# patches_base=essex-rc1
@@ -43,6 +44,7 @@ This package contains the API and registry servers.
Summary: Glance Python libraries
Group: Applications/System
+Requires: MySQL-python
Requires: pysendfile
Requires: python-eventlet
Requires: python-httplib2
@@ -92,7 +94,7 @@ This package contains documentation files for glance.
%patch0001 -p1
-sed -i 's|\(sql_connection = sqlite:///\)\(glance.sqlite\)|\1%{_sharedstatedir}/glance/\2|' etc/glance-registry.conf
+sed -i 's|\(sql_connection = \)sqlite:///glance.sqlite|\1mysql://glance:glance@localhost/glance|' etc/glance-registry.conf
sed -i '/\/usr\/bin\/env python/d' glance/common/config.py glance/registry/db/migrate_repo/manage.py
@@ -149,6 +151,9 @@ install -d -m 755 %{buildroot}%{_localstatedir}/run/glance
# Install log directory
install -d -m 755 %{buildroot}%{_localstatedir}/log/glance
+# Install database setup helper script.
+install -p -D -m 755 %{SOURCE4} %{buildroot}%{_bindir}/openstack-glance-db-setup
+
%pre
getent group glance >/dev/null || groupadd -r glance -g 161
getent passwd glance >/dev/null || \
@@ -192,6 +197,7 @@ fi
%{_bindir}/glance-cache-prefetcher
%{_bindir}/glance-cache-pruner
%{_bindir}/glance-scrubber
+%{_bindir}/openstack-glance-db-setup
%{_unitdir}/openstack-glance-api.service
%{_unitdir}/openstack-glance-registry.service
%{_mandir}/man1/glance*.1.gz
@@ -219,6 +225,10 @@ fi
%doc doc/build/html
%changelog
+* Tue Mar 27 2012 Russell Bryant <rbryant at redhat.com> - 2012-.1-0.9.rc1
+- Use MySQL by default.
+- Add openstack-glance-db-setup script.
+
* Wed Mar 21 2012 Russell Bryant <rbryant at redhat.com> - 2012.1-0.8.rc1
- Fix source URL for essex rc1
More information about the scm-commits
mailing list