mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-07 02:10:05 +00:00
tests: run with mysql + sqlite3
This commit is contained in:
@@ -2,6 +2,8 @@ sudo: false
|
||||
# Must set language to python so we can install custom python pacakges in
|
||||
# docker-based travis builds
|
||||
language: python
|
||||
services:
|
||||
- mysql
|
||||
compiler:
|
||||
- gcc
|
||||
addons:
|
||||
|
@@ -16,7 +16,7 @@ from os.path import abspath, basename, exists, expanduser, join
|
||||
import requests
|
||||
import termcolor
|
||||
|
||||
from serverctl import MYSQL_ROOT_PASSWD, ServerCtl
|
||||
from serverctl import ServerCtl
|
||||
from utils import (
|
||||
cd, chdir, debug, green, info, lru_cache, mkdirs, on_travis, red,
|
||||
setup_logging, shell, warning
|
||||
@@ -177,8 +177,11 @@ def main():
|
||||
args = parse_args()
|
||||
if on_travis() and not args.test_only:
|
||||
fetch_and_build()
|
||||
# for db in ('sqlite3', 'mysql'):
|
||||
for db in ('sqlite3', ):
|
||||
if on_travis():
|
||||
dbs = ('sqlite3', 'mysql')
|
||||
else:
|
||||
dbs = ('sqlite3',)
|
||||
for db in dbs:
|
||||
shell('rm -rf {}/*'.format(INSTALLDIR))
|
||||
start_and_test_with_db(db)
|
||||
|
||||
|
@@ -20,8 +20,6 @@ from utils import (
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MYSQL_ROOT_PASSWD = 's123'
|
||||
|
||||
|
||||
class ServerCtl(object):
|
||||
def __init__(self, datadir, db='sqlite3'):
|
||||
@@ -59,6 +57,24 @@ class ServerCtl(object):
|
||||
'test.seafile.com',
|
||||
]
|
||||
shell(cmd)
|
||||
if self.db == 'mysql':
|
||||
self.add_ccnet_db_conf()
|
||||
|
||||
def add_ccnet_db_conf(self):
|
||||
ccnet_conf = join(self.central_conf_dir, 'ccnet.conf')
|
||||
ccnet_db_conf = '''\
|
||||
[Database]
|
||||
ENGINE = mysql
|
||||
HOST = 127.0.0.1
|
||||
PORT = 3306
|
||||
USER = seafile
|
||||
PASSWD = seafile
|
||||
DB = ccnet
|
||||
CONNECTION_CHARSET = utf8
|
||||
'''
|
||||
with open(ccnet_conf, 'a+') as fp:
|
||||
fp.write('\n')
|
||||
fp.write(ccnet_db_conf)
|
||||
|
||||
def init_seafile(self):
|
||||
cmd = [
|
||||
@@ -72,6 +88,24 @@ class ServerCtl(object):
|
||||
]
|
||||
|
||||
shell(cmd)
|
||||
if self.db == 'mysql':
|
||||
self.add_seafile_db_conf()
|
||||
|
||||
def add_seafile_db_conf(self):
|
||||
seafile_conf = join(self.central_conf_dir, 'seafile.conf')
|
||||
seafile_db_conf = '''\
|
||||
[database]
|
||||
type = mysql
|
||||
host = 127.0.0.1
|
||||
port = 3306
|
||||
user = seafile
|
||||
password = seafile
|
||||
db_name = seafile
|
||||
connection_charset = utf8
|
||||
'''
|
||||
with open(seafile_conf, 'a+') as fp:
|
||||
fp.write('\n')
|
||||
fp.write(seafile_db_conf)
|
||||
|
||||
@contextmanager
|
||||
def run(self):
|
||||
@@ -146,17 +180,14 @@ class ServerCtl(object):
|
||||
|
||||
|
||||
def create_mysql_dbs():
|
||||
shell('mysqladmin -u root password %s' % MYSQL_ROOT_PASSWD)
|
||||
sql = '''\
|
||||
create database `ccnet-existing` character set = 'utf8';
|
||||
create database `seafile-existing` character set = 'utf8';
|
||||
create database `seahub-existing` character set = 'utf8';
|
||||
create database `ccnet` character set = 'utf8';
|
||||
create database `seafile` character set = 'utf8';
|
||||
|
||||
create user 'seafile'@'localhost' identified by 'seafile';
|
||||
|
||||
GRANT ALL PRIVILEGES ON `ccnet-existing`.* to `seafile`@localhost;
|
||||
GRANT ALL PRIVILEGES ON `seafile-existing`.* to `seafile`@localhost;
|
||||
GRANT ALL PRIVILEGES ON `seahub-existing`.* to `seafile`@localhost;
|
||||
GRANT ALL PRIVILEGES ON `ccnet`.* to `seafile`@localhost;
|
||||
GRANT ALL PRIVILEGES ON `seafile`.* to `seafile`@localhost;
|
||||
'''
|
||||
|
||||
shell('mysql -u root -p%s' % MYSQL_ROOT_PASSWD, inputdata=sql)
|
||||
shell('mysql -u root', inputdata=sql)
|
||||
|
Reference in New Issue
Block a user