X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=testsuites%2Fposca%2Ftestcase_dashboard%2Fsystem_bandwidth.py;h=e95ff21432f886c8200a52fcb1d8a7563ea25947;hb=refs%2Fchanges%2F71%2F28571%2F1;hp=63671273db55ba591cb830015a0337676a0f8c13;hpb=9c22cd768a161ec0eab4da24f40a4c626275c746;p=bottlenecks.git diff --git a/testsuites/posca/testcase_dashboard/system_bandwidth.py b/testsuites/posca/testcase_dashboard/system_bandwidth.py index 63671273..e95ff214 100755 --- a/testsuites/posca/testcase_dashboard/system_bandwidth.py +++ b/testsuites/posca/testcase_dashboard/system_bandwidth.py @@ -9,115 +9,121 @@ ############################################################################## import ConfigParser from elasticsearch import Elasticsearch -from pyroute2 import IPDB import json +import os +import utils.logger as log +from utils.parser import Parser as conf_parser +LOG = log.Logger(__name__).getLogger() config = ConfigParser.ConfigParser() +es = Elasticsearch() +dashboard_dir = os.path.join(conf_parser.test_dir, + "posca", + "testcase_dashboard") -dashboard_dir = "/home/opnfv/bottlenecks/testsuites/posca\ -/testcase_dashboard/" -file_str = "/home/opnfv/bottlenecks/testsuites/posca/\ -testcase_cfg/posca_factor_system_bandwidth.yaml" -with open(file_str, "rd") as cfgfile: - config.readfp(cfgfile) - ES_ip_a = config.get("config", "ES_ip") +def dashboard_send_data(runner_config, test_data): + global es + es_ip = runner_config['dashboard_ip'].split(':') + es = Elasticsearch([{'host': es_ip[0]}]) + res = es.index(index="bottlenecks", + doc_type=test_data["testcase"], + body=test_data["data_body"]) + if res['created'] == "False": + LOG.error("date send to kibana have errors ", test_data["data_body"]) -with IPDB() as ip: - GATEWAY_IP = ip.routes['default'].gateway - if ES_ip_a is "": - ES_ip_a = "{}:9200".format(GATEWAY_IP) - print("ES_ip is null get local ip is {}".format(ES_ip_a)) -es_ip = ES_ip_a.split(':') -es = Elasticsearch([{'host': es_ip[0]}]) +def dashboard_system_bandwidth(runner_config): + global es + es_ip = runner_config['dashboard_ip'].split(':') + es = Elasticsearch([{'host': es_ip[0]}]) + # Create bottlenecks index + with open(dashboard_dir + 'posca_system_bandwidth_index_pattern.json')\ + as index_pattern: + doc = json.load(index_pattern) + res = es.index( + index=".kibana", + doc_type="index-pattern", + id="bottlenecks", + body=doc) + if res['created'] == "True": + LOG.info("bottlenecks index-pattern has created") + else: + LOG.info("bottlenecks index-pattern has existed") -# Create bottlenecks index -with open(dashboard_dir + 'posca_system_bandwidth\ -_index_pattern.json') as index_pattern: - doc = json.load(index_pattern) -res = es.index( - index=".kibana", - doc_type="index-pattern", - id="bottlenecks", - body=doc) -if res['created'] == "True": - print("bottlenecks index-pattern has created") -else: - print("bottlenecks index-pattern has existed") + with open(dashboard_dir + 'posca_system_bandwidth_config.json')\ + as index_config: + doc = json.load(index_config) + res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc) + if res['created'] == "True": + LOG.info("bottlenecks config has created") + else: + LOG.info("bottlenecks config has existed") -with open(dashboard_dir + 'posca_system_bandwidth\ -_config.json') as index_config: - doc = json.load(index_config) -res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc) -if res['created'] == "True": - print("bottlenecks config has created") -else: - print("bottlenecks config has existed") + # Configure discover panel + with open(dashboard_dir + 'posca_system_bandwidth_discover.json')\ + as index_discover: + doc = json.load(index_discover) + res = es.index( + index=".kibana", + doc_type="search", + id="system_bandwidth", + body=doc) + if res['created'] == "True": + LOG.info("system_bandwidth search has created") + else: + LOG.info("system_bandwidth search has existed") -# Configure discover panel -with open(dashboard_dir + 'posca_system_bandwidth\ -_discover.json') as index_discover: - doc = json.load(index_discover) -res = es.index( - index=".kibana", - doc_type="search", - id="system_bandwidth", - body=doc) -if res['created'] == "True": - print("system_bandwidth search has created") -else: - print("system_bandwidth search has existed") + # Create testing data in line graph + # Create testing data in line graph + with open(dashboard_dir + 'posca_system_bandwidth_line_data.json')\ + as line_data: + doc = json.load(line_data) + res = es.index( + index=".kibana", + doc_type="visualization", + id="system_bandwidth_line-date", + body=doc) + if res['created'] == "True": + LOG.info("system_bandwidth_line-date visualization has created") + else: + LOG.info("system_bandwidth_line-date visualization has existed") -# Create testing data in line graph -with open(dashboard_dir + 'posca_system_bandwidth\ -_line_data.json') as line_data: - doc = json.load(line_data) -res = es.index( - index=".kibana", - doc_type="visualization", - id="system_bandwidth_line-date", - body=doc) -if res['created'] == "True": - print("system_bandwidth_line-date visualization has created") -else: - print("system_bandwidth_line-date visualization has existed") + # Create comparison results in line chart + with open(dashboard_dir + 'posca_system_bandwidth_line_char.json')\ + as line_char: + doc = json.load(line_char) + res = es.index( + index=".kibana", + doc_type="visualization", + id="system_bandwidth_line-char", + body=doc) + if res['created'] == "True": + LOG.info("system_bandwidth_line-char visualization has created") + else: + LOG.info("system_bandwidth_line-char visualization has existed") -# Create comparison results in line chart -with open(dashboard_dir + 'posca_system_bandwidth\ -_line_char.json') as line_char: - doc = json.load(line_char) -res = es.index( - index=".kibana", - doc_type="visualization", - id="system_bandwidth_line-char", - body=doc) -if res['created'] == "True": - print("system_bandwidth_line-char visualization has created") -else: - print("system_bandwidth_line-char visualization has existed") + # Create monitoring data in table + with open(dashboard_dir + 'posca_system_bandwidth_terms_data.json')\ + as terms_char: + doc = json.load(terms_char) + res = es.index(index=".kibana", doc_type="visualization", + id="system_bandwidth_terms_data", body=doc) + if res['created'] == "True": + LOG.info("system_bandwidth_terms_data visualization has created") + else: + LOG.info("system_bandwidth_terms_data visualization has existed") -# Create monitoring data in table -with open(dashboard_dir + 'posca_system_bandwidth\ -_terms_data.json') as terms_char: - doc = json.load(terms_char) -res = es.index(index=".kibana", doc_type="visualization", - id="system_bandwidth_terms_data", body=doc) -if res['created'] == "True": - print("system_bandwidth_terms_data visualization has created") -else: - print("system_bandwidth_terms_data visualization has existed") - -# Create dashboard -with open(dashboard_dir + 'posca_system_bandwidth\ -_dashboard.json') as dashboard: - doc = json.load(dashboard) -res = es.index( - index=".kibana", - doc_type="dashboard", - id="system_bandwidth_dashboard", - body=doc) -if res['created'] == "True": - print("system_bandwidth dashboard has created") -else: - print("system_bandwidth dashboard has existed") + # Create dashboard + with open(dashboard_dir + 'posca_system_bandwidth_dashboard.json')\ + as dashboard: + doc = json.load(dashboard) + res = es.index( + index=".kibana", + doc_type="dashboard", + id="system_bandwidth_dashboard", + body=doc) + if res['created'] == "True": + LOG.info("system_bandwidth dashboard has created") + else: + LOG.info("system_bandwidth dashboard has existed")