Merge "Parse "dispatcher" options correctly from InfluxDB client"
[yardstick.git] / yardstick / tests / unit / network_services / traffic_profile / test_prox_acl.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 import unittest
17 import mock
18
19 from yardstick.tests import STL_MOCKS
20
21 STLClient = mock.MagicMock()
22 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
23 stl_patch.start()
24
25 if stl_patch:
26     from yardstick.network_services.traffic_profile.prox_ACL import ProxACLProfile
27     from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
28
29
30 class TestProxACLProfile(unittest.TestCase):
31
32     def test_run_test_with_pkt_size(self):
33         def target(*args):
34             runs.append(args[2])
35             if args[2] < 0 or args[2] > 100:
36                 raise RuntimeError(' '.join([str(args), str(runs)]))
37             if args[2] > 75.0:
38                 return fail_tuple, {}
39             return success_tuple, {}
40
41         tp_config = {
42             'traffic_profile': {
43                 'upper_bound': 100.0,
44                 'lower_bound': 0.0,
45                 'tolerated_loss': 50.0,
46                 'attempts': 20
47             },
48         }
49
50         runs = []
51         success_tuple = ProxTestDataTuple(
52             10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
53         fail_tuple = ProxTestDataTuple(
54             10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
55
56         traffic_gen = mock.MagicMock()
57
58         profile_helper = mock.MagicMock()
59         profile_helper.run_test = target
60
61         profile = ProxACLProfile(tp_config)
62         profile.init(mock.MagicMock())
63
64         profile.prox_config["attempts"] = 20
65         profile.queue = mock.MagicMock()
66         profile.tolerated_loss = 50.0
67         profile.pkt_size = 128
68         profile.duration = 30
69         profile.test_value = 100.0
70         profile.tolerated_loss = 100.0
71         profile._profile_helper = profile_helper
72
73         profile.run_test_with_pkt_size(
74             traffic_gen, profile.pkt_size, profile.duration)