apiserver: mock socket.gethostbyname
[yardstick.git] / tests / unit / network_services / traffic_profile / test_traffic_profile.py
index 126a4a2..9a78c36 100644 (file)
 #
 
 from __future__ import absolute_import
+
 import unittest
+import mock
+
+from tests.unit import STL_MOCKS
+
+
+STLClient = mock.MagicMock()
+stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
+stl_patch.start()
 
-from yardstick.network_services.traffic_profile.base import TrafficProfile
-from yardstick.network_services.traffic_profile.traffic_profile import \
-    TrexProfile
+if stl_patch:
+    from yardstick.network_services.traffic_profile.base import TrafficProfile
+    from yardstick.network_services.traffic_profile.traffic_profile import \
+        TrexProfile
 
 
 class TestTrexProfile(unittest.TestCase):
@@ -50,9 +60,11 @@ class TestTrexProfile(unittest.TestCase):
                                    '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},
+                                                  'dscp': 0, 'ttl': 32,
+                                                  'count': 1},
                                    'outer_l4': {'srcport': '2001',
-                                                'dsrport': '1234'}}},
+                                                'dsrport': '1234',
+                                                'count': 1}}},
                'private': {'ipv4':
                            {'outer_l2': {'framesize':
                                          {'64B': '100', '1518B': '0',
@@ -64,9 +76,10 @@ class TestTrexProfile(unittest.TestCase):
                             '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},
+                                           'dscp': 0, 'ttl': 32, 'count': 1},
                             'outer_l4': {'dstport': '2001',
-                                         'srcport': '1234'}}},
+                                         'srcport': '1234',
+                                         'count': 1}}},
                'schema': 'isb:traffic_profile:0.1'}
     PROFILE_v6 = {'description': 'Traffic profile to run RFC2544 latency',
                   'name': 'rfc2544',
@@ -82,9 +95,11 @@ class TestTrexProfile(unittest.TestCase):
                                       '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},
+                                                     'dscp': 0, 'ttl': 32,
+                                                     'count': 1},
                                       'outer_l4': {'srcport': '2001',
-                                                   'dsrport': '1234'}}},
+                                                   'dsrport': '1234',
+                                                   'count': 1}}},
                   'private':
                   {'ipv6': {'outer_l2': {'framesize':
                                          {'64B': '100', '1518B': '0',
@@ -96,9 +111,11 @@ class TestTrexProfile(unittest.TestCase):
                             '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},
+                                           'dscp': 0, 'ttl': 32,
+                                           'count': 1},
                             'outer_l4': {'dstport': '2001',
-                                         'srcport': '1234'}}},
+                                         'srcport': '1234',
+                                         'count': 1}}},
                   'schema': 'isb:traffic_profile:0.1'}
 
     def test___init__(self):
@@ -240,15 +257,15 @@ class TestTrexProfile(unittest.TestCase):
         trex_profile = \
             TrexProfile(TrafficProfile)
         trex_profile.params = self.PROFILE
-        trex_profile.profile_data = self.PROFILE["private"]
-        self.assertIsNotNone(trex_profile.get_streams())
+        profile_data = self.PROFILE["private"]
+        self.assertIsNotNone(trex_profile.get_streams(profile_data))
         trex_profile.pg_id = 1
-        self.assertIsNotNone(trex_profile.get_streams())
+        self.assertIsNotNone(trex_profile.get_streams(profile_data))
         trex_profile.params = self.PROFILE_v6
         trex_profile.profile_data = self.PROFILE_v6["private"]
-        self.assertIsNotNone(trex_profile.get_streams())
+        self.assertIsNotNone(trex_profile.get_streams(profile_data))
         trex_profile.pg_id = 1
-        self.assertIsNotNone(trex_profile.get_streams())
+        self.assertIsNotNone(trex_profile.get_streams(profile_data))
 
     def test_generate_packets(self):
         trex_profile = \