From 142430fb75f65f6535650a9cd3020b1147979466 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Wed, 23 Jun 2021 10:37:02 -0400 Subject: [PATCH] Add database connection for zuul Depends-On: https://review.opendev.org/c/windmill/windmill/+/797662/ Change-Id: I3114291dabca7562127b59d857357e289b8e53e3 Signed-off-by: Paul Belanger --- bindep.txt | 2 ++ tools/test-setup.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ zuul/zuul.conf.j2 | 4 ++++ 3 files changed, 50 insertions(+) create mode 100755 tools/test-setup.sh diff --git a/bindep.txt b/bindep.txt index e9d825b..05c2341 100644 --- a/bindep.txt +++ b/bindep.txt @@ -6,6 +6,8 @@ libffi-devel [platform:rpm] libffi-dev [platform:dpkg] libselinux-python [platform:rpm] libssl-dev [platform:dpkg] +mysql-client [test !platform:rpm] +mysql-server [test] openssl-devel [platform:rpm] python3-dnf [platform:fedora] python3-devel [platform:rpm] diff --git a/tools/test-setup.sh b/tools/test-setup.sh new file mode 100755 index 0000000..241ee37 --- /dev/null +++ b/tools/test-setup.sh @@ -0,0 +1,44 @@ +#!/bin/bash -ex +# Copyright 2018 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. + +# Be sure mysql is started. +sudo service mysql start + +# The root password for the MySQL database; pass it in via +# MYSQL_ROOT_PW. +DB_ROOT_PW=${MYSQL_ROOT_PW:-insecure_worker} + +# This user and its password are used by the tests, if you change it, +# your tests might fail. +DB_USER=openstack_citest +DB_PW=openstack_citest + +sudo -H mysqladmin -u root password $DB_ROOT_PW + +# It's best practice to remove anonymous users from the database. If +# a anonymous user exists, then it matches first for connections and +# other connections from that host will not work. +sudo -H mysql -u root -p$DB_ROOT_PW -h localhost -e " + DELETE FROM mysql.user WHERE User=''; + FLUSH PRIVILEGES; + CREATE USER '$DB_USER'@'%' IDENTIFIED BY '$DB_PW'; + GRANT ALL PRIVILEGES ON *.* TO '$DB_USER'@'%' WITH GRANT OPTION;" + +# Now create our database. +mysql -u $DB_USER -p$DB_PW -h 127.0.0.1 -e " + SET default_storage_engine=MYISAM; + DROP DATABASE IF EXISTS openstack_citest; + CREATE DATABASE openstack_citest CHARACTER SET utf8;" diff --git a/zuul/zuul.conf.j2 b/zuul/zuul.conf.j2 index 3aeb0cc..2c7dd26 100644 --- a/zuul/zuul.conf.j2 +++ b/zuul/zuul.conf.j2 @@ -57,3 +57,7 @@ driver = gerrit server = 127.0.0.1 sshkey = {{ zuul_user_home }}/.ssh/gerrit_id_rsa user = windmill + +[connection database] +driver = sql +dburi = mysql+pymysql://openstack_citest:openstack_citest@localhost/openstack_citest