From 4fb355865a371c6c974e2c4151e468130c42784d Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Thu, 18 Jan 2018 11:09:21 +0800 Subject: [PATCH] tests: run with mysql + sqlite3 --- .travis.yml | 2 ++ ci/run.py | 9 ++++++--- ci/serverctl.py | 51 +++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59992b6..5c0298d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/ci/run.py b/ci/run.py index 9f5791a..b7039c9 100755 --- a/ci/run.py +++ b/ci/run.py @@ -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) diff --git a/ci/serverctl.py b/ci/serverctl.py index f7345a5..9170a4f 100755 --- a/ci/serverctl.py +++ b/ci/serverctl.py @@ -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)