Fix exception handling ixload
[yardstick.git] / yardstick / tests / unit / network_services / traffic_profile / test_pktgen.py
1 # Copyright (c) 2018 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 import mock
16
17 from yardstick.common import utils
18 from yardstick.network_services.traffic_profile import pktgen
19 from yardstick.tests.unit import base as ut_base
20
21
22 class TestIXIARFC2544Profile(ut_base.BaseUnitTestCase):
23
24     def setUp(self):
25         self._tp_config = {'traffic_profile': {}}
26         self._host = 'localhost'
27         self._port = '12345'
28         self.tp = pktgen.PktgenTrafficProfile(self._tp_config)
29         self.tp.init(self._host, self._port)
30         self._mock_send_socket_command = mock.patch.object(
31             utils, 'send_socket_command', return_value=0)
32         self.mock_send_socket_command = self._mock_send_socket_command.start()
33         self.addCleanup(self._stop_mock)
34
35     def _stop_mock(self):
36         self._mock_send_socket_command.stop()
37
38     def test_start(self):
39         self.tp.start()
40         self.mock_send_socket_command.assert_called_once_with(
41             self._host, self._port, 'pktgen.start("0")')
42
43     def test_stop(self):
44         self.tp.stop()
45         self.mock_send_socket_command.assert_called_once_with(
46             self._host, self._port, 'pktgen.stop("0")')
47
48     def test_rate(self):
49         rate = 75
50         self.tp.rate(rate)
51         command = 'pktgen.set("0", "rate", 75)'
52         self.mock_send_socket_command.assert_called_once_with(
53             self._host, self._port, command)
54
55     def test_clear_all_stats(self):
56         self.tp.clear_all_stats()
57         self.mock_send_socket_command.assert_called_once_with(
58             self._host, self._port, 'clr')
59
60     def test_help(self):
61         self.tp.help()
62         self.mock_send_socket_command.assert_called_once_with(
63             self._host, self._port, 'help')