-
Notifications
You must be signed in to change notification settings - Fork 21
/
run_test.py
91 lines (77 loc) · 2.88 KB
/
run_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import sys
import argparse
import subprocess
file_path = os.path.abspath(__file__)
storages = ['local', 'ceph']
conf_dir = os.path.join(os.path.dirname(file_path), 'test', 'functional', 'data')
def prepare(storage, env):
""" migrate data and set env after migrate data.
"""
if storage == 'ceph':
if 'seafobj' not in os.environ.get('PYTHONPATH', ''):
sys.stdout.write('please set env first. \n')
sys.exit(0)
args = ['python', 'test/seafobj_migrate.py']
subprocess.check_call(args, env=env)
with open(os.path.join(conf_dir, 'ceph', 'seafile.conf')) as fr:
with open(os.path.join(conf_dir, 'seafile.conf'), 'w') as fw:
fw.write(fr.read())
if storage == 'multi':
with open(os.path.join(conf_dir, 'multi-backend', 'seafile.conf')) as fr:
with open(os.path.join(conf_dir, 'seafile.conf'), 'w') as fw:
fw.write(fr.read())
os.environ['SEAFILE_CONF_DIR'] = os.path.join(conf_dir)
os.environ['CCNET_CONF_DIR'] = ''
def clear():
""" clear seafile.conf content
"""
with open(os.path.join(conf_dir, 'seafile.conf'), 'r+') as fw:
fw.truncate()
#os.remove(os.path.join(conf_dir, 'seafile.ini'))
def set_env(storage):
""" set env for migrate and run local file system test
"""
os.environ['CCNET_CONF_DIR'] = ''
os.environ['SEAFILE_CONF_DIR'] = conf_dir
if storage == 'fs':
os.environ['CEPH_SEAFILE_CENTRAL_CONF_DIR'] = ''
elif storage == 'ceph':
os.environ['CEPH_SEAFILE_CENTRAL_CONF_DIR'] = os.path.join(conf_dir, 'ceph')
#with open(os.path.join(conf_dir, 'seafile.ini'), 'w') as fd:
# fd.write(os.path.join(conf_dir, 'storage'))
prepare(storage, os.environ)
return os.environ
def run(storage):
if storage == 'all':
for storage in storages:
env = set_env(storage)
msg = 'Start the standard %s filesystem test.' % storage
print(msg.center(180))
#args = ['pytest', '--ignore=test/functional/crypto_test.py','-sv', 'test']
args = ['pytest', '-sv', 'test']
try:
subprocess.check_call(args, env=env)
except:
pass
clear()
else:
env = set_env(storage)
#args = ['pytest', '--ignore=test/functional/crypto_test.py','-sv', 'test']
args = ['pytest', '-sv', 'test']
try:
subprocess.check_call(args, env=env)
except:
pass
clear()
def main():
parser = argparse.ArgumentParser(
description='seafevents main program')
parser.add_argument('--storage', help='backend storeage of file system')
args = parser.parse_args()
storage = 'fs'
if args.storage and args.storage in ['fs', 'ceph', 'all', 'multi']:
storage = args.storage
run(storage)
if __name__ == '__main__':
main()