summaryrefslogtreecommitdiffstats
path: root/utils/init_db.py
diff options
context:
space:
mode:
authorLeo Wang <grakiss.wanglei@huawei.com>2017-03-22 21:40:58 -0400
committerLeo Wang <grakiss.wanglei@huawei.com>2017-03-24 21:19:01 -0400
commit02d44a030687100d0ebf68d1645536536d42cbb9 (patch)
treeea9d6a1753823507939e760cda89b0bfd86bd3bd /utils/init_db.py
parentc731b93e24dca7641b174ee860f14beedc4de442 (diff)
Launch a local TESTAPI DB instance
JIRA: DOVETAIL-374 User may want to dry run the test, and does not intend to upload test results to OPNFV DB. So dovetail provide a way to launch a local TESTAPI DB instance, then user can upload test results to this local db, and browse test results locally. Change-Id: I17b6153c9a308bd3cd59a2450c415200496cb855 Signed-off-by: Leo Wang <grakiss.wanglei@huawei.com>
Diffstat (limited to 'utils/init_db.py')
-rw-r--r--utils/init_db.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/utils/init_db.py b/utils/init_db.py
new file mode 100644
index 00000000..129c61f8
--- /dev/null
+++ b/utils/init_db.py
@@ -0,0 +1,80 @@
+##############################################################################
+# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import requests
+import json
+import sys
+
+db_host_ip = sys.argv[1]
+testapi_port = sys.argv[2]
+
+source_url = 'http://testresults.opnfv.org/test/api/v1'
+target_url = 'http://{}:{}/api/v1'.format(db_host_ip, testapi_port)
+print(target_url)
+
+
+def get(url):
+ return requests.get(url).json()
+
+
+def post(url, data):
+ headers = {'Content-Type': 'application/json'}
+ res = requests.post(url, data=json.dumps(data), headers=headers)
+ print(res.text)
+
+
+def pod():
+ source = '{}/pods'.format(source_url)
+ target = '{}/pods'.format(target_url)
+
+ pods = get(source)['pods']
+ for p in pods:
+ post(target, p)
+
+ add_pod('master', 'metal')
+ add_pod('virtual_136_2', 'virtual')
+
+
+def project():
+ source = '{}/projects'.format(source_url)
+ target = '{}/projects'.format(target_url)
+
+ projects = get(source)['projects']
+ for p in projects:
+ post(target, p)
+
+
+def cases():
+ project_list = ['yardstick', 'functest', 'dovetail']
+
+ for p in project_list:
+ source = '{}/projects/{}/cases'.format(source_url, p)
+ target = '{}/projects/{}/cases'.format(target_url, p)
+
+ cases = get(source)['testcases']
+ for c in cases:
+ post(target, c)
+
+
+def add_pod(name, mode):
+ data = {
+ "role": "",
+ "name": name,
+ "details": '',
+ "mode": mode,
+ "creation_date": "2017-2-23 11:23:03.765581"
+ }
+ pod_url = '{}/pods'.format(target_url)
+ post(pod_url, data)
+
+
+if __name__ == '__main__':
+ pod()
+ project()
+ cases()