diff options
Diffstat (limited to 'yardstick/tests/functional')
-rw-r--r-- | yardstick/tests/functional/benchmark/core/__init__.py (renamed from yardstick/tests/functional/network_services/__init__.py) | 0 | ||||
-rw-r--r-- | yardstick/tests/functional/benchmark/core/test_report.py | 114 | ||||
-rw-r--r-- | yardstick/tests/functional/network_services/vnf_generic/__init__.py | 0 | ||||
-rw-r--r-- | yardstick/tests/functional/network_services/vnf_generic/vnf/__init__.py | 0 | ||||
-rw-r--r-- | yardstick/tests/functional/network_services/vnf_generic/vnf/test_base.py | 103 |
5 files changed, 114 insertions, 103 deletions
diff --git a/yardstick/tests/functional/network_services/__init__.py b/yardstick/tests/functional/benchmark/core/__init__.py index e69de29bb..e69de29bb 100644 --- a/yardstick/tests/functional/network_services/__init__.py +++ b/yardstick/tests/functional/benchmark/core/__init__.py diff --git a/yardstick/tests/functional/benchmark/core/test_report.py b/yardstick/tests/functional/benchmark/core/test_report.py new file mode 100644 index 000000000..5f060dd1e --- /dev/null +++ b/yardstick/tests/functional/benchmark/core/test_report.py @@ -0,0 +1,114 @@ +############################################################################## +# Copyright (c) 2018 Intel Corporation. +# +# 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 +############################################################################## + +import ast +import tempfile +import unittest + +import mock +from six.moves import configparser + +from yardstick.benchmark import core +from yardstick.benchmark.core import report +from yardstick.cmd.commands import change_osloobj_to_paras + + +GOOD_YAML_NAME = 'fake_name' +GOOD_TASK_ID = "9cbe74b6-df09-4535-8bdc-dc3a43b8a4e2" +GOOD_DB_FIELDKEYS = [ + {u'fieldKey': u'metric1', u'fieldType': u'integer'}, + {u'fieldKey': u'metric4', u'fieldType': u'integer'}, + {u'fieldKey': u'metric2', u'fieldType': u'integer'}, + {u'fieldKey': u'metric3', u'fieldType': u'integer'}, +] +GOOD_DB_METRICS = [ + {u'time': u'2018-08-20T16:49:26.372662016Z', + u'metric1': 1, u'metric2': 0, u'metric3': 8, u'metric4': 5}, + {u'time': u'2018-08-20T16:49:27.374208000Z', + u'metric1': 1, u'metric2': 1, u'metric3': 5, u'metric4': 4}, + {u'time': u'2018-08-20T16:49:28.375742976Z', + u'metric1': 2, u'metric2': 2, u'metric3': 3, u'metric4': 3}, + {u'time': u'2018-08-20T16:49:29.377299968Z', + u'metric1': 3, u'metric2': 3, u'metric3': 2, u'metric4': 2}, + {u'time': u'2018-08-20T16:49:30.378252032Z', + u'metric1': 5, u'metric2': 4, u'metric3': 1, u'metric4': 1}, + {u'time': u'2018-08-20T16:49:30.379359421Z', + u'metric1': 8, u'metric2': 5, u'metric3': 1, u'metric4': 0}, +] + +yardstick_config = """ +[DEFAULT] +dispatcher = influxdb +""" + + +def my_query(query_sql): + get_fieldkeys_cmd = 'show field keys' + get_metrics_cmd = 'select * from' + + if get_fieldkeys_cmd in query_sql: + return GOOD_DB_FIELDKEYS + elif get_metrics_cmd in query_sql: + return GOOD_DB_METRICS + return [] + + +class ReportTestCase(unittest.TestCase): + + @mock.patch.object(report.influx, 'query', new=my_query) + @mock.patch.object(configparser.ConfigParser, + 'read', side_effect=mock.mock_open(read_data=yardstick_config)) + def test_report_generate_nsb_simple(self, *args): + tmpfile = tempfile.NamedTemporaryFile(delete=True) + + args = core.Param({"task_id": [GOOD_TASK_ID], "yaml_name": [GOOD_YAML_NAME]}) + params = change_osloobj_to_paras(args) + + with mock.patch.object(report.consts, 'DEFAULT_HTML_FILE', tmpfile.name): + report.Report().generate_nsb(params) + + data_act = None + time_act = None + keys_act = None + tree_act = None + with open(tmpfile.name) as f: + for l in f.readlines(): + if "var report_data = {" in l: + data_act = ast.literal_eval(l.strip()[18:-1]) + elif "var report_time = [" in l: + time_act = ast.literal_eval(l.strip()[18:-1]) + elif "var report_keys = [" in l: + keys_act = ast.literal_eval(l.strip()[18:-1]) + elif "var report_tree = [" in l: + tree_act = ast.literal_eval(l.strip()[18:-1]) + + data_exp = { + 'metric1': [1, 1, 2, 3, 5, 8], + 'metric2': [0, 1, 2, 3, 4, 5], + 'metric3': [8, 5, 3, 2, 1, 1], + 'metric4': [5, 4, 3, 2, 1, 0], + } + time_exp = [ + '16:49:26.372662', '16:49:27.374208', '16:49:28.375742', + '16:49:29.377299', '16:49:30.378252', '16:49:30.379359', + ] + keys_exp = [ + 'metric1', 'metric2', 'metric3', 'metric4', + ] + tree_exp = [ + {'parent': '#', 'text': 'metric1', 'id': 'metric1'}, + {'parent': '#', 'text': 'metric2', 'id': 'metric2'}, + {'parent': '#', 'text': 'metric3', 'id': 'metric3'}, + {'parent': '#', 'text': 'metric4', 'id': 'metric4'}, + ] + + self.assertEqual(data_exp, data_act) + self.assertEqual(time_exp, time_act) + self.assertEqual(keys_exp, keys_act) + self.assertEqual(tree_exp, tree_act) diff --git a/yardstick/tests/functional/network_services/vnf_generic/__init__.py b/yardstick/tests/functional/network_services/vnf_generic/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/yardstick/tests/functional/network_services/vnf_generic/__init__.py +++ /dev/null diff --git a/yardstick/tests/functional/network_services/vnf_generic/vnf/__init__.py b/yardstick/tests/functional/network_services/vnf_generic/vnf/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/yardstick/tests/functional/network_services/vnf_generic/vnf/__init__.py +++ /dev/null diff --git a/yardstick/tests/functional/network_services/vnf_generic/vnf/test_base.py b/yardstick/tests/functional/network_services/vnf_generic/vnf/test_base.py deleted file mode 100644 index e57f8f51c..000000000 --- a/yardstick/tests/functional/network_services/vnf_generic/vnf/test_base.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright (c) 2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import multiprocessing -import time -import uuid - -import mock - -from yardstick.common import messaging -from yardstick.common.messaging import payloads -from yardstick.common.messaging import producer -from yardstick.network_services.vnf_generic.vnf import base as vnf_base -from yardstick.tests.functional import base as ft_base - - -class _TrafficGenMQConsumer(vnf_base.GenericTrafficGen, - vnf_base.GenericVNFEndpoint): - - def __init__(self, name, vnfd, task_id): - vnf_base.GenericTrafficGen.__init__(self, name, vnfd, task_id) - self.queue = multiprocessing.Queue() - self._id = uuid.uuid1().int - vnf_base.GenericVNFEndpoint.__init__(self, self._id, [task_id], - self.queue) - self._consumer = vnf_base.GenericVNFConsumer([task_id], self) - self._consumer.start_rpc_server() - - def run_traffic(self, *args): - pass - - def terminate(self): - pass - - def collect_kpi(self): - pass - - def instantiate(self, *args): - pass - - def scale(self, flavor=''): - pass - - def runner_method_start_iteration(self, ctxt, **kwargs): - if ctxt['id'] in self._ctx_ids: - self._queue.put( - {'action': messaging.RUNNER_METHOD_START_ITERATION, - 'payload': payloads.RunnerPayload.dict_to_obj(kwargs)}) - - def runner_method_stop_iteration(self, ctxt, **kwargs): - if ctxt['id'] in self._ctx_ids: - self._queue.put( - {'action': messaging.RUNNER_METHOD_STOP_ITERATION, - 'payload': payloads.RunnerPayload.dict_to_obj(kwargs)}) - - -class _DummyProducer(producer.MessagingProducer): - pass - - -class GenericVNFMQConsumerTestCase(ft_base.BaseFunctionalTestCase): - - def test_fistro(self): - vnfd = {'benchmark': {'kpi': mock.ANY}, - 'vdu': [{'external-interface': 'ext_int'}] - } - task_id = uuid.uuid1().int - tg_obj = _TrafficGenMQConsumer('name_tg', vnfd, task_id) - producer = _DummyProducer(messaging.TOPIC_RUNNER, task_id) - - num_messages = 10 - for i in range(num_messages): - pload = payloads.RunnerPayload(version=10, data=i) - for method in (messaging.RUNNER_METHOD_START_ITERATION, - messaging.RUNNER_METHOD_STOP_ITERATION): - producer.send_message(method, pload) - - time.sleep(0.5) # Let consumers attend the calls - output = [] - while not tg_obj.queue.empty(): - data = tg_obj.queue.get(True, 1) - data_dict = {'action': data['action'], - 'payload': data['payload'].obj_to_dict()} - output.append(data_dict) - - self.assertEqual(num_messages * 2, len(output)) - for i in range(num_messages): - pload = payloads.RunnerPayload(version=10, data=i).obj_to_dict() - for method in (messaging.RUNNER_METHOD_START_ITERATION, - messaging.RUNNER_METHOD_STOP_ITERATION): - reg = {'action': method, 'payload': pload} - self.assertIn(reg, output) |