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
22 from yardstick.common import exceptions as y_exc
25 @mock.patch('yardstick.benchmark.scenarios.networking.netperf_node.ssh')
26 class NetperfNodeTestCase(unittest.TestCase):
31 'ip': '192.168.10.10',
36 'ip': '192.168.10.11',
42 def test_netperf_node_successful_setup(self, mock_ssh):
44 p = netperf_node.NetperfNode({}, self.ctx)
45 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
48 self.assertIsNotNone(p.server)
49 self.assertIsNotNone(p.client)
50 self.assertTrue(p.setup_done)
52 def test_netperf_node_successful_no_sla(self, mock_ssh):
55 args = {'options': options}
58 p = netperf_node.NetperfNode(args, self.ctx)
59 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
60 p.host = mock_ssh.SSH.from_node()
62 sample_output = self._read_sample_output()
63 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
64 expected_result = jsonutils.loads(sample_output)
66 self.assertEqual(result, expected_result)
68 def test_netperf_node_successful_sla(self, mock_ssh):
73 'sla': {'mean_latency': 100}
77 p = netperf_node.NetperfNode(args, self.ctx)
78 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
79 p.host = mock_ssh.SSH.from_node()
81 sample_output = self._read_sample_output()
82 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
83 expected_result = jsonutils.loads(sample_output)
85 self.assertEqual(result, expected_result)
87 def test_netperf_node_unsuccessful_sla(self, mock_ssh):
92 'sla': {'mean_latency': 5}
96 p = netperf_node.NetperfNode(args, self.ctx)
97 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
98 p.host = mock_ssh.SSH.from_node()
100 sample_output = self._read_sample_output()
101 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
102 self.assertRaises(y_exc.SLAValidationError, p.run, result)
104 def test_netperf_node_unsuccessful_script_error(self, mock_ssh):
107 args = {'options': options}
110 p = netperf_node.NetperfNode(args, self.ctx)
111 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
112 p.host = mock_ssh.SSH.from_node()
114 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
115 self.assertRaises(RuntimeError, p.run, result)
117 def _read_sample_output(self):
118 curr_path = os.path.dirname(os.path.abspath(__file__))
119 output = os.path.join(curr_path, 'netperf_sample_output.json')
120 with open(output) as f:
121 sample_output = f.read()