2 ##############################################################################
3 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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'''
12 from elasticsearch import Elasticsearch
15 import utils.logger as log
16 from utils.parser import Parser as conf_parser
18 LOG = log.Logger(__name__).getLogger()
19 config = ConfigParser.ConfigParser()
21 dashboard_path = os.path.join(conf_parser.test_dir,
24 dashboard_dir = dashboard_path + "/"
27 def dashboard_send_data(runner_config, test_data):
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"])
38 def posca_stress_ping(runner_config):
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')\
45 doc = json.load(index_pattern)
48 doc_type="index-pattern",
51 if res['created'] == "True":
52 LOG.info("bottlenecks index-pattern has created")
54 LOG.info("bottlenecks index-pattern has existed")
56 with open(dashboard_dir + 'posca_system_bandwidth_config.json')\
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")
63 LOG.info("bottlenecks config has existed")
65 # Configure discover panel
66 with open(dashboard_dir + 'posca_stress_ping_discover.json')\
68 doc = json.load(index_discover)
72 id="posca_stress_ping",
74 if res['created'] == "True":
75 LOG.info("posca_stress_ping search has created")
77 LOG.info("posca_stress_ping search has existed")
79 # Create testing data in line graph
80 with open(dashboard_dir + 'posca_stress_ping_histogram.json')\
82 doc = json.load(line_data)
85 doc_type="visualization",
86 id="posca_stress_ping_histogram",
88 if res['created'] == "True":
89 LOG.info("posca_stress_ping visualization has created")
91 LOG.info("posca_stress_ping visualization has existed")
93 # Create comparison results in line chart
94 with open(dashboard_dir + 'posca_stress_ping_table.json')\
96 doc = json.load(line_char)
99 doc_type="visualization",
100 id="posca_stress_ping_table",
102 if res['created'] == "True":
103 LOG.info("posca_stress_ping visualization has created")
105 LOG.info("posca_stress_ping visualization has existed")
108 with open(dashboard_dir + 'posca_stress_ping_dashboard.json')\
110 doc = json.load(dashboard)
113 doc_type="dashboard",
114 id="posca_stress_ping",
116 if res['created'] == "True":
117 LOG.info("posca_stress_ping dashboard has created")
119 LOG.info("posca_stress_ping dashboard has existed")