Merge "Adding intel_pmu tools plugin for collectd"
[yardstick.git] / tests / unit / network_services / traffic_profile / test_base.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016-2017 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 # Unittest for yardstick.network_services.traffic_profile.test_base
19
20 from __future__ import absolute_import
21 import unittest
22 import mock
23
24 from yardstick.network_services.traffic_profile.base import \
25     TrafficProfile, DummyProfile
26
27
28 class TestTrafficProfile(unittest.TestCase):
29     TRAFFIC_PROFILE = {
30         "schema": "isb:traffic_profile:0.1",
31         "name": "fixed",
32         "description": "Fixed traffic profile to run UDP traffic",
33         "traffic_profile": {
34             "traffic_type": "FixedTraffic",
35             "frame_rate": 100,  # pps
36             "flow_number": 10,
37             "frame_size": 64}}
38
39     def _get_res_mock(self, **kw):
40         _mock = mock.MagicMock()
41         for k, v in kw.items():
42             setattr(_mock, k, v)
43             return _mock
44
45     def test___init__(self):
46         traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
47         self.assertEqual(self.TRAFFIC_PROFILE, traffic_profile.params)
48
49     def test_execute(self):
50         traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
51         self.assertRaises(NotImplementedError, traffic_profile.execute, {})
52
53     def test_get(self):
54         traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
55         self.assertRaises(RuntimeError, traffic_profile.get,
56                           self.TRAFFIC_PROFILE)
57
58
59 class TestDummyProfile(unittest.TestCase):
60     def test_execute(self):
61         dummy_profile = DummyProfile(TrafficProfile)
62         self.assertIsNone(dummy_profile.execute({}))