NSB "Prox" : Cleanup duplicated traffic profile
[yardstick.git] / 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 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_ACL import ProxACLProfile
29     from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
30
31
32 class TestProxACLProfile(unittest.TestCase):
33
34     def test_run_test_with_pkt_size(self):
35         def target(*args, **kwargs):
36             runs.append(args[2])
37             if args[2] < 0 or args[2] > 100:
38                 raise RuntimeError(' '.join([str(args), str(runs)]))
39             if args[2] > 75.0:
40                 return fail_tuple, {}
41             return success_tuple, {}
42
43         def get_mock_samples(*args, **kwargs):
44             if args[2] < 0:
45                 raise RuntimeError(' '.join([str(args), str(runs)]))
46             return success_tuple
47
48         tp_config = {
49            'traffic_profile': {
50                 'upper_bound': 100.0,
51                 'lower_bound': 0.0,
52                 'tolerated_loss': 50.0,
53                 'attempts': 20
54             },
55         }
56
57         runs = []
58         success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
59         fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
60
61         traffic_gen = mock.MagicMock()
62
63         profile_helper = mock.MagicMock()
64         profile_helper.run_test = target
65
66         profile = ProxACLProfile(tp_config)
67         profile.init(mock.MagicMock())
68
69         profile.prox_config["attempts"] = 20
70         profile.queue = mock.MagicMock()
71         profile.tolerated_loss = 50.0
72         profile.pkt_size = 128
73         profile.duration = 30
74         profile.test_value = 100.0
75         profile.tolerated_loss = 100.0
76         profile._profile_helper = profile_helper
77
78         profile.run_test_with_pkt_size(traffic_gen, profile.pkt_size, profile.duration)