3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and other.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
13 # yardstick.benchmark.scenarios.networking.netutilization.NetUtilization
15 from __future__ import absolute_import
20 from yardstick.benchmark.scenarios.networking import netutilization
23 @mock.patch('yardstick.benchmark.scenarios.networking.netutilization.ssh')
24 class NetUtilizationTestCase(unittest.TestCase):
31 'key_filename': "mykey.key"
37 def test_setup_success(self, mock_ssh):
42 args = {'options': options}
44 n = netutilization.NetUtilization(args, self.ctx)
45 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
48 self.assertIsNotNone(n.client)
49 self.assertTrue(n.setup_done)
51 def test_execute_command_success(self, mock_ssh):
56 args = {'options': options}
58 n = netutilization.NetUtilization(args, self.ctx)
59 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
62 expected_result = 'abcdefg'
63 mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '')
64 result = n._execute_command("foo")
65 self.assertEqual(result, expected_result)
67 def test_execute_command_failed(self, mock_ssh):
72 args = {'options': options}
74 n = netutilization.NetUtilization(args, self.ctx)
75 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
78 mock_ssh.SSH.from_node().execute.return_value = (127, '', 'abcdefg')
79 self.assertRaises(RuntimeError, n._execute_command,
82 def test_get_network_utilization_success(self, mock_ssh):
87 args = {'options': options}
89 n = netutilization.NetUtilization(args, self.ctx)
90 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
93 mpstat_output = self._read_file("netutilization_sample_output1.txt")
94 mock_ssh.SSH.from_node().execute.return_value = (0, mpstat_output, '')
95 result = n._get_network_utilization()
98 {"network_utilization_maximun": {
99 "lo": {"rxcmp/s": "0.00",
107 "eth0": {"rxcmp/s": "0.00",
114 "rxmcst/s": "0.00"}},
115 "network_utilization_average": {
116 "lo": {"rxcmp/s": "0.00",
124 "eth0": {"rxcmp/s": "0.00",
131 "rxmcst/s": "0.00"}},
132 "network_utilization_minimum": {
133 "lo": {"rxcmp/s": "0.00",
141 "eth0": {"rxcmp/s": "0.00",
148 "rxmcst/s": "0.00"}}}
150 self.assertDictEqual(result, expected_result)
152 def test_get_network_utilization_2_success(self, mock_ssh):
157 args = {'options': options}
159 n = netutilization.NetUtilization(args, self.ctx)
160 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
163 mpstat_output = self._read_file("netutilization_sample_output2.txt")
164 mock_ssh.SSH.from_node().execute.return_value = (0, mpstat_output, '')
165 result = n._get_network_utilization()
168 {"network_utilization_maximun": {
169 "lo": {"rxcmp/s": "0.00",
177 "eth0": {"rxcmp/s": "0.00",
184 "rxmcst/s": "0.00"}},
185 "network_utilization_average": {
186 "lo": {"rxcmp/s": "0.00",
194 "eth0": {"rxcmp/s": "0.00",
201 "rxmcst/s": "0.00"}},
202 "network_utilization_minimum": {
203 "lo": {"rxcmp/s": "0.00",
211 "eth0": {"rxcmp/s": "0.00",
218 "rxmcst/s": "0.00"}}}
220 self.assertDictEqual(result, expected_result)
222 def _read_file(self, filename):
223 curr_path = os.path.dirname(os.path.abspath(__file__))
224 output = os.path.join(curr_path, filename)
225 with open(output) as f:
226 sample_output = f.read()