NSB traffic_profile: fix pylint warnings and return partial 31/52131/3
authorRoss Brattain <ross.b.brattain@intel.com>
Wed, 14 Feb 2018 05:11:11 +0000 (21:11 -0800)
committerEmma Foley <emma.l.foley@intel.com>
Wed, 14 Feb 2018 11:04:21 +0000 (11:04 +0000)
also fix unittests

Change-Id: Ie3026f5a0df8e690271afb71fe36ac531cbae2a0
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
tests/unit/network_services/traffic_profile/test_traffic_profile.py
yardstick/network_services/traffic_profile/traffic_profile.py

index 8355c85..0bb0a88 100644 (file)
@@ -22,7 +22,6 @@ import mock
 
 from tests.unit import STL_MOCKS
 
-
 STLClient = mock.MagicMock()
 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
 stl_patch.start()
@@ -56,79 +55,90 @@ class TestTrexProfile(unittest.TestCase):
     EXAMPLE_IP_ADDR = "10.0.0.1"
     EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414"
 
-    PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
-               'name': 'rfc2544',
-               'traffic_profile': {'traffic_type': 'RFC2544Profile',
-                                   'frame_rate': 100},
-               TrafficProfile.DOWNLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100',
-                                                              '1518B': '0',
-                                                              '128B': '0',
-                                                              '1400B': '0',
-                                                              '256B': '0',
-                                                              '373b': '0',
-                                                              '570B': '0'},
-                                                               "srcmac": "00:00:00:00:00:02",
-                                                               "dstmac": "00:00:00:00:00:01"},
-                                                  'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
-                                                  'proto': 'udp',
-                                                  'srcip4': '9.9.1.1-90.1.2.2',
-                                                  'dscp': 0, 'ttl': 32,
-                                                  'count': 1},
-                                                  'outer_l4': {'srcport': '2001',
-                                                'dsrport': '1234',
-                                                'count': 1}}},
-               TrafficProfile.UPLINK: {'ipv4':
-                           {'outer_l2': {'framesize':
-                                         {'64B': '100', '1518B': '0',
-                                          '128B': '0', '1400B': '0',
-                                          '256B': '0', '373b': '0',
-                                          '570B': '0'},
-                                         "srcmac": "00:00:00:00:00:01",
-                                         "dstmac": "00:00:00:00:00:02"},
-                            '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'}
-    PROFILE_v6 = {'description': 'Traffic profile to run RFC2544 latency',
-                  'name': 'rfc2544',
-                  'traffic_profile': {'traffic_type': 'RFC2544Profile',
-                                      'frame_rate': 100},
-                  TrafficProfile.DOWNLINK: {'ipv6': {'outer_l2': {'framesize':
-                                                   {'64B': '100', '1518B': '0',
-                                                    '128B': '0', '1400B': '0',
-                                                    '256B': '0', '373b': '0',
-                                                    '570B': '0'},
-                                                   "srcmac": "00:00:00:00:00:02",
-                                                   "dstmac": "00:00:00:00:00:01"},
-                                                     'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
-                                                     'proto': 'udp',
-                                                     'srcip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
-                                                     'dscp': 0, 'ttl': 32,
-                                                     'count': 1},
-                                                     'outer_l4': {'srcport': '2001',
-                                                   'dsrport': '1234',
-                                                   'count': 1}}},
-                  TrafficProfile.UPLINK:
-                  {'ipv6': {'outer_l2': {'framesize':
-                                         {'64B': '100', '1518B': '0',
-                                          '128B': '0', '1400B': '0',
-                                          '256B': '0', '373b': '0',
-                                          '570B': '0'},
-                                         "srcmac": "00:00:00:00:00:01",
-                                         "dstmac": "00:00:00:00:00:02"},
-                            'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
-                                           'proto': 'udp',
-                                           'srcip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
-                                           'dscp': 0, 'ttl': 32,
-                                           'count': 1},
-                            'outer_l4': {'dstport': '2001',
-                                         'srcport': '1234',
-                                         'count': 1}}},
-                  'schema': 'isb:traffic_profile:0.1'}
+    PROFILE = {
+        'description': 'Traffic profile to run RFC2544 latency',
+        'name': 'rfc2544',
+        'traffic_profile': {'traffic_type': 'RFC2544Profile',
+                            'frame_rate': 100},
+        TrafficProfile.DOWNLINK: {
+            'ipv4': {'outer_l2': {'framesize': {'64B': '100',
+                                                '1518B': '0',
+                                                '128B': '0',
+                                                '1400B': '0',
+                                                '256B': '0',
+                                                '373b': '0',
+                                                '570B': '0'},
+                                  "srcmac": "00:00:00:00:00:02",
+                                  "dstmac": "00:00:00:00:00:01"},
+                     'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
+                                    'proto': 'udp',
+                                    'srcip4': '9.9.1.1-90.1.2.2',
+                                    'dscp': 0, 'ttl': 32,
+                                    'count': 1},
+                     'outer_l4': {'srcport': '2001',
+                                  'dsrport': '1234',
+                                  'count': 1}}},
+        TrafficProfile.UPLINK: {
+            'ipv4':
+                {'outer_l2': {'framesize':
+                                  {'64B': '100', '1518B': '0',
+                                   '128B': '0', '1400B': '0',
+                                   '256B': '0', '373b': '0',
+                                   '570B': '0'},
+                              "srcmac": "00:00:00:00:00:01",
+                              "dstmac": "00:00:00:00:00:02"},
+                 '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'}
+    PROFILE_v6 = {
+        'description': 'Traffic profile to run RFC2544 latency',
+        'name': 'rfc2544',
+        'traffic_profile': {'traffic_type': 'RFC2544Profile',
+                            'frame_rate': 100},
+        TrafficProfile.DOWNLINK: {
+            'ipv6': {'outer_l2': {'framesize':
+                                      {'64B': '100', '1518B': '0',
+                                       '128B': '0', '1400B': '0',
+                                       '256B': '0', '373b': '0',
+                                       '570B': '0'},
+                                  "srcmac": "00:00:00:00:00:02",
+                                  "dstmac": "00:00:00:00:00:01"},
+                     'outer_l3v4': {
+                         'dstip6':
+                             '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
+                         'proto': 'udp',
+                         'srcip6':
+                             '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
+                         'dscp': 0, 'ttl': 32,
+                         'count': 1},
+                     'outer_l4': {'srcport': '2001',
+                                  'dsrport': '1234',
+                                  'count': 1}}},
+        TrafficProfile.UPLINK: {
+            'ipv6': {'outer_l2': {'framesize':
+                                      {'64B': '100', '1518B': '0',
+                                       '128B': '0', '1400B': '0',
+                                       '256B': '0', '373b': '0',
+                                       '570B': '0'},
+                                  "srcmac": "00:00:00:00:00:01",
+                                  "dstmac": "00:00:00:00:00:02"},
+                     'outer_l3v4': {
+                         'dstip6':
+                             '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
+                         'proto': 'udp',
+                         'srcip6':
+                             '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
+                         'dscp': 0, 'ttl': 32,
+                         'count': 1},
+                     'outer_l4': {'dstport': '2001',
+                                  'srcport': '1234',
+                                  'count': 1}}},
+        'schema': 'isb:traffic_profile:0.1'}
 
     def test___init__(self):
         TrafficProfile.params = self.PROFILE
@@ -211,6 +221,40 @@ class TestTrexProfile(unittest.TestCase):
         self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6,
                           "1.1.1.3", "1.1.1.1")
 
+    def test__dscp_range_action_partial_actual_count_zero(self):
+        traffic_profile = TrexProfile(TrafficProfile)
+        dscp_partial = traffic_profile._dscp_range_action_partial()
+
+        flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+        dscp_partial('1', '1', 'unneeded')
+        self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
+    def test__dscp_range_action_partial_count_greater_than_actual(self):
+        traffic_profile = TrexProfile(TrafficProfile)
+        dscp_partial = traffic_profile._dscp_range_action_partial()
+
+        flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+        dscp_partial('1', '10', '100')
+        self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
+    def test__udp_range_action_partial_actual_count_zero(self):
+        traffic_profile = TrexProfile(TrafficProfile)
+        traffic_profile.udp['field1'] = 'value1'
+        udp_partial = traffic_profile._udp_range_action_partial('field1')
+
+        flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+        udp_partial('1', '1', 'unneeded')
+        self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
+    def test__udp_range_action_partial_count_greater_than_actual(self):
+        traffic_profile = TrexProfile(TrafficProfile)
+        traffic_profile.udp['field1'] = 'value1'
+        udp_partial = traffic_profile._udp_range_action_partial('field1', 'not_used_count')
+
+        flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+        udp_partial('1', '10', '100')
+        self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
     def test__general_single_action_partial(self):
         trex_profile = TrexProfile(TrafficProfile)
 
index 2f97945..3b19ff9 100644 (file)
@@ -70,6 +70,7 @@ class TrexProfile(TrafficProfile):
 
     def _ethernet_range_action_partial(self, direction, _):
         def partial(min_value, max_value, count):
+            # pylint: disable=unused-argument
             stl_vm_flow_var = STLVmFlowVar(name="mac_{}".format(direction),
                                            min_value=1,
                                            max_value=30,
@@ -83,6 +84,7 @@ class TrexProfile(TrafficProfile):
         return partial
 
     def _ip_range_action_partial(self, direction, count=1):
+        # pylint: disable=unused-argument
         def partial(min_value, max_value, count):
             ip1 = int(ipaddress.IPv4Address(min_value))
             ip2 = int(ipaddress.IPv4Address(max_value))
@@ -108,6 +110,7 @@ class TrexProfile(TrafficProfile):
 
     def _ip6_range_action_partial(self, direction, _):
         def partial(min_value, max_value, count):
+            # pylint: disable=unused-argument
             min_value, max_value = self._get_start_end_ipv6(min_value, max_value)
             stl_vm_flow_var = STLVmFlowVar(name="ip6_{}".format(direction),
                                            min_value=min_value,
@@ -124,6 +127,7 @@ class TrexProfile(TrafficProfile):
 
     def _dscp_range_action_partial(self, *_):
         def partial(min_value, max_value, count):
+            # pylint: disable=unused-argument
             stl_vm_flow_var = STLVmFlowVar(name="dscp",
                                            min_value=min_value,
                                            max_value=max_value,
@@ -134,8 +138,10 @@ class TrexProfile(TrafficProfile):
             stl_vm_wr_flow_var = STLVmWrFlowVar(fv_name='dscp',
                                                 pkt_offset='IP.tos')
             self.vm_flow_vars.append(stl_vm_wr_flow_var)
+        return partial
 
     def _udp_range_action_partial(self, field, count=1):
+        # pylint: disable=unused-argument
         def partial(min_value, max_value, count):
             actual_count = int(max_value) - int(min_value)
             if not actual_count: