118 lines
3.5 KiB
Plaintext
118 lines
3.5 KiB
Plaintext
%__mysql_test_run_dir /tmp/mysql
|
|
%__mysql_test_user dbuser
|
|
%__mysql_test_pass dbuserpass
|
|
%__mysql_test_cconf abuild-myclient.cnf
|
|
%__mysql_test_port 63306
|
|
%__mysql_test_db testdb
|
|
|
|
#
|
|
# macro: mysql_testserver_start -- start a test mysqld instance
|
|
#
|
|
# usage: %mysql_test_start -u <db_user> -p <db_user_password> -t <port> -d <db_names>
|
|
#
|
|
# db_user: user of the database (not admin of the server)
|
|
# db_user_password: his password
|
|
# db_names: name or names separated by semicolon (e. g. testhat or test1:test2)
|
|
#
|
|
|
|
%mysql_testserver_start(u:p:t:d:) \
|
|
TEST_RUN_DIR=%{__mysql_test_run_dir} \
|
|
TEST_USER="%{-u:%{-u*}}" \
|
|
if [ -z "$TEST_USER" ]; then \
|
|
TEST_USER='%{__mysql_test_user}' \
|
|
fi \
|
|
TEST_PASS="%{-p:%{-p*}}" \
|
|
if [ -z "$TEST_PASS" ]; then \
|
|
TEST_PASS='%{__mysql_test_pass}' \
|
|
fi \
|
|
TEST_PORT="%{-t:%{-t*}}" \
|
|
if [ -z "$TEST_PORT" ]; then \
|
|
TEST_PORT='%{__mysql_test_port}' \
|
|
fi \
|
|
TEST_DB="%{-d:%{-d*}}" \
|
|
if [ -z "$TEST_DB" ]; then \
|
|
TEST_DB='%{__mysql_test_db}' \
|
|
fi \
|
|
\
|
|
[ -d $TEST_RUN_DIR ] && rm -r $TEST_RUN_DIR \
|
|
mkdir -p $TEST_RUN_DIR/datadir{,-private} \
|
|
\
|
|
cat << EOF > $TEST_RUN_DIR/my.cnf \
|
|
[client] \
|
|
socket = $TEST_RUN_DIR/mysql.sock \
|
|
port = $TEST_PORT \
|
|
[mysqld] \
|
|
user = abuild \
|
|
log-error = $TEST_RUN_DIR/mysqld.log \
|
|
secure_file_priv = $TEST_RUN_DIR/datadir-private \
|
|
datadir = $TEST_RUN_DIR/datadir \
|
|
server-id = 1 \
|
|
socket = $TEST_RUN_DIR/mysql.sock \
|
|
port = $TEST_PORT \
|
|
sql_mode = '' \
|
|
EOF\
|
|
\
|
|
echo '>>> Initializing databases' \
|
|
mysql_install_db --defaults-file=$TEST_RUN_DIR/my.cnf \
|
|
\
|
|
echo '>>> Invoking mysqld' \
|
|
/usr/sbin/mysqld --defaults-file=$TEST_RUN_DIR/my.cnf& \
|
|
sleep 2 \
|
|
\
|
|
echo ">>> Creating \'$TEST_DB\' database, (credentials: $TEST_USER, $TEST_PASS)" \
|
|
mysqladmin --defaults-file=$TEST_RUN_DIR/my.cnf --user=abuild password abuildpw \
|
|
for db in `echo $TEST_DB | tr ':' ' '`; do \
|
|
mysqladmin --defaults-file=$TEST_RUN_DIR/my.cnf --user=abuild --password=abuildpw create $db \
|
|
done \
|
|
cat << EOF > $TEST_RUN_DIR/create_auth.sql \
|
|
CREATE USER '$TEST_USER'@'localhost' IDENTIFIED BY '$TEST_PASS'; \
|
|
GRANT ALL PRIVILEGES ON * . * TO '$TEST_USER'@'localhost'; \
|
|
FLUSH PRIVILEGES; \
|
|
EOF\
|
|
mysql --defaults-file=$TEST_RUN_DIR/my.cnf --user=abuild --password=abuildpw < $TEST_RUN_DIR/create_auth.sql \
|
|
%nil
|
|
|
|
#
|
|
# macro: mysql_testserver_cconf -- generate client access conf
|
|
#
|
|
# usage: %mysql_testserver_cconf -n <filename> -d <dbname>
|
|
#
|
|
# filename: filename of the configuration
|
|
# dbname: database name (only one, not multiple as in %mysql_testserver_start)
|
|
|
|
%mysql_testserver_cconf(n:d:) \
|
|
TEST_RUN_DIR=%{__mysql_test_run_dir} \
|
|
TEST_CCONF="%{-n:%{-n*}}" \
|
|
if [ -z "$TEST_CCONF" ]; then \
|
|
TEST_CCONF='%{__mysql_test_cconf}' \
|
|
fi \
|
|
TEST_DB="%{-d:%{-d*}}" \
|
|
if [ -z "$TEST_DB" ]; then \
|
|
TEST_DB='%{__mysql_test_db}' \
|
|
fi \
|
|
cat << EOF > $TEST_CCONF \
|
|
[client] \
|
|
user = $TEST_USER \
|
|
password = $TEST_PASS \
|
|
database = $TEST_DB \
|
|
socket = $TEST_RUN_DIR/mysql.sock \
|
|
port = $TEST_PORT \
|
|
EOF\
|
|
%nil
|
|
|
|
#
|
|
# macro: mysql_testserver_stop -- start a test mysqld instance
|
|
#
|
|
# usage: %mysql_test_stop
|
|
#
|
|
|
|
%mysql_testserver_stop() \
|
|
TEST_RUN_DIR=%{__mysql_test_run_dir} \
|
|
echo '>>> Shutting the mysql server down' \
|
|
cat << EOF > $TEST_RUN_DIR/shutdown.sql \
|
|
SHUTDOWN; \
|
|
EOF\
|
|
mysql --defaults-file=$TEST_RUN_DIR/my.cnf --user=abuild --password=abuildpw < $TEST_RUN_DIR/shutdown.sql \
|
|
%nil
|
|
|