From 1d8674c2108b03dbb75713a7cd0b224edebb284f Mon Sep 17 00:00:00 2001 From: Oleksandr Naumets Date: Mon, 19 Nov 2018 13:45:32 +0000 Subject: Add vBNG test cases stats processing functionality JIRA: YARDSTICK-1546 Change-Id: I3575223ef8231fb4d574e961360b0f2d90a71749 Signed-off-by: Oleksandr Naumets --- .../libs/ixia_libs/test_ixnet_api.py | 88 ++++++++++++++++++---- 1 file changed, 75 insertions(+), 13 deletions(-) (limited to 'yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py') diff --git a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py index 110224742..38ca26b08 100644 --- a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py +++ b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py @@ -15,8 +15,10 @@ import mock import IxNetwork import unittest +import re from copy import deepcopy +from collections import OrderedDict from yardstick.common import exceptions from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api @@ -633,9 +635,9 @@ class TestIxNextgen(unittest.TestCase): mock.call(self.ixnet_gen.FLOW_STATISTICS, self.ixnet_gen.LATENCY_NAME_MAP)]) - def test__set_flow_tracking(self): + def test_set_flow_tracking(self): self.ixnet_gen._ixnet.getList.return_value = ['traffic_item'] - self.ixnet_gen._set_flow_tracking(track_by=['vlanVlanId0']) + self.ixnet_gen.set_flow_tracking(track_by=['vlanVlanId0']) self.ixnet_gen.ixnet.setAttribute.assert_called_once_with( 'traffic_item/tracking', '-trackBy', ['vlanVlanId0']) self.assertEqual(self.ixnet.commit.call_count, 1) @@ -653,17 +655,77 @@ class TestIxNextgen(unittest.TestCase): 'encapsulation', '-offset', 'IPv4 TOS Precedence') self.assertEqual(self.ixnet.commit.call_count, 2) - def test_get_pppoe_scenario_statistics(self): - with mock.patch.object(self.ixnet_gen, '_build_stats_map') as \ - mock_build_stats: - self.ixnet_gen.get_pppoe_scenario_statistics() - - mock_build_stats.assert_any_call(self.ixnet_gen.PORT_STATISTICS, - self.ixnet_gen.PORT_STATS_NAME_MAP) - mock_build_stats.assert_any_call(self.ixnet_gen.FLOW_STATISTICS, - self.ixnet_gen.LATENCY_NAME_MAP) - mock_build_stats.assert_any_call(self.ixnet_gen.PPPOX_CLIENT_PER_PORT, - self.ixnet_gen.PPPOX_CLIENT_PER_PORT_NAME_MAP) + def test__get_view_page_stats(self): + expected_stats = [ + {'header1': 'row1_1', 'header2': 'row1_2'}, + {'header1': 'row2_1', 'header2': 'row2_2'} + ] + self.ixnet_gen._ixnet.getAttribute.side_effect = [ + ['header1', 'header2'], + [ + [['row1_1', 'row1_2']], + [['row2_1', 'row2_2']] + ] + ] + stats = self.ixnet_gen._get_view_page_stats('view_obj') + self.assertListEqual(stats, expected_stats) + + @mock.patch.object(ixnet_api.IxNextgen, '_get_view_page_stats') + def test_get_pppoe_scenario_statistics(self, mock_get_view): + + pattern = re.compile('Flow 2') + + expected_stats = { + 'port_statistics': [{ + 'port_1': 'port_stat1', + 'port_2': 'port_stat2' + }], + 'flow_statistic': [{ + 'flow_1': 'flow_stat1', + 'flow_2': 'flow_stat2' + }], + 'pppox_client_per_port': [{ + 'sub_1': 'sub_stat1', + 'sub_2': 'sub_stat2' + }] + } + + pppoe_scenario_stats = OrderedDict([ + ('port_statistics', 'view_obj'), + ('flow_statistic', 'view_obj'), + ('pppox_client_per_port', 'view_obj') + ]) + + pppoe_scenario_stats_map = { + 'port_statistics': {'port_1': 'Port 1', + 'port_2': 'Port 2'}, + 'flow_statistic': {'flow_1': 'Flow 1', + 'flow_2': pattern}, + 'pppox_client_per_port': {'sub_1': 'Sub 1', + 'sub_2': 'Sub 2'} + } + + # All stats keys + port_stats = [{'Port 1': 'port_stat1', + 'Port 2': 'port_stat2', + 'Port 3': 'port_stat3'}] + flows_stats = [{'Flow 1': 'flow_stat1', + 'Flow 2': 'flow_stat2', + 'Flow 3': 'flow_stat3'}] + pppoe_sub_stats = [{'Sub 1': 'sub_stat1', + 'Sub 2': 'sub_stat2', + 'Sub 3': 'sub_stat3'}] + + mock_get_view.side_effect = [port_stats, flows_stats, pppoe_sub_stats] + self.ixnet_gen._ixnet.getAttribute.return_value = '1' + + with mock.patch.multiple(ixnet_api.IxNextgen, + PPPOE_SCENARIO_STATS=pppoe_scenario_stats, + PPPOE_SCENARIO_STATS_MAP=pppoe_scenario_stats_map): + stats = self.ixnet_gen.get_pppoe_scenario_statistics() + self.assertDictEqual(stats, expected_stats) + self.assertEqual(self.ixnet_gen.ixnet.getAttribute.call_count, 6) + self.ixnet_gen.ixnet.setAttribute.assert_not_called() def test__update_ipv4_address(self): with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item', -- cgit 1.2.3-korg