Merge "updating the traffic profile to enable static cgnapt for ixnet"
[yardstick.git] / tests / unit / network_services / traffic_profile / test_prox_profile.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_profile import ProxProfile
29
30
31 class TestProxProfile(unittest.TestCase):
32
33     def test_fill_samples(self):
34         samples = {}
35         traffic_generator = mock.MagicMock()
36         traffic_generator.vpci_if_name_ascending = [
37             ['id1', 'name1'],
38             ['id2', 'name2'],
39         ]
40
41         traffic_generator.resource_helper.sut.port_stats.side_effect = [
42             list(range(12)),
43             list(range(10, 22)),
44         ]
45
46         expected = {
47             'name1': {
48                 'in_packets': 6,
49                 'out_packets': 7,
50             },
51             'name2': {
52                 'in_packets': 16,
53                 'out_packets': 17,
54             },
55         }
56         ProxProfile.fill_samples(samples, traffic_generator)
57         self.assertDictEqual(samples, expected)
58
59     def test_init(self):
60         tp_config = {
61             'traffic_profile': {},
62         }
63
64         profile = ProxProfile(tp_config)
65         profile.init(234)
66         self.assertEqual(profile.queue, 234)
67
68     def test_execute(self):
69         packet_sizes = [
70             10,
71             100,
72             1000,
73         ]
74         tp_config = {
75             'traffic_profile': {
76                 'packet_sizes': packet_sizes,
77             },
78         }
79
80         traffic_generator = mock.MagicMock()
81         profile = ProxProfile(tp_config)
82
83         self.assertFalse(profile.done)
84         for _ in packet_sizes:
85             with self.assertRaises(NotImplementedError):
86                 profile.execute(traffic_generator)
87
88         self.assertIsNone(profile.execute(traffic_generator))
89
90     def test_bounds_iterator(self):
91         tp_config = {
92             'traffic_profile': {},
93         }
94
95         profile = ProxProfile(tp_config)
96         value = 0.0
97         for value in profile.bounds_iterator():
98             pass
99
100         self.assertEqual(value, 100.0)
101
102         mock_logger = mock.MagicMock()
103         for _ in profile.bounds_iterator(mock_logger):
104             pass
105
106         self.assertEqual(mock_logger.debug.call_count, 1)
107         self.assertEqual(mock_logger.info.call_count, 10)