1 # Copyright (c) 2017 Intel Corporation
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from __future__ import absolute_import
21 from tests.unit import STL_MOCKS
23 STLClient = mock.MagicMock()
24 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
28 from yardstick.network_services.traffic_profile.prox_profile import ProxProfile
29 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
32 class TestProxProfile(unittest.TestCase):
34 def test_sort_vpci(self):
35 traffic_generator = mock.Mock()
36 interface_1 = {'virtual-interface': {'vpci': 'id1'}, 'name': 'name1'}
37 interface_2 = {'virtual-interface': {'vpci': 'id2'}, 'name': 'name2'}
38 interface_3 = {'virtual-interface': {'vpci': 'id3'}, 'name': 'name3'}
39 interfaces = [interface_2, interface_3, interface_1]
40 traffic_generator.vnfd_helper = {
41 'vdu': [{'external-interface': interfaces}]}
42 output = ProxProfile.sort_vpci(traffic_generator)
43 self.assertEqual([interface_1, interface_2, interface_3], output)
45 def test_fill_samples(self):
48 traffic_generator = mock.MagicMock()
53 traffic_generator.resource_helper.sut.port_stats.side_effect = [
68 with mock.patch.object(ProxProfile, 'sort_vpci', return_value=interfaces):
69 ProxProfile.fill_samples(samples, traffic_generator)
71 self.assertDictEqual(samples, expected)
75 'traffic_profile': {},
78 profile = ProxProfile(tp_config)
81 self.assertIs(profile.queue, queue)
83 def test_execute_traffic(self):
91 'packet_sizes': packet_sizes,
95 traffic_generator = mock.MagicMock()
97 setup_helper = traffic_generator.setup_helper
98 setup_helper.find_in_section.return_value = None
100 prox_resource_helper = ProxResourceHelper(setup_helper)
101 traffic_generator.resource_helper = prox_resource_helper
103 profile = ProxProfile(tp_config)
105 self.assertFalse(profile.done)
106 for _ in packet_sizes:
107 with self.assertRaises(NotImplementedError):
108 profile.execute_traffic(traffic_generator)
110 self.assertIsNone(profile.execute_traffic(traffic_generator))
111 self.assertTrue(profile.done)
113 def test_bounds_iterator(self):
115 'traffic_profile': {},
118 profile = ProxProfile(tp_config)
120 for value in profile.bounds_iterator():
123 self.assertEqual(value, 100.0)
125 mock_logger = mock.MagicMock()
126 for _ in profile.bounds_iterator(mock_logger):
129 self.assertEqual(mock_logger.debug.call_count, 1)
130 self.assertEqual(mock_logger.info.call_count, 10)