1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 # yardstick.benchmark.scenarios.networking.netperf_node.NetperfNode
13 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.benchmark.scenarios.networking import netperf_node
24 @mock.patch('yardstick.benchmark.scenarios.networking.netperf_node.ssh')
25 class NetperfNodeTestCase(unittest.TestCase):
30 'ip': '192.168.10.10',
35 'ip': '192.168.10.11',
41 def test_netperf_node_successful_setup(self, mock_ssh):
43 p = netperf_node.NetperfNode({}, self.ctx)
44 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
47 self.assertIsNotNone(p.server)
48 self.assertIsNotNone(p.client)
49 self.assertTrue(p.setup_done)
51 def test_netperf_node_successful_no_sla(self, mock_ssh):
54 args = {'options': options}
57 p = netperf_node.NetperfNode(args, self.ctx)
58 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
59 p.host = mock_ssh.SSH.from_node()
61 sample_output = self._read_sample_output()
62 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
63 expected_result = jsonutils.loads(sample_output)
65 self.assertEqual(result, expected_result)
67 def test_netperf_node_successful_sla(self, mock_ssh):
72 'sla': {'mean_latency': 100}
76 p = netperf_node.NetperfNode(args, self.ctx)
77 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
78 p.host = mock_ssh.SSH.from_node()
80 sample_output = self._read_sample_output()
81 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
82 expected_result = jsonutils.loads(sample_output)
84 self.assertEqual(result, expected_result)
86 def test_netperf_node_unsuccessful_sla(self, mock_ssh):
91 'sla': {'mean_latency': 5}
95 p = netperf_node.NetperfNode(args, self.ctx)
96 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
97 p.host = mock_ssh.SSH.from_node()
99 sample_output = self._read_sample_output()
100 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
101 self.assertRaises(AssertionError, p.run, result)
103 def test_netperf_node_unsuccessful_script_error(self, mock_ssh):
106 args = {'options': options}
109 p = netperf_node.NetperfNode(args, self.ctx)
110 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
111 p.host = mock_ssh.SSH.from_node()
113 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
114 self.assertRaises(RuntimeError, p.run, result)
116 def _read_sample_output(self):
117 curr_path = os.path.dirname(os.path.abspath(__file__))
118 output = os.path.join(curr_path, 'netperf_sample_output.json')
119 with open(output) as f:
120 sample_output = f.read()