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):
30 es_ip = runner_config['dashboard_ip'].split(':')
31 es = Elasticsearch([{'host': es_ip[0]}])
32 print test_data["test_body"]
33 res = es.index(index="bottlenecks",
34 doc_type=test_data["testcase"],
35 body=test_data["test_body"][0])
36 if res['created'] == "False":
37 LOG.error("date send to kibana have errors ", test_data["data_body"])
40 def posca_moon_init(runner_config):
42 es_ip = runner_config['dashboard_ip'].split(':')
43 es = Elasticsearch([{'host': es_ip[0]}])
44 # Create bottlenecks index
45 with open(dashboard_dir + 'posca_feature_moon_index_pattern.json')\
47 doc = json.load(index_pattern)
50 doc_type="index-pattern",
53 if res['created'] == "True":
54 LOG.info("bottlenecks index-pattern has created")
56 LOG.info("bottlenecks index-pattern has existed")
58 with open(dashboard_dir + 'posca_system_bandwidth_config.json')\
60 doc = json.load(index_config)
61 res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc)
62 if res['created'] == "True":
63 LOG.info("bottlenecks config has created")
65 LOG.info("bottlenecks config has existed")
67 # Configure discover panel
68 with open(dashboard_dir + 'posca_feature_moon_discover.json')\
70 doc = json.load(index_discover)
76 if res['created'] == "True":
77 LOG.info("moon testcase search has created")
79 LOG.info("moon testcase search has existed")
81 # Create testing data in line graph
82 with open(dashboard_dir + 'posca_feature_moon_resources_histogram.json')\
84 doc = json.load(line_data)
87 doc_type="visualization",
90 if res['created'] == "True":
91 LOG.info("moon resources visualization has created")
93 LOG.info("moon resources visualization has existed")
95 # Create comparison results in line chart
96 with open(dashboard_dir + 'posca_feature_moon_tenants_histogram.json')\
98 doc = json.load(line_char)
101 doc_type="visualization",
104 if res['created'] == "True":
105 LOG.info("moon tenants visualization has created")
107 LOG.info("moon tenants visualization has existed")
110 with open(dashboard_dir + 'posca_feature_moon_dashboard.json')\
112 doc = json.load(dashboard)
115 doc_type="dashboard",
118 if res['created'] == "True":
119 LOG.info("moon testcases dashboard has created")
121 LOG.info("moon testcases dashboard has existed")