aboutsummaryrefslogtreecommitdiffstats
path: root/tools/docker/results/resultsdb/init_db.py
diff options
context:
space:
mode:
authorSridhar K. N. Rao <sridhar.rao@spirent.com>2019-06-11 12:53:58 +0530
committerSridhar K. N. Rao <sridhar.rao@spirent.com>2019-07-30 23:39:35 +0530
commitd691cc89e106d710f4d36bc3998501415588e2e1 (patch)
treefe05ef9977c2fd6a531ef3535ad11342037a48c3 /tools/docker/results/resultsdb/init_db.py
parent589639d313c24104b2a27ef16baf716d1d274108 (diff)
Docker: VSPERF Results Container.
This patch adds docker-compose.yml and related config files for creating a results container. The container hosts following services: 1. Barometer Grafana. 2. Barometer Influxdb. 2. ELK Stack. 3. OPNFV TestAPI. 4. Jupyter Notebook with VSPERF testresults-analysis. Removed dashboard files, which can be obtained from barometer-grafana. Added comment in tools.rst under pre-deployment Retained only vpserf-cases and vsperf in cases.json and projects.json Changed barometer-influxdb to influxdb:latest. Added README.md file. Added environment variable setting to disable token for jupyter JIRA: VSPERF-602 Change-Id: I37a1391a1f34f834ce0d46def75a9f3454e09772 Signed-off-by: Sridhar K. N. Rao <sridhar.rao@spirent.com>
Diffstat (limited to 'tools/docker/results/resultsdb/init_db.py')
-rw-r--r--tools/docker/results/resultsdb/init_db.py110
1 files changed, 110 insertions, 0 deletions
diff --git a/tools/docker/results/resultsdb/init_db.py b/tools/docker/results/resultsdb/init_db.py
new file mode 100644
index 00000000..40bb4ee2
--- /dev/null
+++ b/tools/docker/results/resultsdb/init_db.py
@@ -0,0 +1,110 @@
+##############################################################################
+# 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
+##############################################################################
+"""
+Preload the results database with testcases.
+"""
+
+from __future__ import print_function
+import json
+import sys
+import requests
+
+DB_HOST_IP = sys.argv[1]
+TESTAPI_PORT = sys.argv[2]
+
+TARGET_URL = 'http://{}:{}/api/v1'.format(DB_HOST_IP, TESTAPI_PORT)
+
+
+def get(url):
+ """
+ Get the http response.
+ """
+ return requests.get(url).json()
+
+
+def post(url, data):
+ """
+ Post HTTP request.
+ """
+ headers = {'Content-Type': 'application/json'}
+ res = requests.post(url, data=json.dumps(data), headers=headers)
+ print(res.text)
+
+
+def pod():
+ """
+ Get the PODs.
+ """
+ target = '{}/pods'.format(TARGET_URL)
+
+ with open('pods.json', 'r') as podref:
+ pods = json.load(podref)
+ for apod in pods:
+ post(target, apod)
+
+ add_pod('master', 'metal')
+ add_pod('virtual_136_2', 'virtual')
+
+
+def project():
+ """
+ Get the Projects
+ """
+ target = '{}/projects'.format(TARGET_URL)
+ with open('projects.json', 'r') as projref:
+ projects = json.load(projref)
+ for proj in projects:
+ post(target, proj)
+
+
+def cases():
+ """
+ Get the Cases
+ """
+ with open('cases.json', 'r') as caseref:
+ for line in caseref:
+ subcases = json.loads(line)
+ for cas in subcases["testcases"]:
+ target = '{}/projects/{}/cases'.format(TARGET_URL,
+ cas['project_name'])
+ post(target, cas)
+ add_case("functest", "tempest_custom")
+
+
+def add_pod(name, mode):
+ """
+ Add the Pods.
+ """
+ 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)
+
+
+def add_case(projectname, casename):
+ """
+ Add a testcase
+ """
+ data = {
+ "project_name": projectname,
+ "name": casename,
+ }
+ case_url = '{}/projects/{}/cases'.format(TARGET_URL, projectname)
+ post(case_url, data)
+
+
+if __name__ == '__main__':
+ pod()
+ project()
+ cases()