summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-07-24 19:19:44 +0300
committerLars Wirzenius <liw@liw.fi>2018-07-24 19:19:44 +0300
commitf828f6365e3b169fb6a01b0c474b334fdbcaf2e7 (patch)
tree8b0ee61c3757cafe4357bf998a0eae0f40f7beb5
parent7b9b4fc72b6d18cca36f9243172b55e288ba013b (diff)
downloadick2-f828f6365e3b169fb6a01b0c474b334fdbcaf2e7.tar.gz
Add: dummy controller for profiling
-rw-r--r--dummy_controller.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/dummy_controller.py b/dummy_controller.py
new file mode 100644
index 0000000..430a2c9
--- /dev/null
+++ b/dummy_controller.py
@@ -0,0 +1,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')