aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/tests')
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_model.py5
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py3
-rw-r--r--yardstick/tests/unit/benchmark/core/test_report.py184
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py11
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py154
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py20
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py73
7 files changed, 322 insertions, 128 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
index d880b4169..e76a3ca27 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
@@ -55,7 +55,7 @@ class ModelLibvirtTestCase(unittest.TestCase):
numa_cpus=0 - 10,
socket=1, threads=1,
vm_image="/var/lib/libvirt/images/yardstick-nsb-image.img",
- cpuset=2 - 10, cputune='')
+ cpuset=2 - 10, cputune='', machine='pc')
def setUp(self):
self.pci_address_str = '0001:04:03.2'
@@ -352,7 +352,8 @@ class ModelLibvirtTestCase(unittest.TestCase):
xml_ref = model.VM_TEMPLATE.format(vm_name='vm_name',
random_uuid=_uuid, mac_addr=mac, memory='1024', vcpu='8', cpu='4',
numa_cpus='0-7', socket='3', threads='2',
- vm_image='qemu_image', cpuset='4,5', cputune='cool')
+ vm_image='qemu_image', cpuset='4,5', cputune='cool',
+ machine='pc-i440fx-xenial')
xml_ref = model.Libvirt.add_cdrom(cdrom_img, xml_ref)
self.assertEqual(xml_out, xml_ref)
mock_get_mac_address.assert_called_once_with(0x00)
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
index ab9e632be..413bb68b7 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
@@ -437,7 +437,8 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.assertEqual([vnf_instance_2],
self.ovs_dpdk.setup_ovs_dpdk_context())
- mock_setup_hugepages.assert_called_once_with(self.ovs_dpdk.connection, 1024 * 1024)
+ mock_setup_hugepages.assert_called_once_with(self.ovs_dpdk.connection,
+ (1024 + 4096) * 1024) # ram + dpdk_socket0_mem + dpdk_socket1_mem
mock__check_hugepages.assert_called_once()
mock_create_vm.assert_called_once_with(
self.ovs_dpdk.connection, '/tmp/vm_ovs_0.xml')
diff --git a/yardstick/tests/unit/benchmark/core/test_report.py b/yardstick/tests/unit/benchmark/core/test_report.py
index 524302f92..3e80dcc45 100644
--- a/yardstick/tests/unit/benchmark/core/test_report.py
+++ b/yardstick/tests/unit/benchmark/core/test_report.py
@@ -1,5 +1,6 @@
##############################################################################
# Copyright (c) 2017 Rajesh Kudaka.
+# 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
@@ -7,30 +8,93 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.core.report
-
-from __future__ import print_function
-
-from __future__ import absolute_import
-
+import mock
import unittest
import uuid
-try:
- from unittest import mock
-except ImportError:
- import mock
-
+from api.utils import influx
from yardstick.benchmark.core import report
from yardstick.cmd.commands import change_osloobj_to_paras
-FAKE_YAML_NAME = 'fake_name'
-FAKE_TASK_ID = str(uuid.uuid4())
-FAKE_DB_FIELDKEYS = [{'fieldKey': 'fake_key'}]
-FAKE_TIME = '0000-00-00T00:00:00.000000Z'
-FAKE_DB_TASK = [{'fake_key': 0.000, 'time': FAKE_TIME}]
-FAKE_TIMESTAMP = ['fake_time']
-DUMMY_TASK_ID = 'aaaaaa-aaaaaaaa-aaaaaaaaaa-aaaaaa'
+GOOD_YAML_NAME = 'fake_name'
+GOOD_TASK_ID = str(uuid.uuid4())
+GOOD_DB_FIELDKEYS = [{'fieldKey': 'fake_key'}]
+GOOD_DB_TASK = [{
+ 'fake_key': 0.000,
+ 'time': '0000-00-00T00:00:00.000000Z',
+ }]
+GOOD_TIMESTAMP = ['00:00:00.000000']
+BAD_YAML_NAME = 'F@KE_NAME'
+BAD_TASK_ID = 'aaaaaa-aaaaaaaa-aaaaaaaaaa-aaaaaa'
+
+
+class JSTreeTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.jstree = report.JSTree()
+
+ def test__create_node(self):
+ _id = "tg__0.DropPackets"
+
+ expected_data = [
+ {"id": "tg__0", "text": "tg__0", "parent": "#"},
+ {"id": "tg__0.DropPackets", "text": "DropPackets", "parent": "tg__0"}
+ ]
+ self.jstree._create_node(_id)
+
+ self.assertEqual(self.jstree._created_nodes, ['#', 'tg__0', 'tg__0.DropPackets'])
+ self.assertEqual(self.jstree.jstree_data, expected_data)
+
+ def test_format_for_jstree(self):
+ data = [
+ {'data': [0, ], 'name': 'tg__0.DropPackets'},
+ {'data': [548, ], 'name': 'tg__0.LatencyAvg.5'},
+ {'data': [1172, ], 'name': 'tg__0.LatencyAvg.6'},
+ {'data': [1001, ], 'name': 'tg__0.LatencyMax.5'},
+ {'data': [1468, ], 'name': 'tg__0.LatencyMax.6'},
+ {'data': [18.11, ], 'name': 'tg__0.RxThroughput'},
+ {'data': [18.11, ], 'name': 'tg__0.TxThroughput'},
+ {'data': [0, ], 'name': 'tg__1.DropPackets'},
+ {'data': [548, ], 'name': 'tg__1.LatencyAvg.5'},
+ {'data': [1172, ], 'name': 'tg__1.LatencyAvg.6'},
+ {'data': [1001, ], 'name': 'tg__1.LatencyMax.5'},
+ {'data': [1468, ], 'name': 'tg__1.LatencyMax.6'},
+ {'data': [18.1132084505, ], 'name': 'tg__1.RxThroughput'},
+ {'data': [18.1157260383, ], 'name': 'tg__1.TxThroughput'},
+ {'data': [9057888, ], 'name': 'vnf__0.curr_packets_in'},
+ {'data': [0, ], 'name': 'vnf__0.packets_dropped'},
+ {'data': [617825443, ], 'name': 'vnf__0.packets_fwd'},
+ ]
+
+ expected_output = [
+ {"id": "tg__0", "text": "tg__0", "parent": "#"},
+ {"id": "tg__0.DropPackets", "text": "DropPackets", "parent": "tg__0"},
+ {"id": "tg__0.LatencyAvg", "text": "LatencyAvg", "parent": "tg__0"},
+ {"id": "tg__0.LatencyAvg.5", "text": "5", "parent": "tg__0.LatencyAvg"},
+ {"id": "tg__0.LatencyAvg.6", "text": "6", "parent": "tg__0.LatencyAvg"},
+ {"id": "tg__0.LatencyMax", "text": "LatencyMax", "parent": "tg__0"},
+ {"id": "tg__0.LatencyMax.5", "text": "5", "parent": "tg__0.LatencyMax"},
+ {"id": "tg__0.LatencyMax.6", "text": "6", "parent": "tg__0.LatencyMax"},
+ {"id": "tg__0.RxThroughput", "text": "RxThroughput", "parent": "tg__0"},
+ {"id": "tg__0.TxThroughput", "text": "TxThroughput", "parent": "tg__0"},
+ {"id": "tg__1", "text": "tg__1", "parent": "#"},
+ {"id": "tg__1.DropPackets", "text": "DropPackets", "parent": "tg__1"},
+ {"id": "tg__1.LatencyAvg", "text": "LatencyAvg", "parent": "tg__1"},
+ {"id": "tg__1.LatencyAvg.5", "text": "5", "parent": "tg__1.LatencyAvg"},
+ {"id": "tg__1.LatencyAvg.6", "text": "6", "parent": "tg__1.LatencyAvg"},
+ {"id": "tg__1.LatencyMax", "text": "LatencyMax", "parent": "tg__1"},
+ {"id": "tg__1.LatencyMax.5", "text": "5", "parent": "tg__1.LatencyMax"},
+ {"id": "tg__1.LatencyMax.6", "text": "6", "parent": "tg__1.LatencyMax"},
+ {"id": "tg__1.RxThroughput", "text": "RxThroughput", "parent": "tg__1"},
+ {"id": "tg__1.TxThroughput", "text": "TxThroughput", "parent": "tg__1"},
+ {"id": "vnf__0", "text": "vnf__0", "parent": "#"},
+ {"id": "vnf__0.curr_packets_in", "text": "curr_packets_in", "parent": "vnf__0"},
+ {"id": "vnf__0.packets_dropped", "text": "packets_dropped", "parent": "vnf__0"},
+ {"id": "vnf__0.packets_fwd", "text": "packets_fwd", "parent": "vnf__0"},
+ ]
+
+ result = self.jstree.format_for_jstree(data)
+ self.assertEqual(expected_output, result)
class ReportTestCase(unittest.TestCase):
@@ -38,37 +102,69 @@ class ReportTestCase(unittest.TestCase):
def setUp(self):
super(ReportTestCase, self).setUp()
self.param = change_osloobj_to_paras({})
- self.param.yaml_name = [FAKE_YAML_NAME]
- self.param.task_id = [FAKE_TASK_ID]
+ self.param.yaml_name = [GOOD_YAML_NAME]
+ self.param.task_id = [GOOD_TASK_ID]
self.rep = report.Report()
+ def test___init__(self):
+ self.assertEqual([], self.rep.Timestamp)
+ self.assertEqual("", self.rep.yaml_name)
+ self.assertEqual("", self.rep.task_id)
+
+ def test__validate(self):
+ self.rep._validate(GOOD_YAML_NAME, GOOD_TASK_ID)
+ self.assertEqual(GOOD_YAML_NAME, self.rep.yaml_name)
+ self.assertEqual(GOOD_TASK_ID, str(self.rep.task_id))
+
+ def test__validate_invalid_yaml_name(self):
+ with self.assertRaisesRegexp(ValueError, "yaml*"):
+ self.rep._validate(BAD_YAML_NAME, GOOD_TASK_ID)
+
+ def test__validate_invalid_task_id(self):
+ with self.assertRaisesRegexp(ValueError, "task*"):
+ self.rep._validate(GOOD_YAML_NAME, BAD_TASK_ID)
+
+ @mock.patch.object(influx, 'query')
+ def test__get_fieldkeys(self, mock_query):
+ mock_query.return_value = GOOD_DB_FIELDKEYS
+ self.rep.yaml_name = GOOD_YAML_NAME
+ self.rep.task_id = GOOD_TASK_ID
+ self.assertEqual(GOOD_DB_FIELDKEYS, self.rep._get_fieldkeys())
+
+ @mock.patch.object(influx, 'query')
+ def test__get_fieldkeys_nodbclient(self, mock_query):
+ mock_query.side_effect = RuntimeError
+ self.assertRaises(RuntimeError, self.rep._get_fieldkeys)
+
+ @mock.patch.object(influx, 'query')
+ def test__get_fieldkeys_testcase_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, "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
+ self.rep.yaml_name = GOOD_YAML_NAME
+ self.rep.task_id = GOOD_TASK_ID
+ self.assertEqual(GOOD_DB_TASK, self.rep._get_tasks())
+
+ @mock.patch.object(influx, 'query')
+ def test__get_tasks_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)
+
@mock.patch.object(report.Report, '_get_tasks')
@mock.patch.object(report.Report, '_get_fieldkeys')
@mock.patch.object(report.Report, '_validate')
- def test_generate_success(self, mock_valid, mock_keys, mock_tasks):
- mock_tasks.return_value = FAKE_DB_TASK
- mock_keys.return_value = FAKE_DB_FIELDKEYS
+ def test_generate(self, mock_valid, mock_keys, mock_tasks):
+ mock_tasks.return_value = GOOD_DB_TASK
+ mock_keys.return_value = GOOD_DB_FIELDKEYS
self.rep.generate(self.param)
- mock_valid.assert_called_once_with(FAKE_YAML_NAME, FAKE_TASK_ID)
+ mock_valid.assert_called_once_with(GOOD_YAML_NAME, GOOD_TASK_ID)
mock_tasks.assert_called_once_with()
mock_keys.assert_called_once_with()
-
- # pylint: disable=deprecated-method
- def test_invalid_yaml_name(self):
- self.assertRaisesRegexp(ValueError, "yaml*", self.rep._validate,
- 'F@KE_NAME', FAKE_TASK_ID)
-
- # pylint: disable=deprecated-method
- def test_invalid_task_id(self):
- self.assertRaisesRegexp(ValueError, "task*", self.rep._validate,
- FAKE_YAML_NAME, DUMMY_TASK_ID)
-
- @mock.patch('api.utils.influx.query')
- def test_task_not_found(self, mock_query):
- mock_query.return_value = []
- self.rep.yaml_name = FAKE_YAML_NAME
- self.rep.task_id = FAKE_TASK_ID
- # pylint: disable=deprecated-method
- self.assertRaisesRegexp(KeyError, "Task ID", self.rep._get_fieldkeys)
- self.assertRaisesRegexp(KeyError, "Task ID", self.rep._get_tasks)
- # pylint: enable=deprecated-method
+ self.assertEqual(GOOD_TIMESTAMP, self.rep.Timestamp)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
index 4524eb7e6..f17656328 100644
--- a/yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
@@ -21,6 +21,8 @@ from yardstick.network_services.traffic_profile import prox_binsearch
class TestProxBinSearchProfile(unittest.TestCase):
+ THEOR_MAX_THROUGHPUT = 0.00012340000000000002
+
def setUp(self):
self._mock_log_info = mock.patch.object(prox_binsearch.LOG, 'info')
self.mock_log_info = self._mock_log_info.start()
@@ -80,7 +82,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
# Result Samples inc theor_max
result_tuple = {'Actual_throughput': 5e-07,
- 'theor_max_throughput': 7.5e-07,
+ 'theor_max_throughput': self.THEOR_MAX_THROUGHPUT,
'PktSize': 200,
'Status': 'Result'}
@@ -96,7 +98,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
"PktSize": 200,
"RxThroughput": 7.5e-07,
"Throughput": 7.5e-07,
- "TxThroughput": 0.00012340000000000002,
+ "TxThroughput": self.THEOR_MAX_THROUGHPUT,
"Status": 'Success'}
calls = profile.queue.put(success_result_tuple)
@@ -222,6 +224,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
raise RuntimeError(' '.join([str(args), str(runs)]))
if args[2] > 75.0:
return fail_tuple, {}
+
return success_tuple, {}
tp_config = {
@@ -258,7 +261,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
# Result Samples inc theor_max
result_tuple = {'Actual_throughput': 5e-07,
- 'theor_max_throughput': 7.5e-07,
+ 'theor_max_throughput': self.THEOR_MAX_THROUGHPUT,
'PktSize': 200,
"Status": 'Result'}
@@ -274,7 +277,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
"PktSize": 200,
"RxThroughput": 7.5e-07,
"Throughput": 7.5e-07,
- "TxThroughput": 0.00012340000000000002,
+ "TxThroughput": self.THEOR_MAX_THROUGHPUT,
"Status": 'Success'}
calls = profile.queue.put(success_result_tuple)
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
index 894b16e13..6d1d8c6a1 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
@@ -648,6 +648,82 @@ class TestProxSocketHelper(unittest.TestCase):
self.assertListEqual(result, expected)
self.assertTrue(ok)
+ @mock.patch.object(prox_helpers.LOG, 'error')
+ def test_multi_port_stats_diff(self, *args):
+ mock_socket = mock.MagicMock()
+ prox = prox_helpers.ProxSocketHelper(mock_socket)
+ prox.get_string = mock.MagicMock(return_value=(True, '0,1,2,3,4,5;1,1,2,3,4,5'))
+ _, t1 = prox.multi_port_stats([0, 1])
+
+ prox.get_string = mock.MagicMock(return_value=(True, '0,2,4,6,8,6;1,4,8,16,32,6'))
+ _, t2 = prox.multi_port_stats([0, 1])
+
+ prox.get_string = mock.MagicMock(return_value=(True, '0,1,1,1,1,1;1,1,1,1,1,1'))
+ _, t3 = prox.multi_port_stats([0, 1])
+
+ prox.get_string = mock.MagicMock(return_value=(True, '0,2,2,2,2,2;1,2,2,2,2,2'))
+ _, t4 = prox.multi_port_stats([0, 1])
+
+ expected = [[0, 1.0, 2.0, 0, 0, 1], [1, 3.0, 6.0, 0, 0, 1]]
+ result = prox.multi_port_stats_diff(t1, t2, 1)
+
+ self.assertListEqual(result, expected)
+
+ result = prox.multi_port_stats_diff(t4, t3, 1)
+ expected = [[0, 1.0, 1.0, 0, 0, 1], [1, 1.0, 1.0, 0, 0, 1]]
+
+ self.assertListEqual(result, expected)
+
+ prox.get_string = mock.MagicMock(return_value=(True, '0,2,4,6,8,10'))
+ ok, t5 = prox.multi_port_stats([0, 1])
+ self.assertFalse(ok)
+ self.assertListEqual(t5, [])
+
+ result = prox.multi_port_stats_diff(t5, t4, 1)
+ expected = [[0, 0.0, 0.0, 0, 0, 0], [1, 0.0, 0.0, 0, 0, 0]]
+ self.assertListEqual(result, expected)
+
+ prox.get_string = mock.MagicMock(return_value=(True, '0,10,10,20,30,0;1,30,40,50,60,0'))
+ _, t6 = prox.multi_port_stats([0, 1])
+
+ prox.get_string = \
+ mock.MagicMock(return_value=(True, '0,100,100,100,100,0;1,100,100,100,100,0'))
+ _, t7 = prox.multi_port_stats([0, 1])
+
+ result = prox.multi_port_stats_diff(t6, t7, 1)
+ expected = [[0, 0.0, 0.0, 0, 0, 0], [1, 0.0, 0.0, 0, 0, 0]]
+ self.assertListEqual(result, expected)
+
+ result = prox.multi_port_stats_diff(t1, t2, 0)
+ expected = [[0, 0.0, 0.0, 0, 0, 1], [1, 0.0, 0.0, 0, 0, 1]]
+ self.assertListEqual(result, expected)
+
+ @mock.patch.object(prox_helpers.LOG, 'error')
+ def test_multi_port_stats_tuple(self, *args):
+ mock_socket = mock.MagicMock()
+ prox = prox_helpers.ProxSocketHelper(mock_socket)
+ prox.get_string = mock.MagicMock(return_value=(True, '0,1,2,3,4,5;1,1,2,3,4,5'))
+ _, result1 = prox.multi_port_stats([0, 1])
+ prox.get_string = mock.MagicMock(return_value=(True, '0,2,4,6,8,6;1,4,8,16,32,6'))
+ _, result2 = prox.multi_port_stats([0, 1])
+
+ result = prox.multi_port_stats_diff(result1, result2, 1)
+
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
+
+ expected = {'xe0': {'in_packets': 1.0, 'out_packets': 2.0},
+ 'xe1': {'in_packets': 3.0, 'out_packets': 6.0}}
+ live_stats = prox.multi_port_stats_tuple(result, vnfd_helper.ports_iter())
+ self.assertDictEqual(live_stats, expected)
+
+ live_stats = prox.multi_port_stats_tuple(result, None)
+ expected = {}
+ self.assertDictEqual(live_stats, expected)
+
+ live_stats = prox.multi_port_stats_tuple(None, vnfd_helper.ports_iter())
+ self.assertDictEqual(live_stats, expected)
+
def test_port_stats(self):
port_stats = [
','.join(str(n) for n in range(3, 15)),
@@ -1568,8 +1644,83 @@ class TestProxResourceHelper(unittest.TestCase):
helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
helper._queue = queue = mock.MagicMock()
helper._result = {'z': 123}
+
+ helper.client = mock.MagicMock()
+ helper.client.hz.return_value = 1
+ helper.client.multi_port_stats.return_value = \
+ (True, [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]])
+ helper.client.multi_port_stats_diff.return_value = \
+ ([0, 1, 2, 3, 4, 5, 6, 7])
+ helper.client.multi_port_stats_tuple.return_value = \
+ {"xe0": {"in_packets": 1, "out_packets": 2}}
+ helper.resource = resource = mock.MagicMock()
+
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
+ helper.vnfd_helper = vnfd_helper
+
+ resource.check_if_system_agent_running.return_value = 0, '1234'
+ resource.amqp_collect_nfvi_kpi.return_value = 543
+ resource.check_if_system_agent_running.return_value = (0, None)
+
+ queue.empty.return_value = False
+ queue.get.return_value = {'a': 789}
+
+ expected = {'z': 123, 'a': 789,
+ 'collect_stats': {'core': 543},
+ 'live_stats': {'xe0': {'in_packets': 1, 'out_packets': 2}}}
+ result = helper.collect_kpi()
+ self.assertDictEqual(result, expected)
+
+ def test_collect_kpi_no_hz(self):
+ helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
+ helper._queue = queue = mock.MagicMock()
+ helper._result = {'z': 123}
+
+ helper.client = mock.MagicMock()
+ helper.client.multi_port_stats.return_value = \
+ (True, [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]])
+ helper.client.multi_port_stats_diff.return_value = \
+ ([0, 1, 2, 3, 4, 5, 6, 7])
+ helper.client.multi_port_stats_tuple.return_value = \
+ {"xe0": {"in_packets": 1, "out_packets": 2}}
+ helper.resource = resource = mock.MagicMock()
+
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
+ helper.vnfd_helper = vnfd_helper
+
+ resource.check_if_system_agent_running.return_value = 0, '1234'
+ resource.amqp_collect_nfvi_kpi.return_value = 543
+ resource.check_if_system_agent_running.return_value = (0, None)
+
+ queue.empty.return_value = False
+ queue.get.return_value = {'a': 789}
+
+ expected = {'z': 123, 'a': 789,
+ 'collect_stats': {'core': 543},
+ 'live_stats': {'xe0': {'in_packets': 1, 'out_packets': 2}}}
+ result = helper.collect_kpi()
+ self.assertDictEqual(result, expected)
+
+ def test_collect_kpi_bad_data(self):
+ helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
+ helper._queue = queue = mock.MagicMock()
+ helper._result = {'z': 123}
+
+ helper.client = mock.MagicMock()
+ helper.client.multi_port_stats.return_value = \
+ (False, [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]])
+ helper.client.multi_port_stats_diff.return_value = \
+ ([0, 1, 2, 3, 4, 5, 6, 7])
+ helper.client.multi_port_stats_tuple.return_value = \
+ {"xe0": {"in_packets": 1, "out_packets": 2}}
helper.resource = resource = mock.MagicMock()
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
+ helper.vnfd_helper = vnfd_helper
+
resource.check_if_system_agent_running.return_value = 0, '1234'
resource.amqp_collect_nfvi_kpi.return_value = 543
resource.check_if_system_agent_running.return_value = (0, None)
@@ -1577,7 +1728,8 @@ class TestProxResourceHelper(unittest.TestCase):
queue.empty.return_value = False
queue.get.return_value = {'a': 789}
- expected = {'z': 123, 'a': 789, 'collect_stats': {'core': 543}}
+ expected = {'z': 123, 'a': 789,
+ 'collect_stats': {'core': 543}}
result = helper.collect_kpi()
self.assertDictEqual(result, expected)
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
index a7e61da0f..935d3fa30 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
@@ -329,13 +329,27 @@ class TestProxTrafficGen(unittest.TestCase):
}
prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock(
**{"self.check_if_system_agent_running.return_value": [False]})
+
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
+ prox_traffic_gen.resource_helper.vnfd_helper = vnfd_helper
+
+ prox_traffic_gen._vnf_wrapper.resource_helper.client = mock.MagicMock()
+ prox_traffic_gen._vnf_wrapper.resource_helper.client.multi_port_stats.return_value = \
+ [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]]
+ prox_traffic_gen._vnf_wrapper.resource_helper.client.multi_port_stats_diff.return_value = \
+ [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]
+ prox_traffic_gen._vnf_wrapper.resource_helper.client.\
+ multi_port_stats_tuple.return_value = \
+ {"xe0": {"in_packets": 1, "out_packets": 2}}
+
prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="")
expected = {
- 'collect_stats': {},
+ 'collect_stats': {'live_stats': {'xe0': {'in_packets': 1, 'out_packets': 2}}},
'physical_node': 'mock_node'
}
- self.assertEqual(prox_traffic_gen.collect_kpi(), expected)
-
+ result = prox_traffic_gen.collect_kpi()
+ self.assertDictEqual(result, expected)
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
@mock.patch(
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
index 7b937dfb5..8d49cb3f4 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
@@ -16,7 +16,6 @@ from multiprocessing import Process, Queue
import time
import mock
-from six.moves import configparser
import unittest
from yardstick.benchmark.contexts import base as ctx_base
@@ -147,48 +146,6 @@ class TestConfigCreate(unittest.TestCase):
self.assertEqual(config_create.downlink_ports, ['xe1'])
self.assertEqual(config_create.socket, 2)
- def test_dpdk_port_to_link_id(self):
- vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
- config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
- self.assertEqual(config_create.dpdk_port_to_link_id_map, {'xe0': 0, 'xe1': 1})
-
- def test_vpe_initialize(self):
- vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
- config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
- config = configparser.ConfigParser()
- config_create.vpe_initialize(config)
- self.assertEqual(config.get('EAL', 'log_level'), '0')
- self.assertEqual(config.get('PIPELINE0', 'type'), 'MASTER')
- self.assertEqual(config.get('PIPELINE0', 'core'), 's2C0')
- self.assertEqual(config.get('MEMPOOL0', 'pool_size'), '256K')
- self.assertEqual(config.get('MEMPOOL1', 'pool_size'), '2M')
-
- def test_vpe_rxq(self):
- vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
- config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
- config = configparser.ConfigParser()
- config_create.downlink_ports = ['xe0']
- config_create.vpe_rxq(config)
- self.assertEqual(config.get('RXQ0.0', 'mempool'), 'MEMPOOL1')
-
- def test_get_sink_swq(self):
- vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
- config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
- config = configparser.ConfigParser()
- config.add_section('PIPELINE0')
- config.set('PIPELINE0', 'key1', 'value1')
- config.set('PIPELINE0', 'key2', 'value2 SINK')
- config.set('PIPELINE0', 'key3', 'TM value3')
- config.set('PIPELINE0', 'key4', 'value4')
- config.set('PIPELINE0', 'key5', 'the SINK value5')
-
- self.assertEqual(config_create.get_sink_swq(config, 'PIPELINE0', 'key1', 5), 'SWQ-1')
- self.assertEqual(config_create.get_sink_swq(config, 'PIPELINE0', 'key2', 5), 'SWQ-1 SINK0')
- self.assertEqual(config_create.get_sink_swq(config, 'PIPELINE0', 'key3', 5), 'SWQ-1 TM5')
- config_create.sw_q += 1
- self.assertEqual(config_create.get_sink_swq(config, 'PIPELINE0', 'key4', 5), 'SWQ0')
- self.assertEqual(config_create.get_sink_swq(config, 'PIPELINE0', 'key5', 5), 'SWQ0 SINK1')
-
def test_generate_vpe_script(self):
vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
vpe_config_vnf = vpe_vnf.ConfigCreate(vnfd_helper, 2)
@@ -214,36 +171,6 @@ class TestConfigCreate(unittest.TestCase):
self.assertIsInstance(result, str)
self.assertNotEqual(result, '')
- def test_create_vpe_config(self):
- vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
- config_create = vpe_vnf.ConfigCreate(vnfd_helper, 23)
- config_create.uplink_ports = ['xe1']
- with mock.patch.object(config_create, 'vpe_upstream') as mock_up, \
- mock.patch.object(config_create, 'vpe_downstream') as \
- mock_down, \
- mock.patch.object(config_create, 'vpe_tmq') as mock_tmq, \
- mock.patch.object(config_create, 'vpe_initialize') as \
- mock_ini, \
- mock.patch.object(config_create, 'vpe_rxq') as mock_rxq:
- mock_ini_obj = mock.Mock()
- mock_rxq_obj = mock.Mock()
- mock_up_obj = mock.Mock()
- mock_down_obj = mock.Mock()
- mock_tmq_obj = mock.Mock()
- mock_ini.return_value = mock_ini_obj
- mock_rxq.return_value = mock_rxq_obj
- mock_up.return_value = mock_up_obj
- mock_down.return_value = mock_down_obj
- mock_tmq.return_value = mock_tmq_obj
- config_create.create_vpe_config('fake_config_file')
-
- mock_rxq.assert_called_once_with(mock_ini_obj)
- mock_up.assert_called_once_with('fake_config_file', 0)
- mock_down.assert_called_once_with('fake_config_file', 0)
- mock_tmq.assert_called_once_with(mock_down_obj, 0)
- mock_up_obj.write.assert_called_once()
- mock_tmq_obj.write.assert_called_once()
-
class TestVpeApproxVnf(unittest.TestCase):