stress_test_dashboard_code
[bottlenecks.git] / testsuites / posca / testcase_dashboard / posca_stress_ping.py
1 #!/usr/bin/python
2 ##############################################################################
3 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 '''This file realize a function of creating dashboard of stress ping test'''
11 import ConfigParser
12 from elasticsearch import Elasticsearch
13 import json
14 import os
15 import utils.logger as log
16 from utils.parser import Parser as conf_parser
17
18 LOG = log.Logger(__name__).getLogger()
19 config = ConfigParser.ConfigParser()
20 es = Elasticsearch()
21 dashboard_path = os.path.join(conf_parser.test_dir,
22                               "posca",
23                               "testcase_dashboard")
24 dashboard_dir = dashboard_path + "/"
25
26
27 def dashboard_send_data(runner_config, test_data):
28     global es
29     es_ip = runner_config['dashboard_ip'].split(':')
30     es = Elasticsearch([{'host': es_ip[0]}])
31     res = es.index(index="bottlenecks",
32                    doc_type=test_data["testcase"],
33                    body=test_data["data_body"])
34     if res['created'] == "False":
35         LOG.error("date send to kibana have errors ", test_data["data_body"])
36
37
38 def posca_stress_ping(runner_config):
39     global es
40     es_ip = runner_config['dashboard_ip'].split(':')
41     es = Elasticsearch([{'host': es_ip[0]}])
42     # Create bottlenecks index
43     with open(dashboard_dir + 'posca_stress_ping_index_pattern.json')\
44             as index_pattern:
45         doc = json.load(index_pattern)
46     res = es.index(
47         index=".kibana",
48         doc_type="index-pattern",
49         id="bottlenecks",
50         body=doc)
51     if res['created'] == "True":
52         LOG.info("bottlenecks index-pattern has created")
53     else:
54         LOG.info("bottlenecks index-pattern has existed")
55
56     with open(dashboard_dir + 'posca_system_bandwidth_config.json')\
57             as index_config:
58         doc = json.load(index_config)
59     res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc)
60     if res['created'] == "True":
61         LOG.info("bottlenecks config has created")
62     else:
63         LOG.info("bottlenecks config has existed")
64
65     # Configure discover panel
66     with open(dashboard_dir + 'posca_stress_ping_discover.json')\
67             as index_discover:
68         doc = json.load(index_discover)
69     res = es.index(
70         index=".kibana",
71         doc_type="search",
72         id="posca_stress_ping",
73         body=doc)
74     if res['created'] == "True":
75         LOG.info("posca_stress_ping search has created")
76     else:
77         LOG.info("posca_stress_ping search has existed")
78
79     # Create testing data in line graph
80     with open(dashboard_dir + 'posca_stress_ping_histogram.json')\
81             as line_data:
82         doc = json.load(line_data)
83     res = es.index(
84         index=".kibana",
85         doc_type="visualization",
86         id="posca_stress_ping_histogram",
87         body=doc)
88     if res['created'] == "True":
89         LOG.info("posca_stress_ping visualization has created")
90     else:
91         LOG.info("posca_stress_ping visualization has existed")
92
93     # Create comparison results in line chart
94     with open(dashboard_dir + 'posca_stress_ping_table.json')\
95             as line_char:
96         doc = json.load(line_char)
97     res = es.index(
98         index=".kibana",
99         doc_type="visualization",
100         id="posca_stress_ping_table",
101         body=doc)
102     if res['created'] == "True":
103         LOG.info("posca_stress_ping visualization has created")
104     else:
105         LOG.info("posca_stress_ping visualization has existed")
106
107     # Create dashboard
108     with open(dashboard_dir + 'posca_stress_ping_dashboard.json')\
109             as dashboard:
110         doc = json.load(dashboard)
111     res = es.index(
112         index=".kibana",
113         doc_type="dashboard",
114         id="posca_stress_ping",
115         body=doc)
116     if res['created'] == "True":
117         LOG.info("posca_stress_ping dashboard has created")
118     else:
119         LOG.info("posca_stress_ping dashboard has existed")