-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathct_run.py
executable file
·94 lines (80 loc) · 2.51 KB
/
ct_run.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
92
93
94
#!/usr/bin/env python
"""Runs integration tests."""
import argparse
import os
import platform
import sys
script_dir = os.path.dirname(os.path.realpath(__file__))
helpers_dir = os.path.join(script_dir, 'helpers')
docker_dir = os.path.join(helpers_dir, 'bamboos', 'docker')
sys.path.insert(0, docker_dir)
from environment import docker
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Run Common Tests.')
parser.add_argument(
'--gdb',
action='store_true',
default=False,
help='run tests in GDB')
parser.add_argument(
'--image', '-i',
action='store',
default='onedata/builder:1802-1',
help='docker image to use as a test master',
dest='image')
parser.add_argument(
'--release',
action='store',
default='release',
help='release directory to run tests from',
dest='release')
parser.add_argument(
'--suite',
action='append',
default=[],
help='name of the test suite',
dest='suites')
[args, pass_args] = parser.parse_known_args()
script_dir = os.path.dirname(os.path.realpath(__file__))
base_test_dir = os.path.join(os.path.realpath(args.release), 'test',
'integration')
test_dirs = map(lambda suite: os.path.join(base_test_dir, suite), args.suites)
if not test_dirs:
test_dirs = [base_test_dir]
command = '''
import os, subprocess, sys, stat
if {shed_privileges}:
os.environ['HOME'] = '/tmp'
docker_gid = os.stat('/var/run/docker.sock').st_gid
os.chmod('/etc/resolv.conf', 0o666)
os.setgroups([docker_gid])
os.setregid({gid}, {gid})
os.setreuid({uid}, {uid})
if {gdb}:
command = ['gdb', 'python', '-silent', '-statistics', '-ex', """run -c "
import pytest
pytest.main({args} + ['{test_dirs}'])" """]
else:
command = ['py.test'] + {args} + ['{test_dirs}']
ret = subprocess.call(command)
sys.exit(ret)
'''
command = command.format(
args=pass_args,
uid=os.geteuid(),
gid=os.getegid(),
test_dirs="', '".join(test_dirs),
shed_privileges=(platform.system() == 'Linux'),
gdb=args.gdb)
ret = docker.run(tty=True,
rm=True,
interactive=True,
workdir=script_dir,
reflect=[(script_dir, 'rw'),
('/var/run/docker.sock', 'rw')],
image=args.image,
envs={'BASE_TEST_DIR': base_test_dir},
run_params=['--privileged'] if args.gdb else [],
command=['python', '-c', command])
sys.exit(ret)