3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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.netperf_node.NetperfNode
20 from yardstick.benchmark.scenarios.networking import netperf_node
23 @mock.patch('yardstick.benchmark.scenarios.networking.netperf_node.ssh')
24 class NetperfNodeTestCase(unittest.TestCase):
29 'ip': '192.168.10.10',
34 'ip': '192.168.10.11',
40 def test_netperf_node_successful_setup(self, mock_ssh):
42 p = netperf_node.NetperfNode({}, self.ctx)
43 mock_ssh.SSH().execute.return_value = (0, '', '')
46 self.assertIsNotNone(p.server)
47 self.assertIsNotNone(p.client)
48 self.assertEqual(p.setup_done, True)
50 def test_netperf_node_successful_no_sla(self, mock_ssh):
53 args = {'options': options}
56 p = netperf_node.NetperfNode(args, self.ctx)
57 mock_ssh.SSH().execute.return_value = (0, '', '')
58 p.host = mock_ssh.SSH()
60 sample_output = self._read_sample_output()
61 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
62 expected_result = json.loads(sample_output)
64 self.assertEqual(result, expected_result)
66 def test_netperf_node_successful_sla(self, mock_ssh):
71 'sla': {'mean_latency': 100}
75 p = netperf_node.NetperfNode(args, self.ctx)
76 mock_ssh.SSH().execute.return_value = (0, '', '')
77 p.host = mock_ssh.SSH()
79 sample_output = self._read_sample_output()
80 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
81 expected_result = json.loads(sample_output)
83 self.assertEqual(result, expected_result)
85 def test_netperf_node_unsuccessful_sla(self, mock_ssh):
90 'sla': {'mean_latency': 5}
94 p = netperf_node.NetperfNode(args, self.ctx)
95 mock_ssh.SSH().execute.return_value = (0, '', '')
96 p.host = mock_ssh.SSH()
98 sample_output = self._read_sample_output()
99 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
100 self.assertRaises(AssertionError, p.run, result)
102 def test_netperf_node_unsuccessful_script_error(self, mock_ssh):
105 args = {'options': options}
108 p = netperf_node.NetperfNode(args, self.ctx)
109 mock_ssh.SSH().execute.return_value = (0, '', '')
110 p.host = mock_ssh.SSH()
112 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
113 self.assertRaises(RuntimeError, p.run, result)
115 def _read_sample_output(self):
116 curr_path = os.path.dirname(os.path.abspath(__file__))
117 output = os.path.join(curr_path, 'netperf_sample_output.json')
118 with open(output) as f:
119 sample_output = f.read()
126 if __name__ == '__main__':