Change path to reporting db
[bottlenecks.git] / testsuites / posca / testcase_dashboard / system_bandwidth.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 import ConfigParser
11 from elasticsearch import Elasticsearch
12 import json
13 import os
14 import utils.logger as log
15 from utils.parser import Parser as conf_parser
16
17 LOG = log.Logger(__name__).getLogger()
18 config = ConfigParser.ConfigParser()
19 es = Elasticsearch()
20 dashboard_path = os.path.join(conf_parser.test_dir,
21                               "posca",
22                               "testcase_dashboard")
23 dashboard_dir = dashboard_path + "/"
24
25
26 def dashboard_send_data(runner_config, test_data):
27     global es
28     es_ip = runner_config['dashboard_ip'].split(':')
29     es = Elasticsearch([{'host': es_ip[0]}])
30     res = es.index(index="bottlenecks",
31                    doc_type=test_data["testcase"],
32                    body=test_data["data_body"])
33     if res['created'] == "False":
34         LOG.error("date send to kibana have errors ", test_data["data_body"])
35
36
37 def dashboard_system_bandwidth(runner_config):
38     global es
39     es_ip = runner_config['dashboard_ip'].split(':')
40     es = Elasticsearch([{'host': es_ip[0]}])
41     # Create bottlenecks index
42     with open(dashboard_dir + 'posca_system_bandwidth_index_pattern.json')\
43             as index_pattern:
44         doc = json.load(index_pattern)
45     res = es.index(
46         index=".kibana",
47         doc_type="index-pattern",
48         id="bottlenecks",
49         body=doc)
50     if res['created'] == "True":
51         LOG.info("bottlenecks index-pattern has created")
52     else:
53         LOG.info("bottlenecks index-pattern has existed")
54
55     with open(dashboard_dir + 'posca_system_bandwidth_config.json')\
56             as index_config:
57         doc = json.load(index_config)
58     res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc)
59     if res['created'] == "True":
60         LOG.info("bottlenecks config has created")
61     else:
62         LOG.info("bottlenecks config has existed")
63
64     # Configure discover panel
65     with open(dashboard_dir + 'posca_system_bandwidth_discover.json')\
66             as index_discover:
67         doc = json.load(index_discover)
68     res = es.index(
69         index=".kibana",
70         doc_type="search",
71         id="system_bandwidth",
72         body=doc)
73     if res['created'] == "True":
74         LOG.info("system_bandwidth search has created")
75     else:
76         LOG.info("system_bandwidth search has existed")
77
78     # Create testing data in line graph
79     # Create testing data in line graph
80     with open(dashboard_dir + 'posca_system_bandwidth_line_data.json')\
81             as line_data:
82         doc = json.load(line_data)
83     res = es.index(
84         index=".kibana",
85         doc_type="visualization",
86         id="system_bandwidth_line-date",
87         body=doc)
88     if res['created'] == "True":
89         LOG.info("system_bandwidth_line-date visualization has created")
90     else:
91         LOG.info("system_bandwidth_line-date visualization has existed")
92
93     # Create comparison results in line chart
94     with open(dashboard_dir + 'posca_system_bandwidth_line_char.json')\
95             as line_char:
96         doc = json.load(line_char)
97     res = es.index(
98         index=".kibana",
99         doc_type="visualization",
100         id="system_bandwidth_line-char",
101         body=doc)
102     if res['created'] == "True":
103         LOG.info("system_bandwidth_line-char visualization has created")
104     else:
105         LOG.info("system_bandwidth_line-char visualization has existed")
106
107     # Create monitoring data in table
108     with open(dashboard_dir + 'posca_system_bandwidth_terms_data.json')\
109             as terms_char:
110         doc = json.load(terms_char)
111     res = es.index(index=".kibana", doc_type="visualization",
112                    id="system_bandwidth_terms_data", body=doc)
113     if res['created'] == "True":
114         LOG.info("system_bandwidth_terms_data visualization has created")
115     else:
116         LOG.info("system_bandwidth_terms_data visualization has existed")
117
118     # Create dashboard
119     with open(dashboard_dir + 'posca_system_bandwidth_dashboard.json')\
120             as dashboard:
121         doc = json.load(dashboard)
122     res = es.index(
123         index=".kibana",
124         doc_type="dashboard",
125         id="system_bandwidth_dashboard",
126         body=doc)
127     if res['created'] == "True":
128         LOG.info("system_bandwidth dashboard has created")
129     else:
130         LOG.info("system_bandwidth dashboard has existed")