forked from NVIDIA/proxyfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregression_test.py
executable file
·301 lines (248 loc) · 9.84 KB
/
regression_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/usr/bin/env python
"""
A script to lint and test ProxyFS project code.
"""
from __future__ import print_function, unicode_literals
from threading import Timer
import os
import argparse
import functools
import logging
import platform
import contextlib
import subprocess
import shutil
import sys
import tempfile
import time
PACKAGES = ["blunder",
"cleanproxyfs",
"conf",
"dlm",
"fs",
"fsworkout",
"fuse",
"headhunter",
"httpserver",
"inode",
"inodeworkout",
"jrpcfs",
"logger",
"mkproxyfs", "mkproxyfs/mkproxyfs",
"pfs-stress",
"pfsconfjson", "pfsconfjsonpacked",
"pfsworkout",
"platform",
"proxyfsd", "proxyfsd/proxyfsd",
"ramswift", "ramswift/ramswift",
"stats",
"statslogger",
"swiftclient",
"utils"]
COLORS = {"bright red": '1;31', "bright green": '1;32'}
@contextlib.contextmanager
def return_to_wd():
curdir = os.getcwd()
try:
yield
finally:
os.chdir(curdir)
@contextlib.contextmanager
def self_cleaning_tempdir(*args, **kwargs):
our_tempdir = tempfile.mkdtemp(*args, **kwargs)
try:
yield our_tempdir
finally:
shutil.rmtree(our_tempdir, ignore_errors=True)
def proxyfs_binary_path(binary):
try:
gopath = os.environ["GOPATH"]
except KeyError:
color_print("$GOPATH must be set", 'bright red')
os.exit(1)
return os.path.join(gopath, "bin", binary)
def color_print(content, color=None):
print("\x1b[{color}m{content}\x1b[0m".format(content=content,
color=COLORS[color]))
def proxyfs_package_path(package):
try:
gopath = os.environ["GOPATH"]
except KeyError:
color_print("$GOPATH must be set", 'bright red')
os.exit(1)
return os.path.join(gopath, "src/github.com/swiftstack/ProxyFS", package)
def color_print(content, color=None):
print("\x1b[{color}m{content}\x1b[0m".format(content=content,
color=COLORS[color]))
def report(task, success=False):
printer = color_print if sys.stdout.isatty() else lambda *a, **kw: print(*a)
if success:
printer("{} {}".format(task, "succeeded!"), color="bright green")
else:
printer("{} {}".format(task, "failed!"), color="bright red")
class GoCommand(object):
def __init__(self, command, project_path,
options=None, report_as=None, skip=False):
self.command = command
self.project_path = project_path
self.options = options or []
self.report_as = report_as
self.skip = skip
def execute(self, package):
if self.skip:
return None
package_path = "{}{}".format(self.project_path, package)
command_line = ["go", self.command] + self.options + [package_path]
logging.info(' '.join("'{}'".format(s) if ' ' in s else s
for s in command_line))
success = not bool(subprocess.call(command_line))
return success
def get_go_commands(options, project_path, skip_tests=False):
commands = [
GoCommand('fmt', project_path),
GoCommand('get', project_path, ['-t', '-u'], skip=not options.get),
# Source code has to be `go install`ed before `stringer` can run on
# it, so we install before generate, which mysteriously does work?
# see https://github.com/golang/go/issues/10249
GoCommand('install', project_path, ['-gcflags', '-N -l'], report_as="`go install`"),
GoCommand('generate', project_path, report_as="`go generate`"),
]
if not options.deb_builder:
commands.append(
GoCommand('test', project_path,
filter(lambda x: x, [options.bench, options.cover]),
report_as="`go test`",
skip=skip_tests)
)
commands.append(GoCommand('vet', project_path, report_as="`go vet`"))
return commands
def execute_go_commands(commands, packages):
reports = []
failures = 0
for command in commands:
successes = filter(lambda success: success is not None,
[command.execute(package) for package in packages])
success = all(successes)
failures += not success
if command.report_as is not None:
reports.append(functools.partial(report, command.report_as,
success=success))
for reporter in reports:
reporter()
return failures
def test_pfs_middleware(options):
failures = 0
with return_to_wd():
proxyfs_dir = os.path.dirname(os.path.abspath(__file__))
pfs_middleware_dir = os.path.join(proxyfs_dir, "pfs_middleware")
os.chdir(pfs_middleware_dir)
failures += bool(subprocess.call((['python', 'setup.py', 'test'])))
report("test_pfs_middleware()", not failures)
return failures
def build_proxyfs(options):
commands = get_go_commands(options, "github.com/swiftstack/ProxyFS/")
if options.packages is None:
selected_packages = PACKAGES
else:
selected_packages = options.packages
return execute_go_commands(commands, selected_packages)
def build_dependencies(options):
failures = 0
proxyfs_dir = os.path.dirname(os.path.abspath(__file__))
stringer_path = 'golang.org/x/tools/cmd/stringer'
full_stringer_path = os.path.join(proxyfs_dir, "vendor", stringer_path)
print("Building " + stringer_path)
install_cmd = ("go", "install")
with return_to_wd():
os.chdir(full_stringer_path)
success = not(bool(subprocess.call(install_cmd)))
failures += not success
report("build_dependencies()", not failures)
return failures
def build_jrpcclient(options):
proxyfs_dir = os.path.dirname(os.path.abspath(__file__))
jrpcclient_dir = os.path.join(proxyfs_dir, "jrpcclient")
command = ['./regression_test.py']
if options.no_install:
command.append('--no-install')
if options.deb_builder:
command.append('--deb-builder')
if options.just_build_libs:
command.append('--just-build-libs')
return bool(subprocess.call(command, cwd=jrpcclient_dir))
def build_vfs(options):
proxyfs_dir = os.path.dirname(os.path.abspath(__file__))
vfs_dir = os.path.join(proxyfs_dir, "vfs")
failures = 0
clean_cmd = ('make', 'clean')
failures += bool(subprocess.call(clean_cmd, cwd=vfs_dir))
if failures:
return failures
failures += bool(subprocess.call('make', cwd=vfs_dir))
if failures:
return failures
distro = platform.linux_distribution()[0]
if not options.no_install:
if options.deb_builder:
if 'centos' in distro.lower():
install_cmd = ('make', 'installcentos')
else:
install_cmd = ('make', 'install')
else:
if 'centos' in distro.lower():
install_cmd = ('sudo', '-E', 'make', 'installcentos')
else:
install_cmd = ('sudo', '-E', 'make', 'install')
failures += bool(subprocess.call(install_cmd, cwd=vfs_dir))
return failures
def main(options):
failures = 0
if not options.just_libs and not options.just_build_libs:
go_version = subprocess.check_output((['go', 'version']))
color_print(go_version[:-1], "bright green")
if not options.quiet:
logging.basicConfig(format="%(message)s", level=logging.INFO)
failures += build_dependencies(options)
if failures:
return failures
failures += build_proxyfs(options)
if failures:
return failures
if platform.system() != "Darwin":
if not options.no_libs:
failures += build_jrpcclient(options)
if failures:
return failures
failures += build_vfs(options)
if failures:
return failures
return failures
if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(description=__doc__)
arg_parser.add_argument('--bench', '-bench',
action='store_const', const='-bench=.',
help="include benchmark measurements in test output")
arg_parser.add_argument('--cover', '-cover',
action='store_const', const='-cover',
help="include coverage statistics in test output")
arg_parser.add_argument('--get', '-get', action='store_true',
help="invoke `go get` to retrieve new dependencies")
arg_parser.add_argument('--packages', '-p', action='store', nargs='*',
help="specific packages to process")
arg_parser.add_argument('--no-install', action='store_true',
help="When building C libraries, do not attempt "
"to install resulting objects")
arg_parser.add_argument('--deb-builder', action='store_true',
help="Modify commands to run inside "
"swift-deb-builder")
arg_parser.add_argument('--quiet', '-q', action='store_true',
help="suppress printing of what commands are being run")
libs_group = arg_parser.add_mutually_exclusive_group()
libs_group.add_argument('--no-libs', action='store_true',
help="don't build C libraries or run C tests")
libs_group.add_argument('--just-build-libs', action='store_true',
help="only build C libraries")
libs_group.add_argument('--just-libs', action='store_true',
help="only build C libraries and run C tests")
options = arg_parser.parse_args()
exit(main(options))