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
|
#!/usr/bin/python3
# Copyright (C) 2018 Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import cProfile
import json
import os
import sys
import ick2
def new_project(i):
return {
'project': 'project-{}'.format(i),
'pipelines': [],
'parameters': {},
}
def main():
iters = int(sys.argv[1])
num_projects = int(sys.argv[2])
statedir = sys.argv[3]
os.mkdir(statedir)
state = ick2.FilePersistentState()
state.set_directory(statedir)
apis = {
'/builds': ick2.BuildsAPI,
'/logs': ick2.LogAPI,
'/pipelines': ick2.PipelineAPI,
'/projects': ick2.ProjectAPI,
'/workers': ick2.WorkerAPI,
}
for path in apis:
apis[path] = apis[path](state)
projects = [new_project(i) for i in range(num_projects)]
for i in range(iters):
for project in projects:
reqs = [
{
'method': 'POST',
'path': '/projects',
'body': project,
},
{
'method': 'PUT',
'path': '/projects/{}'.format(project['project']),
'body': project,
}
]
for req in reqs:
method = req['method']
path = req['path']
body = req.get('body')
if len(path.split('/')) == 2:
toplevel = path
name = None
else:
toplevel = os.path.dirname(path)
name = os.path.basename(path)
api = apis[toplevel]
try:
if method == 'POST':
api.create(body)
elif method == 'PUT':
api.update(body, name)
elif method == 'DELETE':
api.delete(body, name)
elif method == 'LIST':
api.list()
elif method == 'SHOW':
api.show(name)
else:
raise Exception('Unknown method: {}'.format(method))
except ick2.IckException:
pass
if __name__ == '__main__':
cProfile.run('main()', 'dummy.prof')
|