aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/network_services/traffic_profile
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/network_services/traffic_profile')
-rw-r--r--tests/unit/network_services/traffic_profile/test_base.py43
-rw-r--r--tests/unit/network_services/traffic_profile/test_fixed.py4
-rw-r--r--tests/unit/network_services/traffic_profile/test_http.py10
-rw-r--r--tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py71
-rw-r--r--tests/unit/network_services/traffic_profile/test_prox_binsearch.py94
-rw-r--r--tests/unit/network_services/traffic_profile/test_rfc2544.py80
-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)79
7 files changed, 221 insertions, 160 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 616921e33..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
@@ -179,9 +177,7 @@ class TestIXIARFC2544Profile(unittest.TestCase):
"dst_mac_0": "00:00:00:00:00:03",
"dst_mac_1": "00:00:00:00:00:04",
"dst_mac_2": "00:00:00:00:00:04"}
- result = r_f_c2544_profile._get_ixia_traffic_profile(
- self.PROFILE, mac, xfile="tmp",
- static_traffic=STATIC_TRAFFIC)
+ result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
self.assertIsNotNone(result)
def test_get_ixia_traffic_profile(self):
@@ -225,7 +221,6 @@ class TestIXIARFC2544Profile(unittest.TestCase):
"proto": "udp",
"srcip4": "152.16.40.20",
"ttl": 32,
- "count": "1"
},
"outer_l4": {
"dstport": "2001",
@@ -260,7 +255,6 @@ class TestIXIARFC2544Profile(unittest.TestCase):
"proto": "udp",
"srcip4": "152.16.40.20",
"ttl": 32,
- "count": "1"
},
"outer_l3v6": {
"count": 1024,
@@ -269,7 +263,6 @@ class TestIXIARFC2544Profile(unittest.TestCase):
"proto": "udp",
"srcip4": "152.16.40.20",
"ttl": 32,
- "count": "1"
},
"outer_l4": {
"dstport": "1234",
@@ -289,12 +282,11 @@ class TestIXIARFC2544Profile(unittest.TestCase):
"dst_mac_0": "00:00:00:00:00:03",
"dst_mac_1": "00:00:00:00:00:04",
"dst_mac_2": "00:00:00:00:00:04"}
- result = r_f_c2544_profile._get_ixia_traffic_profile(
- self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC)
+ result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
self.assertIsNotNone(result)
@mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
- def test_get_ixia_traffic_profile_v6(self, mock_open):
+ def test_get_ixia_traffic_profile_v6(self, *args):
traffic_generator = mock.Mock(autospec=TrexProfile)
traffic_generator.my_ports = [0, 1]
traffic_generator.uplink_ports = [-1]
@@ -435,8 +427,7 @@ class TestIXIARFC2544Profile(unittest.TestCase):
'outer_l4': {'dstport': '2001',
'srcport': '1234'}}},
'schema': 'isb:traffic_profile:0.1'}
- result = r_f_c2544_profile._get_ixia_traffic_profile(
- profile_data, mac, static_traffic=STATIC_TRAFFIC)
+ result = r_f_c2544_profile._get_ixia_traffic_profile(profile_data, mac)
self.assertIsNotNone(result)
def test__get_ixia_traffic_profile_default_args(self):
@@ -459,8 +450,7 @@ class TestIXIARFC2544Profile(unittest.TestCase):
ixia_obj = mock.MagicMock()
r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
r_f_c2544_profile.rate = 100
- result = r_f_c2544_profile._ixia_traffic_generate(traffic_generator,
- traffic, ixia_obj)
+ result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj)
self.assertIsNone(result)
def test_execute(self):
@@ -482,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)
@@ -511,13 +501,6 @@ class TestIXIARFC2544Profile(unittest.TestCase):
self.assertEqual(r_f_c2544_profile.ports, ports_expected)
def test_get_drop_percentage(self):
- traffic_generator = mock.Mock(autospec=TrexProfile)
- traffic_generator.networks = {
- "uplink_0": ["xe0"],
- "downlink_0": ["xe1"],
- }
- traffic_generator.client = \
- mock.Mock(return_value=True)
r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
r_f_c2544_profile.params = self.PROFILE
ixia_obj = mock.MagicMock()
@@ -541,17 +524,11 @@ class TestIXIARFC2544Profile(unittest.TestCase):
"out_packets": 1000}
tol_min = 100.0
tolerance = 0.0
- self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
- traffic_generator, samples,
- tol_min, tolerance, ixia_obj))
+ self.assertIsNotNone(
+ r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
+ ixia_obj))
def test_get_drop_percentage_update(self):
- traffic_generator = mock.Mock(autospec=TrexProfile)
- traffic_generator.my_ports = [0, 1]
- traffic_generator.uplink_ports = [0]
- traffic_generator.downlink_ports = [1]
- traffic_generator.client = \
- mock.Mock(return_value=True)
r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
r_f_c2544_profile.params = self.PROFILE
ixia_obj = mock.MagicMock()
@@ -575,17 +552,11 @@ class TestIXIARFC2544Profile(unittest.TestCase):
"out_packets": 1002}
tol_min = 0.0
tolerance = 1.0
- self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
- traffic_generator, samples,
- tol_min, tolerance, ixia_obj))
+ self.assertIsNotNone(
+ r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
+ ixia_obj))
def test_get_drop_percentage_div_zero(self):
- traffic_generator = mock.Mock(autospec=TrexProfile)
- traffic_generator.my_ports = [0, 1]
- traffic_generator.uplink_ports = [0]
- traffic_generator.downlink_ports = [1]
- traffic_generator.client = \
- mock.Mock(return_value=True)
r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
r_f_c2544_profile.params = self.PROFILE
ixia_obj = mock.MagicMock()
@@ -610,9 +581,9 @@ class TestIXIARFC2544Profile(unittest.TestCase):
tol_min = 0.0
tolerance = 0.0
r_f_c2544_profile.tmp_throughput = 0
- self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
- traffic_generator, samples,
- tol_min, tolerance, ixia_obj))
+ self.assertIsNotNone(
+ r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
+ ixia_obj))
def test_get_multiplier(self):
r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
@@ -636,11 +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,
- r_f_c2544_profile.start_ixia_latency(traffic_generator,
- ixia_obj))
-
-
-if __name__ == '__main__':
- unittest.main()
+ self.assertIsNone(
+ r_f_c2544_profile.start_ixia_latency(traffic_generator, ixia_obj))
diff --git a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
index c1f1c825b..1b4189b48 100644
--- a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
+++ b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
@@ -32,7 +32,7 @@ if stl_patch:
class TestProxBinSearchProfile(unittest.TestCase):
def test_execute_1(self):
- def target(*args, **kwargs):
+ def target(*args, **_):
runs.append(args[2])
if args[2] < 0 or args[2] > 100:
raise RuntimeError(' '.join([str(args), str(runs)]))
@@ -43,6 +43,8 @@ class TestProxBinSearchProfile(unittest.TestCase):
tp_config = {
'traffic_profile': {
'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
},
}
@@ -61,11 +63,47 @@ class TestProxBinSearchProfile(unittest.TestCase):
profile.execute_traffic(traffic_generator)
self.assertEqual(round(profile.current_lower, 2), 74.69)
- self.assertEqual(round(profile.current_upper, 2), 75.39)
- self.assertEqual(len(runs), 8)
+ self.assertEqual(round(profile.current_upper, 2), 76.09)
+ self.assertEqual(len(runs), 7)
+
+ # Result Samples inc theor_max
+ result_tuple = {"Result_Actual_throughput": 7.5e-07,
+ "Result_theor_max_throughput": 0.00012340000000000002,
+ "Result_pktSize": 200}
+ profile.queue.put.assert_called_with(result_tuple)
+
+ success_result_tuple = {"Success_CurrentDropPackets": 0.5,
+ "Success_DropPackets": 0.5,
+ "Success_LatencyAvg": 5.3,
+ "Success_LatencyMax": 5.2,
+ "Success_LatencyMin": 5.1,
+ "Success_PktSize": 200,
+ "Success_RxThroughput": 7.5e-07,
+ "Success_Throughput": 7.5e-07,
+ "Success_TxThroughput": 0.00012340000000000002}
+
+ calls = profile.queue.put(success_result_tuple)
+ profile.queue.put.assert_has_calls(calls)
+
+ success_result_tuple2 = {"Success_CurrentDropPackets": 0.5,
+ "Success_DropPackets": 0.5,
+ "Success_LatencyAvg": 5.3,
+ "Success_LatencyMax": 5.2,
+ "Success_LatencyMin": 5.1,
+ "Success_PktSize": 200,
+ "Success_RxThroughput": 7.5e-07,
+ "Success_Throughput": 7.5e-07,
+ "Success_TxThroughput": 123.4,
+ "Success_can_be_lost": 409600,
+ "Success_drop_total": 20480,
+ "Success_rx_total": 4075520,
+ "Success_tx_total": 4096000}
+
+ calls = profile.queue.put(success_result_tuple2)
+ profile.queue.put.assert_has_calls(calls)
def test_execute_2(self):
- def target(*args, **kwargs):
+ def target(*args, **_):
runs.append(args[2])
if args[2] < 0 or args[2] > 100:
raise RuntimeError(' '.join([str(args), str(runs)]))
@@ -77,6 +115,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
'traffic_profile': {
'packet_sizes': [200],
'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
},
}
@@ -97,3 +136,50 @@ class TestProxBinSearchProfile(unittest.TestCase):
self.assertEqual(round(profile.current_lower, 2), 24.06)
self.assertEqual(round(profile.current_upper, 2), 25.47)
self.assertEqual(len(runs), 7)
+
+ def test_execute_3(self):
+ def target(*args, **_):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 75.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+
+ profile_helper = mock.MagicMock()
+ profile_helper.run_test = target
+
+ profile = ProxBinSearchProfile(tp_config)
+ profile.init(mock.MagicMock())
+ profile._profile_helper = profile_helper
+
+ profile.upper_bound = 100.0
+ profile.lower_bound = 99.0
+ profile.execute_traffic(traffic_generator)
+
+
+ # Result Samples
+ result_tuple = {"Result_theor_max_throughput": 0, "Result_pktSize": 200}
+ profile.queue.put.assert_called_with(result_tuple)
+
+ # Check for success_ tuple (None expected)
+ calls = profile.queue.put.mock_calls
+ for call in calls:
+ for call_detail in call[1]:
+ for k in call_detail:
+ if "Success_" in k:
+ self.assertRaises(AttributeError)
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 0bb0a88a6..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");
@@ -13,14 +11,15 @@
# 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.
-#
-from __future__ import absolute_import
+import ipaddress
-import unittest
import mock
+import six
+import unittest
from tests.unit import STL_MOCKS
+from yardstick.common import exceptions as y_exc
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
@@ -28,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):
@@ -152,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 = \
@@ -165,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 = \
@@ -181,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 = \
@@ -215,11 +214,27 @@ class TestTrexProfile(unittest.TestCase):
TrexProfile(TrafficProfile)
self.assertEqual({}, trex_profile.generate_imix_data(False))
- def test__get_start_end_ipv6(self):
- trex_profile = \
- TrexProfile(TrafficProfile)
- self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6,
- "1.1.1.3", "1.1.1.1")
+ def test__count_ip_ipv4(self):
+ start, end, count = TrexProfile._count_ip('1.1.1.1', '1.2.3.4')
+ self.assertEqual('1.1.1.1', str(start))
+ self.assertEqual('1.2.3.4', str(end))
+ diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) -
+ int(ipaddress.IPv4Address(six.u('1.1.1.1'))))
+ self.assertEqual(diff, count)
+
+ def test__count_ip_ipv6(self):
+ start_ip = '0064:ff9b:0:0:0:0:9810:6414'
+ end_ip = '0064:ff9b:0:0:0:0:9810:6420'
+ start, end, count = TrexProfile._count_ip(start_ip, end_ip)
+ self.assertEqual(0x98106414, start)
+ self.assertEqual(0x98106420, end)
+ self.assertEqual(0x98106420 - 0x98106414, count)
+
+ def test__count_ip_ipv6_exception(self):
+ start_ip = '0064:ff9b:0:0:0:0:9810:6420'
+ end_ip = '0064:ff9b:0:0:0:0:9810:6414'
+ with self.assertRaises(y_exc.IPv6RangeError):
+ TrexProfile._count_ip(start_ip, end_ip)
def test__dscp_range_action_partial_actual_count_zero(self):
traffic_profile = TrexProfile(TrafficProfile)
@@ -258,13 +273,17 @@ class TestTrexProfile(unittest.TestCase):
def test__general_single_action_partial(self):
trex_profile = TrexProfile(TrafficProfile)
- trex_profile._general_single_action_partial(ETHERNET)(SRC)(self.EXAMPLE_ETHERNET_ADDR)
- self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, trex_profile.ether_packet.src)
+ trex_profile._general_single_action_partial(ETHERNET)(SRC)(
+ self.EXAMPLE_ETHERNET_ADDR)
+ self.assertEqual(self.EXAMPLE_ETHERNET_ADDR,
+ trex_profile.ether_packet.src)
- trex_profile._general_single_action_partial(IP)(DST)(self.EXAMPLE_IP_ADDR)
+ trex_profile._general_single_action_partial(IP)(DST)(
+ self.EXAMPLE_IP_ADDR)
self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
- trex_profile._general_single_action_partial(IPv6)(DST)(self.EXAMPLE_IPv6_ADDR)
+ trex_profile._general_single_action_partial(IPv6)(DST)(
+ self.EXAMPLE_IPv6_ADDR)
self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060)