aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/benchmark
diff options
context:
space:
mode:
authorVolodymyr Mytnyk <volodymyrx.mytnyk@intel.com>2019-01-24 10:17:48 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-01-24 10:17:48 +0000
commitdfb534bbd7ab1454c1ad3b63d0b785e3050c1962 (patch)
tree4bb95bfdbc19b6fda0e41cfacda74aaae8d9dbe8 /yardstick/tests/unit/benchmark
parente097cbcff4b911c91a87fee5e9218f79b8d0eeef (diff)
parent855e0532f9a58986fbb95e19ac42e90b53f031b3 (diff)
Merge changes from topic 'report/html_table'
* changes: Additional rework of NSB report Only show metrics for selected nodes in data table Fix conversion to JS for HTML reports
Diffstat (limited to 'yardstick/tests/unit/benchmark')
-rw-r--r--yardstick/tests/unit/benchmark/core/test_report.py139
1 files changed, 105 insertions, 34 deletions
diff --git a/yardstick/tests/unit/benchmark/core/test_report.py b/yardstick/tests/unit/benchmark/core/test_report.py
index 11d017ff0..4683c26b0 100644
--- a/yardstick/tests/unit/benchmark/core/test_report.py
+++ b/yardstick/tests/unit/benchmark/core/test_report.py
@@ -9,6 +9,7 @@
##############################################################################
import mock
+import six
import unittest
import uuid
@@ -19,13 +20,82 @@ from yardstick.cmd.commands import change_osloobj_to_paras
GOOD_YAML_NAME = 'fake_name'
GOOD_TASK_ID = str(uuid.uuid4())
GOOD_DB_FIELDKEYS = [{'fieldKey': 'fake_key'}]
-GOOD_DB_TASK = [{
+GOOD_DB_METRICS = [{
'fake_key': 1.234,
'time': '0000-00-00T12:34:56.789012Z',
}]
GOOD_TIMESTAMP = ['12:34:56.789012']
BAD_YAML_NAME = 'F@KE_NAME'
BAD_TASK_ID = 'aaaaaa-aaaaaaaa-aaaaaaaaaa-aaaaaa'
+MORE_DB_FIELDKEYS = [
+ {'fieldKey': 'fake_key'},
+ {'fieldKey': 'str_str'},
+ {'fieldKey': u'str_unicode'},
+ {u'fieldKey': 'unicode_str'},
+ {u'fieldKey': u'unicode_unicode'},
+ ]
+MORE_DB_METRICS = [{
+ 'fake_key': None,
+ 'time': '0000-00-00T00:00:00.000000Z',
+ }, {
+ 'fake_key': 123,
+ 'time': '0000-00-00T00:00:01.000000Z',
+ }, {
+ 'fake_key': 4.56,
+ 'time': '0000-00-00T00:00:02.000000Z',
+ }, {
+ 'fake_key': 9876543210987654321,
+ 'time': '0000-00-00T00:00:03.000000Z',
+ }, {
+ 'fake_key': 'str_str value',
+ 'time': '0000-00-00T00:00:04.000000Z',
+ }, {
+ 'fake_key': u'str_unicode value',
+ 'time': '0000-00-00T00:00:05.000000Z',
+ }, {
+ u'fake_key': 'unicode_str value',
+ 'time': '0000-00-00T00:00:06.000000Z',
+ }, {
+ u'fake_key': u'unicode_unicode value',
+ 'time': '0000-00-00T00:00:07.000000Z',
+ }, {
+ 'fake_key': '7.89',
+ 'time': '0000-00-00T00:00:08.000000Z',
+ }, {
+ 'fake_key': '1011',
+ 'time': '0000-00-00T00:00:09.000000Z',
+ }, {
+ 'fake_key': '9876543210123456789',
+ 'time': '0000-00-00T00:00:10.000000Z',
+ }]
+MORE_TIMESTAMP = ['00:00:%02d.000000' % n for n in range(len(MORE_DB_METRICS))]
+MORE_EMPTY_DATA = [None] * len(MORE_DB_METRICS)
+MORE_EXPECTED_TABLE_VALS = {
+ 'Timestamp': MORE_TIMESTAMP,
+ 'fake_key': [
+ None,
+ 123,
+ 4.56,
+ 9876543210987654321 if six.PY3 else 9.876543210987655e+18,
+ 'str_str value',
+ 'str_unicode value',
+ 'unicode_str value',
+ 'unicode_unicode value',
+ 7.89,
+ 1011,
+ 9876543210123456789 if six.PY3 else 9.876543210123457e+18,
+ ],
+ 'str_str': MORE_EMPTY_DATA,
+ 'str_unicode': MORE_EMPTY_DATA,
+ 'unicode_str': MORE_EMPTY_DATA,
+ 'unicode_unicode': MORE_EMPTY_DATA,
+ }
+MORE_EXPECTED_DATASETS = [{
+ 'label': key,
+ 'data': MORE_EXPECTED_TABLE_VALS[key],
+ }
+ for key in map(str, [field['fieldKey'] for field in MORE_DB_FIELDKEYS])
+ ]
class JSTreeTestCase(unittest.TestCase):
@@ -47,23 +117,15 @@ class JSTreeTestCase(unittest.TestCase):
def test_format_for_jstree(self):
data = [
- {'data': [0, ], 'label': 'tg__0.DropPackets'},
- {'data': [548, ], 'label': 'tg__0.LatencyAvg.5'},
- {'data': [1172, ], 'label': 'tg__0.LatencyAvg.6'},
- {'data': [1001, ], 'label': 'tg__0.LatencyMax.5'},
- {'data': [1468, ], 'label': 'tg__0.LatencyMax.6'},
- {'data': [18.11, ], 'label': 'tg__0.RxThroughput'},
- {'data': [18.11, ], 'label': 'tg__0.TxThroughput'},
- {'data': [0, ], 'label': 'tg__1.DropPackets'},
- {'data': [548, ], 'label': 'tg__1.LatencyAvg.5'},
- {'data': [1172, ], 'label': 'tg__1.LatencyAvg.6'},
- {'data': [1001, ], 'label': 'tg__1.LatencyMax.5'},
- {'data': [1468, ], 'label': 'tg__1.LatencyMax.6'},
- {'data': [18.1132084505, ], 'label': 'tg__1.RxThroughput'},
- {'data': [18.1157260383, ], 'label': 'tg__1.TxThroughput'},
- {'data': [9057888, ], 'label': 'vnf__0.curr_packets_in'},
- {'data': [0, ], 'label': 'vnf__0.packets_dropped'},
- {'data': [617825443, ], 'label': 'vnf__0.packets_fwd'},
+ 'tg__0.DropPackets',
+ 'tg__0.LatencyAvg.5', 'tg__0.LatencyAvg.6',
+ 'tg__0.LatencyMax.5', 'tg__0.LatencyMax.6',
+ 'tg__0.RxThroughput', 'tg__0.TxThroughput',
+ 'tg__1.DropPackets',
+ 'tg__1.LatencyAvg.5', 'tg__1.LatencyAvg.6',
+ 'tg__1.LatencyMax.5', 'tg__1.LatencyMax.6',
+ 'tg__1.RxThroughput', 'tg__1.TxThroughput',
+ 'vnf__0.curr_packets_in', 'vnf__0.packets_dropped', 'vnf__0.packets_fwd',
]
expected_output = [
@@ -117,11 +179,11 @@ class ReportTestCase(unittest.TestCase):
self.assertEqual(GOOD_TASK_ID, str(self.rep.task_id))
def test__validate_invalid_yaml_name(self):
- with self.assertRaisesRegexp(ValueError, "yaml*"):
+ with six.assertRaisesRegex(self, ValueError, "yaml*"):
self.rep._validate(BAD_YAML_NAME, GOOD_TASK_ID)
def test__validate_invalid_task_id(self):
- with self.assertRaisesRegexp(ValueError, "task*"):
+ with six.assertRaisesRegex(self, ValueError, "task*"):
self.rep._validate(GOOD_YAML_NAME, BAD_TASK_ID)
@mock.patch.object(influx, 'query')
@@ -141,42 +203,51 @@ class ReportTestCase(unittest.TestCase):
mock_query.return_value = []
self.rep.yaml_name = GOOD_YAML_NAME
self.rep.task_id = GOOD_TASK_ID
- self.assertRaisesRegexp(KeyError, "Test case", self.rep._get_fieldkeys)
+ six.assertRaisesRegex(self, KeyError, "Test case", self.rep._get_fieldkeys)
@mock.patch.object(influx, 'query')
- def test__get_tasks(self, mock_query):
- mock_query.return_value = GOOD_DB_TASK
+ def test__get_metrics(self, mock_query):
+ mock_query.return_value = GOOD_DB_METRICS
self.rep.yaml_name = GOOD_YAML_NAME
self.rep.task_id = GOOD_TASK_ID
- self.assertEqual(GOOD_DB_TASK, self.rep._get_tasks())
+ self.assertEqual(GOOD_DB_METRICS, self.rep._get_metrics())
@mock.patch.object(influx, 'query')
- def test__get_tasks_task_not_found(self, mock_query):
+ def test__get_metrics_task_not_found(self, mock_query):
mock_query.return_value = []
self.rep.yaml_name = GOOD_YAML_NAME
self.rep.task_id = GOOD_TASK_ID
- self.assertRaisesRegexp(KeyError, "Task ID", self.rep._get_tasks)
+ six.assertRaisesRegex(self, KeyError, "Task ID", self.rep._get_metrics)
- @mock.patch.object(report.Report, '_get_tasks')
+ @mock.patch.object(report.Report, '_get_metrics')
+ @mock.patch.object(report.Report, '_get_fieldkeys')
+ def test__generate_common(self, mock_keys, mock_metrics):
+ mock_metrics.return_value = MORE_DB_METRICS
+ mock_keys.return_value = MORE_DB_FIELDKEYS
+ datasets, table_vals = self.rep._generate_common(self.param)
+ self.assertEqual(MORE_EXPECTED_DATASETS, datasets)
+ self.assertEqual(MORE_EXPECTED_TABLE_VALS, table_vals)
+
+ @mock.patch.object(report.Report, '_get_metrics')
@mock.patch.object(report.Report, '_get_fieldkeys')
@mock.patch.object(report.Report, '_validate')
- def test_generate(self, mock_valid, mock_keys, mock_tasks):
- mock_tasks.return_value = GOOD_DB_TASK
+ def test_generate(self, mock_valid, mock_keys, mock_metrics):
+ mock_metrics.return_value = GOOD_DB_METRICS
mock_keys.return_value = GOOD_DB_FIELDKEYS
self.rep.generate(self.param)
mock_valid.assert_called_once_with(GOOD_YAML_NAME, GOOD_TASK_ID)
- mock_tasks.assert_called_once_with()
+ mock_metrics.assert_called_once_with()
mock_keys.assert_called_once_with()
self.assertEqual(GOOD_TIMESTAMP, self.rep.Timestamp)
- @mock.patch.object(report.Report, '_get_tasks')
+ @mock.patch.object(report.Report, '_get_metrics')
@mock.patch.object(report.Report, '_get_fieldkeys')
@mock.patch.object(report.Report, '_validate')
- def test_generate_nsb(self, mock_valid, mock_keys, mock_tasks):
- mock_tasks.return_value = GOOD_DB_TASK
+ def test_generate_nsb(self, mock_valid, mock_keys, mock_metrics):
+ mock_metrics.return_value = GOOD_DB_METRICS
mock_keys.return_value = GOOD_DB_FIELDKEYS
self.rep.generate_nsb(self.param)
mock_valid.assert_called_once_with(GOOD_YAML_NAME, GOOD_TASK_ID)
- mock_tasks.assert_called_once_with()
+ mock_metrics.assert_called_once_with()
mock_keys.assert_called_once_with()
self.assertEqual(GOOD_TIMESTAMP, self.rep.Timestamp)