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 ##############################################################################
11 from elasticsearch import Elasticsearch
12 from pyroute2 import IPDB
15 config = ConfigParser.ConfigParser()
17 dashboard_dir = "/home/opnfv/bottlenecks/testsuites/posca\
19 file_str = "/home/opnfv/bottlenecks/testsuites/posca/\
20 testcase_cfg/posca_factor_system_bandwidth.yaml"
22 with open(file_str, "rd") as cfgfile:
23 config.readfp(cfgfile)
24 ES_ip_a = config.get("config", "ES_ip")
27 GATEWAY_IP = ip.routes['default'].gateway
29 ES_ip_a = "{}:9200".format(GATEWAY_IP)
30 print("ES_ip is null get local ip is {}".format(ES_ip_a))
32 es_ip = ES_ip_a.split(':')
33 es = Elasticsearch([{'host': es_ip[0]}])
35 # Create bottlenecks index
36 with open(dashboard_dir + 'posca_system_bandwidth\
37 _index_pattern.json') as index_pattern:
38 doc = json.load(index_pattern)
41 doc_type="index-pattern",
44 if res['created'] == "True":
45 print("bottlenecks index-pattern has created")
47 print("bottlenecks index-pattern has existed")
49 with open(dashboard_dir + 'posca_system_bandwidth\
50 _config.json') as index_config:
51 doc = json.load(index_config)
52 res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc)
53 if res['created'] == "True":
54 print("bottlenecks config has created")
56 print("bottlenecks config has existed")
58 # Configure discover panel
59 with open(dashboard_dir + 'posca_system_bandwidth\
60 _discover.json') as index_discover:
61 doc = json.load(index_discover)
65 id="system_bandwidth",
67 if res['created'] == "True":
68 print("system_bandwidth search has created")
70 print("system_bandwidth search has existed")
72 # Create testing data in line graph
73 with open(dashboard_dir + 'posca_system_bandwidth\
74 _line_data.json') as line_data:
75 doc = json.load(line_data)
78 doc_type="visualization",
79 id="system_bandwidth_line-date",
81 if res['created'] == "True":
82 print("system_bandwidth_line-date visualization has created")
84 print("system_bandwidth_line-date visualization has existed")
86 # Create comparison results in line chart
87 with open(dashboard_dir + 'posca_system_bandwidth\
88 _line_char.json') as line_char:
89 doc = json.load(line_char)
92 doc_type="visualization",
93 id="system_bandwidth_line-char",
95 if res['created'] == "True":
96 print("system_bandwidth_line-char visualization has created")
98 print("system_bandwidth_line-char visualization has existed")
100 # Create monitoring data in table
101 with open(dashboard_dir + 'posca_system_bandwidth\
102 _terms_data.json') as terms_char:
103 doc = json.load(terms_char)
104 res = es.index(index=".kibana", doc_type="visualization",
105 id="system_bandwidth_terms_data", body=doc)
106 if res['created'] == "True":
107 print("system_bandwidth_terms_data visualization has created")
109 print("system_bandwidth_terms_data visualization has existed")
112 with open(dashboard_dir + 'posca_system_bandwidth\
113 _dashboard.json') as dashboard:
114 doc = json.load(dashboard)
117 doc_type="dashboard",
118 id="system_bandwidth_dashboard",
120 if res['created'] == "True":
121 print("system_bandwidth dashboard has created")
123 print("system_bandwidth dashboard has existed")