1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB 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 ##############################################################################
12 from oslo_serialization import jsonutils
14 from yardstick.benchmark.scenarios.compute import lmbench
15 from yardstick.common import exceptions as y_exc
16 from yardstick import ssh
19 class LmbenchTestCase(unittest.TestCase):
26 'key_filename': "mykey.key"
32 self._mock_ssh = mock.patch.object(ssh, 'SSH')
33 self.mock_ssh = self._mock_ssh.start()
34 self.addCleanup(self._stop_mocks)
36 def _stop_mocks(self):
39 def test_successful_setup(self):
41 l = lmbench.Lmbench({}, self.ctx)
42 self.mock_ssh.from_node().execute.return_value = (0, '', '')
45 self.assertIsNotNone(l.client)
46 self.assertTrue(l.setup_done)
48 def test_unsuccessful_unknown_type_run(self):
53 args = {'options': options}
55 l = lmbench.Lmbench(args, self.ctx)
57 self.assertRaises(RuntimeError, l.run, self.result)
59 def test_successful_latency_run_no_sla(self):
62 "test_type": "latency",
66 args = {'options': options}
67 l = lmbench.Lmbench(args, self.ctx)
69 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
70 self.mock_ssh.from_node().execute.return_value = (0, sample_output, '')
72 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
73 self.assertEqual(self.result, expected_result)
75 def test_successful_bandwidth_run_no_sla(self):
78 "test_type": "bandwidth",
83 args = {"options": options}
84 l = lmbench.Lmbench(args, self.ctx)
86 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
87 self.mock_ssh.from_node().execute.return_value = (0, sample_output, '')
89 expected_result = jsonutils.loads(sample_output)
90 self.assertEqual(self.result, expected_result)
92 def test_successful_latency_run_sla(self):
95 "test_type": "latency",
101 "sla": {"max_latency": 35}
103 l = lmbench.Lmbench(args, self.ctx)
105 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
106 self.mock_ssh.from_node().execute.return_value = (0, sample_output, '')
108 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
109 self.assertEqual(self.result, expected_result)
111 def test_successful_bandwidth_run_sla(self):
114 "test_type": "bandwidth",
121 "sla": {"min_bandwidth": 10000}
123 l = lmbench.Lmbench(args, self.ctx)
125 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
126 self.mock_ssh.from_node().execute.return_value = (0, sample_output, '')
128 expected_result = jsonutils.loads(sample_output)
129 self.assertEqual(self.result, expected_result)
131 def test_unsuccessful_latency_run_sla(self):
134 "test_type": "latency",
140 "sla": {"max_latency": 35}
142 l = lmbench.Lmbench(args, self.ctx)
144 sample_output = '[{"latency": 37.5, "size": 0.00049}]'
145 self.mock_ssh.from_node().execute.return_value = (0, sample_output, '')
146 self.assertRaises(y_exc.SLAValidationError, l.run, self.result)
148 def test_unsuccessful_bandwidth_run_sla(self):
151 "test_type": "bandwidth",
158 "sla": {"min_bandwidth": 10000}
160 l = lmbench.Lmbench(args, self.ctx)
162 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}'
163 self.mock_ssh.from_node().execute.return_value = (0, sample_output, '')
164 self.assertRaises(y_exc.SLAValidationError, l.run, self.result)
166 def test_successful_latency_for_cache_run_sla(self):
169 "test_type": "latency_for_cache",
175 "sla": {"max_latency": 35}
177 l = lmbench.Lmbench(args, self.ctx)
179 sample_output = "{\"L1cache\": 1.6}"
180 self.mock_ssh.from_node().execute.return_value = (0, sample_output, '')
182 expected_result = jsonutils.loads(sample_output)
183 self.assertEqual(self.result, expected_result)
185 def test_unsuccessful_script_error(self):
187 options = {"test_type": "bandwidth"}
188 args = {"options": options}
189 l = lmbench.Lmbench(args, self.ctx)
191 self.mock_ssh.from_node().execute.return_value = (1, '', 'FOOBAR')
192 self.assertRaises(RuntimeError, l.run, self.result)