diff options
author | liyin <liyin11@huawei.com> | 2017-02-18 22:24:18 +0800 |
---|---|---|
committer | Ace Lee <liyin11@huawei.com> | 2017-02-20 11:00:13 +0000 |
commit | bffdc13b667abc6eb8bccdcc1aa82cf963a5dfa8 (patch) | |
tree | b8fdcc9be40e622e5a8a1ddb859eb03a53b10cbc /testsuites | |
parent | 58c97253eaaf72f73924837fca4ddcb5cb8a5d94 (diff) |
stress_test_dashboard_code
JIRA:BOTTLENECK-138
Those codes will create dashboard for stress test.
And we have fixed a bug, that we will increace env prepare in this patch
besides: we also add some code of how to yardstick api.
Change-Id: I64bb249ee0df9fe37e998a784ba346719bf25197
Signed-off-by: liyin <liyin11@huawei.com>
Diffstat (limited to 'testsuites')
7 files changed, 217 insertions, 3 deletions
diff --git a/testsuites/posca/testcase_dashboard/posca_stress_ping.py b/testsuites/posca/testcase_dashboard/posca_stress_ping.py new file mode 100644 index 00000000..7a5a8fb8 --- /dev/null +++ b/testsuites/posca/testcase_dashboard/posca_stress_ping.py @@ -0,0 +1,119 @@ +#!/usr/bin/python +############################################################################## +# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +'''This file realize a function of creating dashboard of stress ping test''' +import ConfigParser +from elasticsearch import Elasticsearch +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_path = os.path.join(conf_parser.test_dir, + "posca", + "testcase_dashboard") +dashboard_dir = dashboard_path + "/" + + +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"]) + + +def posca_stress_ping(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_stress_ping_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") + + 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") + + # Configure discover panel + with open(dashboard_dir + 'posca_stress_ping_discover.json')\ + as index_discover: + doc = json.load(index_discover) + res = es.index( + index=".kibana", + doc_type="search", + id="posca_stress_ping", + body=doc) + if res['created'] == "True": + LOG.info("posca_stress_ping search has created") + else: + LOG.info("posca_stress_ping search has existed") + + # Create testing data in line graph + with open(dashboard_dir + 'posca_stress_ping_histogram.json')\ + as line_data: + doc = json.load(line_data) + res = es.index( + index=".kibana", + doc_type="visualization", + id="posca_stress_ping_histogram", + body=doc) + if res['created'] == "True": + LOG.info("posca_stress_ping visualization has created") + else: + LOG.info("posca_stress_ping visualization has existed") + + # Create comparison results in line chart + with open(dashboard_dir + 'posca_stress_ping_table.json')\ + as line_char: + doc = json.load(line_char) + res = es.index( + index=".kibana", + doc_type="visualization", + id="posca_stress_ping_table", + body=doc) + if res['created'] == "True": + LOG.info("posca_stress_ping visualization has created") + else: + LOG.info("posca_stress_ping visualization has existed") + + # Create dashboard + with open(dashboard_dir + 'posca_stress_ping_dashboard.json')\ + as dashboard: + doc = json.load(dashboard) + res = es.index( + index=".kibana", + doc_type="dashboard", + id="posca_stress_ping", + body=doc) + if res['created'] == "True": + LOG.info("posca_stress_ping dashboard has created") + else: + LOG.info("posca_stress_ping dashboard has existed") diff --git a/testsuites/posca/testcase_dashboard/posca_stress_ping_dashboard.json b/testsuites/posca/testcase_dashboard/posca_stress_ping_dashboard.json new file mode 100644 index 00000000..a06ceab8 --- /dev/null +++ b/testsuites/posca/testcase_dashboard/posca_stress_ping_dashboard.json @@ -0,0 +1,13 @@ +{ + "title": "posca_stress_ping", + "hits": 0, + "description": "", + "panelsJSON": "[{\"id\":\"posca_stress_ping_histogram\",\"type\":\"visualization\",\"panelIndex\":1,\"size_x\":6,\"size_y\":4,\"col\":1,\"row\":1},{\"id\":\"posca_stress_ping_table\",\"type\":\"visualization\",\"panelIndex\":2,\"size_x\":6,\"size_y\":4,\"col\":7,\"row\":1}]", + "optionsJSON": "{\"darkTheme\":false}", + "uiStateJSON": "{}", + "version": 1, + "timeRestore": false, + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"filter\":[{\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}}}]}" + } +}
\ No newline at end of file diff --git a/testsuites/posca/testcase_dashboard/posca_stress_ping_discover.json b/testsuites/posca/testcase_dashboard/posca_stress_ping_discover.json new file mode 100644 index 00000000..4a23dc1f --- /dev/null +++ b/testsuites/posca/testcase_dashboard/posca_stress_ping_discover.json @@ -0,0 +1,16 @@ +{ + "title": "posca_stress_ping", + "description": "", + "hits": 0, + "columns": [ + "_source" + ], + "sort": [ + "_score", + "desc" + ], + "version": 1, + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"index\":\"bottlenecks\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[],\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}},\"require_field_match\":false,\"fragment_size\":2147483647}}" + } +}
\ No newline at end of file diff --git a/testsuites/posca/testcase_dashboard/posca_stress_ping_histogram.json b/testsuites/posca/testcase_dashboard/posca_stress_ping_histogram.json new file mode 100644 index 00000000..181aaca3 --- /dev/null +++ b/testsuites/posca/testcase_dashboard/posca_stress_ping_histogram.json @@ -0,0 +1,11 @@ +{ + "title": "posca_stress_ping_histogram", + "visState": "{\"title\":\"New Visualization\",\"type\":\"histogram\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"scale\":\"linear\",\"mode\":\"stacked\",\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"sum\",\"schema\":\"metric\",\"params\":{\"field\":\"success_rate\"}},{\"id\":\"2\",\"type\":\"terms\",\"schema\":\"segment\",\"params\":{\"field\":\"number_of_users\",\"size\":100,\"order\":\"desc\",\"orderBy\":\"1\"}}],\"listeners\":{}}", + "uiStateJSON": "{}", + "description": "", + "savedSearchId": "posca_stress_ping", + "version": 1, + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"filter\":[]}" + } +}
\ No newline at end of file diff --git a/testsuites/posca/testcase_dashboard/posca_stress_ping_index_pattern.json b/testsuites/posca/testcase_dashboard/posca_stress_ping_index_pattern.json new file mode 100644 index 00000000..552cc6ef --- /dev/null +++ b/testsuites/posca/testcase_dashboard/posca_stress_ping_index_pattern.json @@ -0,0 +1,4 @@ +{ + "title": "bottlenecks", + "fields": "[{\"name\":\"success_times\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"indexed\":true,\"analyzed\":false,\"doc_values\":true},{\"name\":\"_index\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"indexed\":false,\"analyzed\":false,\"doc_values\":false},{\"name\":\"number_of_users\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"indexed\":true,\"analyzed\":false,\"doc_values\":true},{\"name\":\"_source\",\"type\":\"_source\",\"count\":0,\"scripted\":false,\"indexed\":false,\"analyzed\":false,\"doc_values\":false},{\"name\":\"duration_time\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"indexed\":true,\"analyzed\":false,\"doc_values\":true},{\"name\":\"success_rate\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"indexed\":true,\"analyzed\":false,\"doc_values\":true},{\"name\":\"_id\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"indexed\":false,\"analyzed\":false,\"doc_values\":false},{\"name\":\"_type\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"indexed\":false,\"analyzed\":false,\"doc_values\":false},{\"name\":\"_score\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"indexed\":false,\"analyzed\":false,\"doc_values\":false}]" +}
\ No newline at end of file diff --git a/testsuites/posca/testcase_dashboard/posca_stress_ping_table.json b/testsuites/posca/testcase_dashboard/posca_stress_ping_table.json new file mode 100644 index 00000000..c6070a4c --- /dev/null +++ b/testsuites/posca/testcase_dashboard/posca_stress_ping_table.json @@ -0,0 +1,11 @@ +{ + "title": "posca_stress_ping_table", + "visState": "{\"title\":\"New Visualization\",\"type\":\"table\",\"params\":{\"perPage\":10,\"showPartialRows\":false,\"showMeticsAtAllLevels\":false},\"aggs\":[{\"id\":\"1\",\"type\":\"sum\",\"schema\":\"metric\",\"params\":{\"field\":\"duration_time\"}},{\"id\":\"2\",\"type\":\"terms\",\"schema\":\"bucket\",\"params\":{\"field\":\"number_of_users\",\"size\":100,\"order\":\"asc\",\"orderBy\":\"1\"}},{\"id\":\"3\",\"type\":\"terms\",\"schema\":\"bucket\",\"params\":{\"field\":\"success_times\",\"size\":100,\"order\":\"asc\",\"orderBy\":\"1\"}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"bucket\",\"params\":{\"field\":\"success_rate\",\"size\":100,\"order\":\"asc\",\"orderBy\":\"1\"}}],\"listeners\":{}}", + "uiStateJSON": "{}", + "description": "", + "savedSearchId": "posca_stress_ping", + "version": 1, + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"filter\":[]}" + } +}
\ No newline at end of file diff --git a/testsuites/posca/testcase_script/posca_stress_ping.py b/testsuites/posca/testcase_script/posca_stress_ping.py index abf8044a..02244a37 100644 --- a/testsuites/posca/testcase_script/posca_stress_ping.py +++ b/testsuites/posca/testcase_script/posca_stress_ping.py @@ -16,9 +16,11 @@ import uuid import json import os import multiprocessing +import docker +import datetime import utils.infra_setup.runner.yardstick as Runner from utils.parser import Parser as conf_parser -import docker +import testsuites.posca.testcase_dashboard.posca_stress_ping as DashBoard # -------------------------------------------------- # logging configuration # -------------------------------------------------- @@ -33,10 +35,16 @@ test_dict = { "testcase": "ping_bottlenecks" } } +testfile = os.path.basename(__file__) +testcase, file_format = os.path.splitext(testfile) def env_pre(con_dic): - Runner.yardstick_env_prepare(con_dic['contexts']) + client = docker.from_env() + con = client.containers.get('bottleneckcompose_yardstick_1') + cmd = ('yardstick env prepare') + stdout = con.exec_run(cmd) + LOG.debug(stdout) def do_test(test_config, con_dic): @@ -59,6 +67,18 @@ def do_test(test_config, con_dic): return out_value +def config_to_result(num, out_num, during_date): + testdata = {} + test_result = {} + test_result["number_of_users"] = float(num) + test_result["success_times"] = out_num + test_result["success_rate"] = out_num / num + test_result["duration_time"] = during_date + testdata["data_body"] = test_result + testdata["testcase"] = testcase + return testdata + + def func_run(condic): test_config = {} test_date = do_test(test_config, condic) @@ -72,19 +92,39 @@ def run(test_config): con_dic["contexts"]["yardstick_test_ip"] =\ conf_parser.ip_parser("yardstick_test_ip") + if test_config["dashboard"]["dashboard"] == 'y': + if test_config["dashboard"]["dashboard_ip"] is None: + test_config["dashboard"]["dashboard_ip"] =\ + conf_parser.ip_parser("dashboard") + LOG.info("Create Dashboard data") + DashBoard.posca_stress_ping(test_config["dashboard"]) + + LOG.info("yardstick envrionment prepare!") env_pre(con_dic) - for num in test_num: + for value in test_num: result = [] out_num = 0 + num = int(value) pool = multiprocessing.Pool(processes=num) + + starttime = datetime.datetime.now() for i in range(0, int(num)): result.append(pool.apply_async(func_run, (con_dic, ))) pool.close() pool.join() for res in result: out_num = out_num + float(res.get()) + + endtime = datetime.datetime.now() LOG.info("%s thread success %d times" % (num, out_num)) + during_date = (endtime - starttime).seconds + + data_reply = config_to_result(num, out_num, during_date) + if test_config['dashboard']['dashboard'] == 'y': + DashBoard.dashboard_send_data(test_config['dashboard'], data_reply) + conf_parser.result_to_file(data_reply, test_config["out_file"]) + if out_num < num: success_rate = ('%d/%d' % (out_num, num)) LOG.error('error thread: %d ' |