63671273db55ba591cb830015a0337676a0f8c13
[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 from pyroute2 import IPDB
13 import json
14
15 config = ConfigParser.ConfigParser()
16
17 dashboard_dir = "/home/opnfv/bottlenecks/testsuites/posca\
18 /testcase_dashboard/"
19 file_str = "/home/opnfv/bottlenecks/testsuites/posca/\
20 testcase_cfg/posca_factor_system_bandwidth.yaml"
21
22 with open(file_str, "rd") as cfgfile:
23     config.readfp(cfgfile)
24     ES_ip_a = config.get("config", "ES_ip")
25
26 with IPDB() as ip:
27     GATEWAY_IP = ip.routes['default'].gateway
28     if ES_ip_a is "":
29         ES_ip_a = "{}:9200".format(GATEWAY_IP)
30         print("ES_ip is null get local ip is {}".format(ES_ip_a))
31
32 es_ip = ES_ip_a.split(':')
33 es = Elasticsearch([{'host': es_ip[0]}])
34
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)
39 res = es.index(
40     index=".kibana",
41     doc_type="index-pattern",
42     id="bottlenecks",
43     body=doc)
44 if res['created'] == "True":
45     print("bottlenecks index-pattern has created")
46 else:
47     print("bottlenecks index-pattern has existed")
48
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")
55 else:
56     print("bottlenecks config has existed")
57
58 # Configure discover panel
59 with open(dashboard_dir + 'posca_system_bandwidth\
60 _discover.json') as index_discover:
61     doc = json.load(index_discover)
62 res = es.index(
63     index=".kibana",
64     doc_type="search",
65     id="system_bandwidth",
66     body=doc)
67 if res['created'] == "True":
68     print("system_bandwidth search has created")
69 else:
70     print("system_bandwidth search has existed")
71
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)
76 res = es.index(
77     index=".kibana",
78     doc_type="visualization",
79     id="system_bandwidth_line-date",
80     body=doc)
81 if res['created'] == "True":
82     print("system_bandwidth_line-date visualization has created")
83 else:
84     print("system_bandwidth_line-date visualization has existed")
85
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)
90 res = es.index(
91     index=".kibana",
92     doc_type="visualization",
93     id="system_bandwidth_line-char",
94     body=doc)
95 if res['created'] == "True":
96     print("system_bandwidth_line-char visualization has created")
97 else:
98     print("system_bandwidth_line-char visualization has existed")
99
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")
108 else:
109     print("system_bandwidth_terms_data visualization has existed")
110
111 # Create dashboard
112 with open(dashboard_dir + 'posca_system_bandwidth\
113 _dashboard.json') as dashboard:
114     doc = json.load(dashboard)
115 res = es.index(
116     index=".kibana",
117     doc_type="dashboard",
118     id="system_bandwidth_dashboard",
119     body=doc)
120 if res['created'] == "True":
121     print("system_bandwidth dashboard has created")
122 else:
123     print("system_bandwidth dashboard has existed")