Moon testcase bug fix
[bottlenecks.git] / testsuites / posca / testcase_dashboard / posca_feature_moon.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 '''This file realize a function of creating dashboard of stress ping test'''
11 import ConfigParser
12 from elasticsearch import Elasticsearch
13 import json
14 import os
15 import utils.logger as log
16 from utils.parser import Parser as conf_parser
17
18 LOG = log.Logger(__name__).getLogger()
19 config = ConfigParser.ConfigParser()
20 es = Elasticsearch()
21 dashboard_path = os.path.join(conf_parser.test_dir,
22                               "posca",
23                               "testcase_dashboard")
24 dashboard_dir = dashboard_path + "/"
25
26
27 def dashboard_send_data(runner_config, test_data):
28     global es
29     print runner_config
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"])
38
39
40 def posca_moon_init(runner_config):
41     global es
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')\
46             as index_pattern:
47         doc = json.load(index_pattern)
48     res = es.index(
49         index=".kibana",
50         doc_type="index-pattern",
51         id="bottlenecks",
52         body=doc)
53     if res['created'] == "True":
54         LOG.info("bottlenecks index-pattern has created")
55     else:
56         LOG.info("bottlenecks index-pattern has existed")
57
58     with open(dashboard_dir + 'posca_system_bandwidth_config.json')\
59             as index_config:
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")
64     else:
65         LOG.info("bottlenecks config has existed")
66
67     # Configure discover panel
68     with open(dashboard_dir + 'posca_feature_moon_discover.json')\
69             as index_discover:
70         doc = json.load(index_discover)
71     res = es.index(
72         index=".kibana",
73         doc_type="search",
74         id="moon",
75         body=doc)
76     if res['created'] == "True":
77         LOG.info("moon testcase search has created")
78     else:
79         LOG.info("moon testcase search has existed")
80
81     # Create testing data in line graph
82     with open(dashboard_dir + 'posca_feature_moon_resources_histogram.json')\
83             as line_data:
84         doc = json.load(line_data)
85     res = es.index(
86         index=".kibana",
87         doc_type="visualization",
88         id="resources",
89         body=doc)
90     if res['created'] == "True":
91         LOG.info("moon resources visualization has created")
92     else:
93         LOG.info("moon resources visualization has existed")
94
95     # Create comparison results in line chart
96     with open(dashboard_dir + 'posca_feature_moon_tenants_histogram.json')\
97             as line_char:
98         doc = json.load(line_char)
99     res = es.index(
100         index=".kibana",
101         doc_type="visualization",
102         id="tenants",
103         body=doc)
104     if res['created'] == "True":
105         LOG.info("moon tenants visualization has created")
106     else:
107         LOG.info("moon tenants visualization has existed")
108
109     # Create dashboard
110     with open(dashboard_dir + 'posca_feature_moon_dashboard.json')\
111             as dashboard:
112         doc = json.load(dashboard)
113     res = es.index(
114         index=".kibana",
115         doc_type="dashboard",
116         id="moon",
117         body=doc)
118     if res['created'] == "True":
119         LOG.info("moon testcases dashboard has created")
120     else:
121         LOG.info("moon testcases dashboard has existed")