Merge "KVMFORNFV:Livemigration testcase changes in Yardstick"
[yardstick.git] / tests / unit / network_services / traffic_profile / test_prox_ramp.py
1 # Copyright (c) 2017 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 #
15
16 from __future__ import absolute_import
17
18 import unittest
19 import mock
20
21 from tests.unit import STL_MOCKS
22
23 STLClient = mock.MagicMock()
24 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
25 stl_patch.start()
26
27 if stl_patch:
28     from yardstick.network_services.traffic_profile.prox_ramp import ProxRampProfile
29     from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
30
31
32 class TestProxRampProfile(unittest.TestCase):
33
34     def test_run_test_with_pkt_size(self):
35         tp_config = {
36             'traffic_profile': {
37                 'lower_bound': 10.0,
38                 'upper_bound': 100.0,
39                 'step_value': 10.0,
40             },
41         }
42
43         success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
44
45         traffic_gen = mock.MagicMock()
46         traffic_gen.resource_helper.run_test.return_value = success_tuple
47
48         profile = ProxRampProfile(tp_config)
49         profile.fill_samples = fill_samples = mock.MagicMock()
50         profile.queue = mock.MagicMock()
51
52         profile.run_test_with_pkt_size(traffic_gen, 128, 30)
53         self.assertEqual(traffic_gen.resource_helper.run_test.call_count, 10)
54         self.assertEqual(fill_samples.call_count, 10)
55
56     def test_run_test_with_pkt_size_with_fail(self):
57         tp_config = {
58             'traffic_profile': {
59                 'lower_bound': 10.0,
60                 'upper_bound': 100.0,
61                 'step_value': 10.0,
62             },
63         }
64
65         success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
66         fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
67
68         traffic_gen = mock.MagicMock()
69         traffic_gen.resource_helper.run_test.side_effect = [
70             success_tuple,
71             success_tuple,
72             success_tuple,
73             fail_tuple,
74             success_tuple,
75             fail_tuple,
76             fail_tuple,
77             fail_tuple,
78         ]
79
80         profile = ProxRampProfile(tp_config)
81         profile.fill_samples = fill_samples = mock.MagicMock()
82         profile.queue = mock.MagicMock()
83
84         profile.run_test_with_pkt_size(traffic_gen, 128, 30)
85         self.assertEqual(traffic_gen.resource_helper.run_test.call_count, 4)
86         self.assertEqual(fill_samples.call_count, 3)