#!/bin/bash -x
wait_for_line () {
    while read line
    do
        echo "$line" | grep -q "$1" && break
    done < "$2"
    # Read the fifo for ever otherwise process would block
    cat "$2" >/dev/null &
}

# Start MySQL process for tests
MYSQL_DATA=`mktemp -d /tmp/gnocchi-mysql-XXXXX`
mkfifo ${MYSQL_DATA}/out
PATH=$PATH:/usr/libexec
mysqld --no-defaults --datadir=${MYSQL_DATA} --pid-file=${MYSQL_DATA}/mysql.pid --socket=${MYSQL_DATA}/mysql.socket --skip-networking --skip-grant-tables &> ${MYSQL_DATA}/out &
# Wait for MySQL to start listening to connections
wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out
export GNOCCHI_TEST_MYSQL_URL="mysql://root@localhost/test?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
mysql -S ${MYSQL_DATA}/mysql.socket -e 'CREATE DATABASE test;'

mkdir $MYSQL_DATA/tooz
export GNOCCHI_COORDINATION_URL="file:///$MYSQL_DATA/tooz"

$*

ret=$?
kill $(jobs -p)
rm -rf "${MYSQL_DATA}"
exit $ret

#!/bin/bash -x
wait_for_line () {
    while read line
    do
        echo "$line" | grep -q "$1" && break
    done < "$2"
    # Read the fifo for ever otherwise process would block
    cat "$2" >/dev/null &
}

# Start MySQL process for tests
MYSQL_DATA=`mktemp -d /tmp/gnocchi-mysql-XXXXX`
mkfifo ${MYSQL_DATA}/out
PATH=$PATH:/usr/libexec
mysqld --no-defaults --datadir=${MYSQL_DATA} --pid-file=${MYSQL_DATA}/mysql.pid --socket=${MYSQL_DATA}/mysql.socket --skip-networking --skip-grant-tables &> ${MYSQL_DATA}/out &
# Wait for MySQL to start listening to connections
wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out
export GNOCCHI_TEST_MYSQL_URL="mysql://root@localhost/test?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
mysql --no-defaults -S ${MYSQL_DATA}/mysql.socket -e 'CREATE DATABASE test;'

mkdir $MYSQL_DATA/tooz
export GNOCCHI_COORDINATION_URL="file:///$MYSQL_DATA/tooz"

$*

ret=$?
kill $(jobs -p)
rm -rf "${MYSQL_DATA}"
exit $ret

Use --no-defaults with mysql database creation
Use --no-defaults with mysql database creation

Otherwise configuration from an extant my.cnf can be used and
the database will be created in the primary mysql service, not
the one being used for tests.

Change-Id: I0f3b382fc2a348e1e857cfecb6cfa573b90d9a2d
