diff options
Diffstat (limited to 'tests/unit/network_services/traffic_profile')
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_base.py | 43 | ||||
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_fixed.py | 4 | ||||
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_http.py | 10 | ||||
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py | 13 | ||||
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_prox_profile.py | 21 | ||||
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_rfc2544.py | 80 | ||||
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py (renamed from tests/unit/network_services/traffic_profile/test_traffic_profile.py) | 34 |
7 files changed, 100 insertions, 105 deletions
diff --git a/tests/unit/network_services/traffic_profile/test_base.py b/tests/unit/network_services/traffic_profile/test_base.py index 290610361..3b8804976 100644 --- a/tests/unit/network_services/traffic_profile/test_base.py +++ b/tests/unit/network_services/traffic_profile/test_base.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,16 +11,16 @@ # 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. -# -# Unittest for yardstick.network_services.traffic_profile.test_base +import sys -from __future__ import absolute_import -import unittest import mock +import unittest -from yardstick.network_services.traffic_profile.base import \ - TrafficProfile, DummyProfile +from yardstick.common import exceptions +from yardstick.network_services import traffic_profile as tprofile_package +from yardstick.network_services.traffic_profile import base +from yardstick import tests as y_tests class TestTrafficProfile(unittest.TestCase): @@ -43,20 +41,33 @@ class TestTrafficProfile(unittest.TestCase): return _mock def test___init__(self): - traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) + traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE) self.assertEqual(self.TRAFFIC_PROFILE, traffic_profile.params) def test_execute(self): - traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) - self.assertRaises(NotImplementedError, traffic_profile.execute_traffic, {}) + traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE) + self.assertRaises(NotImplementedError, + traffic_profile.execute_traffic, {}) + + def test_get_existing_traffic_profile(self): + traffic_profile_list = [ + 'RFC2544Profile', 'FixedProfile', 'TrafficProfileGenericHTTP', + 'IXIARFC2544Profile', 'ProxACLProfile', 'ProxBinSearchProfile', + 'ProxProfile', 'ProxRampProfile'] + with mock.patch.dict(sys.modules, y_tests.STL_MOCKS): + tprofile_package.register_modules() + + for tp in traffic_profile_list: + traffic_profile = base.TrafficProfile.get( + {'traffic_profile': {'traffic_type': tp}}) + self.assertEqual(tp, traffic_profile.__class__.__name__) - def test_get(self): - traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) - self.assertRaises(RuntimeError, traffic_profile.get, - self.TRAFFIC_PROFILE) + def test_get_non_existing_traffic_profile(self): + self.assertRaises(exceptions.TrafficProfileNotImplemented, + base.TrafficProfile.get, self.TRAFFIC_PROFILE) class TestDummyProfile(unittest.TestCase): def test_execute(self): - dummy_profile = DummyProfile(TrafficProfile) + dummy_profile = base.DummyProfile(base.TrafficProfile) self.assertIsNone(dummy_profile.execute({})) diff --git a/tests/unit/network_services/traffic_profile/test_fixed.py b/tests/unit/network_services/traffic_profile/test_fixed.py index eb182a2fb..dec94964b 100644 --- a/tests/unit/network_services/traffic_profile/test_fixed.py +++ b/tests/unit/network_services/traffic_profile/test_fixed.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -119,4 +117,4 @@ class TestFixedProfile(unittest.TestCase): fixed_profile = FixedProfile(self.TRAFFIC_PROFILE) fixed_profile.params = self.TRAFFIC_PROFILE fixed_profile.first_run = True - self.assertEqual(None, fixed_profile.execute(traffic_generator)) + self.assertIsNone(fixed_profile.execute(traffic_generator)) diff --git a/tests/unit/network_services/traffic_profile/test_http.py b/tests/unit/network_services/traffic_profile/test_http.py index e818a0528..5d8029ea0 100644 --- a/tests/unit/network_services/traffic_profile/test_http.py +++ b/tests/unit/network_services/traffic_profile/test_http.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,13 +31,11 @@ class TestTrafficProfileGenericHTTP(unittest.TestCase): traffic_profile_generic_htt_p = \ TrafficProfileGenericHTTP(TrafficProfile) traffic_generator = {} - self.assertEqual(None, - traffic_profile_generic_htt_p.execute( - traffic_generator)) + self.assertIsNone( + traffic_profile_generic_htt_p.execute(traffic_generator)) def test__send_http_request(self): traffic_profile_generic_htt_p = \ TrafficProfileGenericHTTP(TrafficProfile) - self.assertEqual(None, - traffic_profile_generic_htt_p._send_http_request( + self.assertIsNone(traffic_profile_generic_htt_p._send_http_request( "10.1.1.1", "250", "/req")) diff --git a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py index f13945abf..e8910d62b 100644 --- a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py +++ b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +27,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) stl_patch.start() if stl_patch: - from yardstick.network_services.traffic_profile.traffic_profile \ + from yardstick.network_services.traffic_profile.trex_traffic_profile \ import TrexProfile from yardstick.network_services.traffic_profile.ixia_rfc2544 import \ IXIARFC2544Profile @@ -474,7 +472,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): r_f_c2544_profile.get_multiplier = mock.Mock() r_f_c2544_profile._ixia_traffic_generate = mock.Mock() ixia_obj = mock.MagicMock() - self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj)) + self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj)) def test_update_traffic_profile(self): traffic_generator = mock.Mock(autospec=TrexProfile) @@ -609,10 +607,5 @@ class TestIXIARFC2544Profile(unittest.TestCase): mock.Mock(return_value={}) r_f_c2544_profile.full_profile = {} r_f_c2544_profile._ixia_traffic_generate = mock.Mock() - self.assertEqual( - None, + self.assertIsNone( r_f_c2544_profile.start_ixia_latency(traffic_generator, ixia_obj)) - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/unit/network_services/traffic_profile/test_prox_profile.py b/tests/unit/network_services/traffic_profile/test_prox_profile.py index 078e72b8e..e5b36096f 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -31,14 +31,25 @@ if stl_patch: class TestProxProfile(unittest.TestCase): + def test_sort_vpci(self): + traffic_generator = mock.Mock() + interface_1 = {'virtual-interface': {'vpci': 'id1'}, 'name': 'name1'} + interface_2 = {'virtual-interface': {'vpci': 'id2'}, 'name': 'name2'} + interface_3 = {'virtual-interface': {'vpci': 'id3'}, 'name': 'name3'} + interfaces = [interface_2, interface_3, interface_1] + traffic_generator.vnfd_helper = { + 'vdu': [{'external-interface': interfaces}]} + output = ProxProfile.sort_vpci(traffic_generator) + self.assertEqual([interface_1, interface_2, interface_3], output) + def test_fill_samples(self): samples = {} + traffic_generator = mock.MagicMock() - traffic_generator.vpci_if_name_ascending = [ + interfaces = [ ['id1', 'name1'], - ['id2', 'name2'], + ['id2', 'name2'] ] - traffic_generator.resource_helper.sut.port_stats.side_effect = [ list(range(12)), list(range(10, 22)), @@ -54,7 +65,9 @@ class TestProxProfile(unittest.TestCase): 'out_packets': 17, }, } - ProxProfile.fill_samples(samples, traffic_generator) + with mock.patch.object(ProxProfile, 'sort_vpci', return_value=interfaces): + ProxProfile.fill_samples(samples, traffic_generator) + self.assertDictEqual(samples, expected) def test_init(self): diff --git a/tests/unit/network_services/traffic_profile/test_rfc2544.py b/tests/unit/network_services/traffic_profile/test_rfc2544.py index 221233710..21c8f6d5b 100644 --- a/tests/unit/network_services/traffic_profile/test_rfc2544.py +++ b/tests/unit/network_services/traffic_profile/test_rfc2544.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +13,6 @@ # limitations under the License. # -from __future__ import absolute_import -from __future__ import division - import unittest import mock @@ -29,7 +24,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) stl_patch.start() if stl_patch: - from yardstick.network_services.traffic_profile.traffic_profile \ + from yardstick.network_services.traffic_profile.trex_traffic_profile \ import TrexProfile from yardstick.network_services.traffic_profile.rfc2544 import \ RFC2544Profile @@ -51,29 +46,29 @@ class TestRFC2544Profile(unittest.TestCase): 'traffic_profile': {'traffic_type': 'RFC2544Profile', 'frame_rate': 100}, 'downlink_0': {'ipv4': - {'outer_l2': {'framesize': - {'64B': '100', '1518B': '0', - '128B': '0', '1400B': '0', - '256B': '0', '373b': '0', - '570B': '0'}}, - 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255', - 'proto': 'udp', - 'srcip4': '90.90.1.1-90.105.255.255', - 'dscp': 0, 'ttl': 32, 'count': 1}, - 'outer_l4': {'srcport': '2001', - 'dsrport': '1234', 'count': 1}}}, + {'outer_l2': {'framesize': + {'64B': '100', '1518B': '0', + '128B': '0', '1400B': '0', + '256B': '0', '373b': '0', + '570B': '0'}}, + 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255', + 'proto': 'udp', + 'srcip4': '90.90.1.1-90.105.255.255', + 'dscp': 0, 'ttl': 32, 'count': 1}, + 'outer_l4': {'srcport': '2001', + 'dsrport': '1234', 'count': 1}}}, 'uplink_0': {'ipv4': - {'outer_l2': {'framesize': - {'64B': '100', '1518B': '0', - '128B': '0', '1400B': '0', - '256B': '0', '373b': '0', - '570B': '0'}}, - 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255', - 'proto': 'udp', - 'srcip4': '1.1.1.1-1.15.255.255', - 'dscp': 0, 'ttl': 32, 'count': 1}, - 'outer_l4': {'dstport': '2001', - 'srcport': '1234', 'count': 1}}}, + {'outer_l2': {'framesize': + {'64B': '100', '1518B': '0', + '128B': '0', '1400B': '0', + '256B': '0', '373b': '0', + '570B': '0'}}, + 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255', + 'proto': 'udp', + 'srcip4': '1.1.1.1-1.15.255.255', + 'dscp': 0, 'ttl': 32, 'count': 1}, + 'outer_l4': {'dstport': '2001', + 'srcport': '1234', 'count': 1}}}, 'schema': 'isb:traffic_profile:0.1'} def test___init__(self): @@ -86,12 +81,11 @@ class TestRFC2544Profile(unittest.TestCase): "uplink_0": ["xe0"], "downlink_0": ["xe1"], } - traffic_generator.client = \ - mock.Mock(return_value=True) + traffic_generator.client.return_value = True r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE r_f_c2544_profile.first_run = True - self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator)) + self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator)) def test_get_drop_percentage(self): traffic_generator = mock.Mock(autospec=TrexProfile) @@ -99,7 +93,7 @@ class TestRFC2544Profile(unittest.TestCase): "uplink_0": ["xe0"], "downlink_0": ["xe1"], } - traffic_generator.client = mock.Mock(return_value=True) + traffic_generator.client.return_value = True r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE @@ -133,7 +127,7 @@ class TestRFC2544Profile(unittest.TestCase): 'rx_throughput_fps': 20, }, } - traffic_generator.generate_samples = mock.MagicMock(return_value=samples) + traffic_generator.generate_samples.return_value = samples traffic_generator.RUN_DURATION = 30 traffic_generator.rfc2544_helper.tolerance_low = 0.0001 traffic_generator.rfc2544_helper.tolerance_high = 0.0001 @@ -164,8 +158,6 @@ class TestRFC2544Profile(unittest.TestCase): "in_packets": 1000, "out_packets": 1002, } - tol_min = 0.0 - tolerance = 1.0 expected = { 'DropPercentage': 0.1996, 'RxThroughput': 33.333333333333336, @@ -181,7 +173,8 @@ class TestRFC2544Profile(unittest.TestCase): 'rx_throughput_fps': 20, }, } - traffic_generator.generate_samples = mock.MagicMock(return_value=samples) + traffic_generator.generate_samples = mock.MagicMock( + return_value=samples) traffic_generator.RUN_DURATION = 30 traffic_generator.rfc2544_helper.tolerance_low = 0.0001 traffic_generator.rfc2544_helper.tolerance_high = 0.0001 @@ -198,7 +191,7 @@ class TestRFC2544Profile(unittest.TestCase): mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE - self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator)) + self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator)) samples = {} for ifname in range(1): name = "xe{}".format(ifname) @@ -208,8 +201,6 @@ class TestRFC2544Profile(unittest.TestCase): "tx_throughput_mbps": 10, "in_packets": 1000, "out_packets": 0} - tol_min = 0.0 - tolerance = 0.0 r_f_c2544_profile.throughput_max = 0 expected = { 'DropPercentage': 100.0, 'RxThroughput': 100 / 3.0, @@ -221,7 +212,7 @@ class TestRFC2544Profile(unittest.TestCase): 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20 } } - traffic_generator.generate_samples = mock.MagicMock(return_value=samples) + traffic_generator.generate_samples = mock.Mock(return_value=samples) traffic_generator.RUN_DURATION = 30 traffic_generator.rfc2544_helper.tolerance_low = 0.0001 traffic_generator.rfc2544_helper.tolerance_high = 0.0001 @@ -281,10 +272,5 @@ class TestRFC2544Profile(unittest.TestCase): r_f_c2544_profile.calculate_pps = mock.Mock(return_value=[2274546.67, 1.0]) - self.assertEqual(None, - r_f_c2544_profile.execute_latency(traffic_generator, - samples)) - - -if __name__ == '__main__': - unittest.main() + self.assertIsNone(r_f_c2544_profile.execute_latency(traffic_generator, + samples)) diff --git a/tests/unit/network_services/traffic_profile/test_traffic_profile.py b/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py index 37b9a08d0..d1009a5e8 100644 --- a/tests/unit/network_services/traffic_profile/test_traffic_profile.py +++ b/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,16 +27,16 @@ stl_patch.start() if stl_patch: from yardstick.network_services.traffic_profile.base import TrafficProfile - from yardstick.network_services.traffic_profile.traffic_profile import TrexProfile - from yardstick.network_services.traffic_profile.traffic_profile import SRC - from yardstick.network_services.traffic_profile.traffic_profile import DST - from yardstick.network_services.traffic_profile.traffic_profile import ETHERNET - from yardstick.network_services.traffic_profile.traffic_profile import IP - from yardstick.network_services.traffic_profile.traffic_profile import IPv6 - from yardstick.network_services.traffic_profile.traffic_profile import UDP - from yardstick.network_services.traffic_profile.traffic_profile import SRC_PORT - from yardstick.network_services.traffic_profile.traffic_profile import DST_PORT - from yardstick.network_services.traffic_profile.traffic_profile import TYPE_OF_SERVICE + from yardstick.network_services.traffic_profile.trex_traffic_profile import TrexProfile + from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC + from yardstick.network_services.traffic_profile.trex_traffic_profile import DST + from yardstick.network_services.traffic_profile.trex_traffic_profile import ETHERNET + from yardstick.network_services.traffic_profile.trex_traffic_profile import IP + from yardstick.network_services.traffic_profile.trex_traffic_profile import IPv6 + from yardstick.network_services.traffic_profile.trex_traffic_profile import UDP + from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC_PORT + from yardstick.network_services.traffic_profile.trex_traffic_profile import DST_PORT + from yardstick.network_services.traffic_profile.trex_traffic_profile import TYPE_OF_SERVICE class TestTrexProfile(unittest.TestCase): @@ -153,11 +151,11 @@ class TestTrexProfile(unittest.TestCase): trex_profile = \ TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_qinq(qinq)) + self.assertIsNone(trex_profile.set_qinq(qinq)) qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0}, "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}} - self.assertEqual(None, trex_profile.set_qinq(qinq)) + self.assertIsNone(trex_profile.set_qinq(qinq)) def test__set_outer_l2_fields(self): trex_profile = \ @@ -166,14 +164,14 @@ class TestTrexProfile(unittest.TestCase): "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}} outer_l2 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l2'] outer_l2['QinQ'] = qinq - self.assertEqual(None, trex_profile._set_outer_l2_fields(outer_l2)) + self.assertIsNone(trex_profile._set_outer_l2_fields(outer_l2)) def test__set_outer_l3v4_fields(self): trex_profile = \ TrexProfile(TrafficProfile) outer_l3v4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l3v4'] outer_l3v4['proto'] = 'tcp' - self.assertEqual(None, trex_profile._set_outer_l3v4_fields(outer_l3v4)) + self.assertIsNone(trex_profile._set_outer_l3v4_fields(outer_l3v4)) def test__set_outer_l3v6_fields(self): trex_profile = \ @@ -182,13 +180,13 @@ class TestTrexProfile(unittest.TestCase): outer_l3v6['proto'] = 'tcp' outer_l3v6['tc'] = 1 outer_l3v6['hlim'] = 10 - self.assertEqual(None, trex_profile._set_outer_l3v6_fields(outer_l3v6)) + self.assertIsNone(trex_profile._set_outer_l3v6_fields(outer_l3v6)) def test__set_outer_l4_fields(self): trex_profile = \ TrexProfile(TrafficProfile) outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4'] - self.assertEqual(None, trex_profile._set_outer_l4_fields(outer_l4)) + self.assertIsNone(trex_profile._set_outer_l4_fields(outer_l4)) def test_get_streams(self): trex_profile = \ |