From 645d093c457a1ccae00d0068a6c2e76960c05b85 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Mon, 14 May 2012 16:03:49 +0200 Subject: [PATCH] Allow the Getting Started script to run non-interactively Related: #84 Signed-off-by: Zane Bitter --- bin/heat | 3 +++ bin/heat-db-setup | 13 +++++-------- docs/GettingStarted.rst | 8 ++++---- heat/utils.py | 2 +- tools/heat-db-drop | 26 ++++++++++++++++++++++---- tools/openstack | 39 +++++++++++++++++---------------------- tools/uninstall-heat | 7 ++++--- 7 files changed, 56 insertions(+), 42 deletions(-) diff --git a/bin/heat b/bin/heat index fa55ad5189..e574ff1d7d 100755 --- a/bin/heat +++ b/bin/heat @@ -311,6 +311,9 @@ def create_options(parser): help="Print more verbose output") parser.add_option('-d', '--debug', default=False, action="store_true", help="Print more verbose output") + parser.add_option('-y', '--yes', default=False, action="store_true", + help="Don't prompt for user input; assume the answer to " + "every question is 'yes'.") parser.add_option('-H', '--host', metavar="ADDRESS", default="0.0.0.0", help="Address of heat API host. " "Default: %default") diff --git a/bin/heat-db-setup b/bin/heat-db-setup index 744df3630e..56f7165b1e 100755 --- a/bin/heat-db-setup +++ b/bin/heat-db-setup @@ -29,7 +29,7 @@ Options: --help | -h Print usage information. - --heatpw | -n + --password | -p Specify the password for the 'heat' MySQL user that will use to connect to the 'heat' MySQL database. By default, the password 'heat' will be used. @@ -66,11 +66,6 @@ MYSQL_HEAT_PW=${MYSQL_HEAT_PW_DEFAULT} HEAT_CONFIG="/etc/heat/heat-engine.conf" ASSUME_YES="" -if [ $# -eq 0 ] -then - usage -fi - case "$1" in rpm) echo "Installing on an RPM system." @@ -90,6 +85,9 @@ case "$1" in SERVICE_STATUS="service $SERVICE_MYSQLD status" SERVICE_ENABLE="" ;; + *) + usage + ;; esac while [ $# -gt 0 ] @@ -98,7 +96,7 @@ do -h|--help) usage ;; - -n|--novapw) + -p|--password) shift MYSQL_HEAT_PW=${1} ;; @@ -111,7 +109,6 @@ do ;; *) # ignore - shift ;; esac shift diff --git a/docs/GettingStarted.rst b/docs/GettingStarted.rst index 4d54736c2a..011bca2759 100644 --- a/docs/GettingStarted.rst +++ b/docs/GettingStarted.rst @@ -34,7 +34,7 @@ Installing OpenStack on Fedora 16 Note: on Fedora 16 you have to enable the `Preview Repository`_ to install the required OpenStack Essex release. A script called "``openstack``" in the tools directory of the repository will install and start OpenStack for you on Fedora 16/17:: - ./tools/openstack install + ./tools/openstack install -y -r ${MYSQL_ROOT_PASSWORD} If you use this method, you will need to manually create a guest network. How this is done depends on your environment. An example network create operation: @@ -90,9 +90,9 @@ Setup the MySQL database for Heat :: - ./bin/heat-db-setup rpm + heat-db-setup rpm -y -r ${MYSQL_ROOT_PASSWORD} -Note: the first argument is either ``rpm`` for RPM-based distros (such as Fedora) or ``deb`` for Debian-based distros (such as Ubuntu). +Note: the first argument is either ``rpm`` for RPM-based distros (such as Fedora) or ``deb`` for Debian-based distros (such as Ubuntu). To prompt for confirmation when e.g. installing MySQL Server, omit the ``-y`` option. Run ``heat-db-setup --help`` for detailed documentation. Register heat with keystone --------------------------- @@ -128,7 +128,7 @@ Create a JEOS :: - sudo -E heat jeos_create F16 x86_64 cfntools + sudo -E heat -y jeos_create F16 x86_64 cfntools Note: The ``-E`` option to ``sudo`` preserves the environment, specifically the keystone credentials, when ``jeos_create`` is run as root. diff --git a/heat/utils.py b/heat/utils.py index 0691d24128..1a8294b8af 100644 --- a/heat/utils.py +++ b/heat/utils.py @@ -178,7 +178,7 @@ def jeos_create(options, arguments, jeos_path, cfntools_path): if image['name'] == distro + '-' + arch + '-' + instance_type: image_registered = True - runoz = None + runoz = options.yes and 'y' or None if os.access(qcow2_filename, os.R_OK): while runoz not in ('y', 'n'): runoz = raw_input('An existing JEOS was found on disk.' \ diff --git a/tools/heat-db-drop b/tools/heat-db-drop index e472452ecc..e137e8ae5e 100755 --- a/tools/heat-db-drop +++ b/tools/heat-db-drop @@ -1,8 +1,26 @@ #!/bin/bash -cat << EOF | mysql -u root -p -DROP USER 'heat'@'localhost'; -DROP USER 'heat'@'%'; -DROP DATABASE heat; + +DATABASE=heat + +while [ $# -gt 0 ]; do + case $1 in + heat|nova|keystone|glance) + DATABASE=$1 + ;; + -r|--rootpw) + shift + MYSQL_ROOT_PW_ARG="--password=$1" + ;; + *) + ;; + esac + shift +done + +cat << EOF | mysql -u root ${MYSQL_ROOT_PW_ARG} +DROP USER '${DATABASE}'@'localhost'; +DROP USER '${DATABASE}'@'%'; +DROP DATABASE ${DATABASE}; flush privileges; EOF diff --git a/tools/openstack b/tools/openstack index 032dd2bccb..e205b6b7d1 100755 --- a/tools/openstack +++ b/tools/openstack @@ -7,6 +7,7 @@ # sleep 1 = systemd's definition of start is different from mine +BASE_DIR=`dirname $0` action=$1 if [ -z "$action" ] @@ -72,18 +73,9 @@ function os_erase() { sudo systemctl start mysqld.service sleep 1 -cat << EOF | mysql -u root -p -DROP USER 'nova'@'localhost'; -DROP USER 'nova'@'%'; -DROP USER 'keystone'@'localhost'; -DROP USER 'keystone'@'%'; -DROP USER 'glance'@'localhost'; -DROP USER 'glance'@'%'; -DROP DATABASE nova; -DROP DATABASE keystone; -DROP DATABASE glance; -flush privileges; -EOF + $BASE_DIR/heat-db-drop nova $* + $BASE_DIR/heat-db-drop keystone $* + $BASE_DIR/heat-db-drop glance $* sudo vgchange -an nova-volumes sudo losetup -d /dev/loop0 @@ -100,9 +92,9 @@ function os_install() { sudo systemctl start mysqld.service sleep 1 # Configure the databases - sudo openstack-nova-db-setup - sudo openstack-glance-db-setup - sudo openstack-keystone-db-setup + sudo openstack-nova-db-setup $* + sudo openstack-glance-db-setup $* + sudo openstack-keystone-db-setup $* # Create a keystone RC file mkdir -p $HOME/.openstack @@ -143,17 +135,18 @@ EOF os_start sleep 1 echo "Installation Complete." - echo "Testing nova and glance. If any errors are displayed, the install failed." + echo "Testing nova and glance. If any errors are displayed, the install failed..." nova flavor-list glance index + echo echo "note: This tool does not create a network. Creating a network" echo "depends on your environment. An example network create operation:" echo - echo "sudo nova-manage network create demonet 10.0.0.0/24 1 256 --bridge=demonetbr0" + echo " sudo nova-manage network create demonet 10.0.0.0/24 1 256 --bridge=demonetbr0" echo - echo "The network range here, should *not* be the one used on your existing physical network." - echo "It should be a range dedicated for the network that OpenStack will configure. So if" - echo "10.0.0.0/24 clashes with your local network, pick another range." + echo -e "The network range here should *not* be one used on your existing physical\n network." + echo "It should be a range dedicated for the network that OpenStack will configure." + echo "If 10.0.0.0/24 clashes with your local network, pick another range." } @@ -167,10 +160,12 @@ case $action in os_stop ;; erase) - os_erase + shift + os_erase $* ;; install) - os_install + shift + os_install $* ;; status) os_status diff --git a/tools/uninstall-heat b/tools/uninstall-heat index 3527ec85b6..fcc3cf3b81 100755 --- a/tools/uninstall-heat +++ b/tools/uninstall-heat @@ -1,8 +1,9 @@ #!/bin/bash TOOLS_DIR=`dirname $0` -if [ "$1" = "-y" ]; then +if [ "$1" = "-y" ] || [ "$1" = "--yes" ]; then SKIP_ASK=y + shift fi user_wants() { @@ -31,12 +32,12 @@ if [ -n "$HEAT_PIDS" ]; then fi if user_wants 'Drop Heat database tables?'; then - $TOOLS_DIR/heat-db-drop + $TOOLS_DIR/heat-db-drop $* echo 1>&2 fi if user_wants 'Erase OpenStack installation?'; then - $TOOLS_DIR/openstack erase + $TOOLS_DIR/openstack erase $* echo 1>&2 fi