1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
20 from yardstick.common import exceptions
21 from yardstick.network_services import traffic_profile as tprofile_package
22 from yardstick.network_services.traffic_profile import base
23 from yardstick import tests as y_tests
26 class TestTrafficProfile(unittest.TestCase):
28 "schema": "isb:traffic_profile:0.1",
30 "description": "Fixed traffic profile to run UDP traffic",
32 "traffic_type": "FixedTraffic",
33 "frame_rate": 100, # pps
37 def _get_res_mock(self, **kw):
38 _mock = mock.MagicMock()
39 for k, v in kw.items():
43 def test___init__(self):
44 traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE)
45 self.assertEqual(self.TRAFFIC_PROFILE, traffic_profile.params)
47 def test_execute(self):
48 traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE)
49 self.assertRaises(NotImplementedError,
50 traffic_profile.execute_traffic, {})
52 def test_get_existing_traffic_profile(self):
53 traffic_profile_list = [
54 'RFC2544Profile', 'FixedProfile', 'TrafficProfileGenericHTTP',
55 'IXIARFC2544Profile', 'ProxACLProfile', 'ProxBinSearchProfile',
56 'ProxProfile', 'ProxRampProfile']
57 with mock.patch.dict(sys.modules, y_tests.STL_MOCKS):
58 tprofile_package.register_modules()
60 for tp in traffic_profile_list:
61 traffic_profile = base.TrafficProfile.get(
62 {'traffic_profile': {'traffic_type': tp}})
63 self.assertEqual(tp, traffic_profile.__class__.__name__)
65 def test_get_non_existing_traffic_profile(self):
66 self.assertRaises(exceptions.TrafficProfileNotImplemented,
67 base.TrafficProfile.get, self.TRAFFIC_PROFILE)
70 class TestDummyProfile(unittest.TestCase):
71 def test_execute(self):
72 dummy_profile = base.DummyProfile(base.TrafficProfile)
73 self.assertIsNone(dummy_profile.execute({}))