3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB 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 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.compute.lmbench.Lmbench
14 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.benchmark.scenarios.compute import lmbench
24 @mock.patch('yardstick.benchmark.scenarios.compute.lmbench.ssh')
25 class LmbenchTestCase(unittest.TestCase):
32 'key_filename': "mykey.key"
38 def test_successful_setup(self, mock_ssh):
40 l = lmbench.Lmbench({}, self.ctx)
41 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
44 self.assertIsNotNone(l.client)
45 self.assertTrue(l.setup_done)
47 def test_unsuccessful_unknown_type_run(self, mock_ssh):
52 args = {'options': options}
54 l = lmbench.Lmbench(args, self.ctx)
56 self.assertRaises(RuntimeError, l.run, self.result)
58 def test_successful_latency_run_no_sla(self, mock_ssh):
61 "test_type": "latency",
65 args = {'options': options}
66 l = lmbench.Lmbench(args, self.ctx)
68 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
69 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
71 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
72 self.assertEqual(self.result, expected_result)
74 def test_successful_bandwidth_run_no_sla(self, mock_ssh):
77 "test_type": "bandwidth",
82 args = {"options": options}
83 l = lmbench.Lmbench(args, self.ctx)
85 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
86 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
88 expected_result = jsonutils.loads(sample_output)
89 self.assertEqual(self.result, expected_result)
91 def test_successful_latency_run_sla(self, mock_ssh):
94 "test_type": "latency",
100 "sla": {"max_latency": 35}
102 l = lmbench.Lmbench(args, self.ctx)
104 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
105 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
107 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
108 self.assertEqual(self.result, expected_result)
110 def test_successful_bandwidth_run_sla(self, mock_ssh):
113 "test_type": "bandwidth",
120 "sla": {"min_bandwidth": 10000}
122 l = lmbench.Lmbench(args, self.ctx)
124 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
125 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
127 expected_result = jsonutils.loads(sample_output)
128 self.assertEqual(self.result, expected_result)
130 def test_unsuccessful_latency_run_sla(self, mock_ssh):
133 "test_type": "latency",
139 "sla": {"max_latency": 35}
141 l = lmbench.Lmbench(args, self.ctx)
143 sample_output = '[{"latency": 37.5, "size": 0.00049}]'
144 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
145 self.assertRaises(AssertionError, l.run, self.result)
147 def test_unsuccessful_bandwidth_run_sla(self, mock_ssh):
150 "test_type": "bandwidth",
157 "sla": {"min_bandwidth": 10000}
159 l = lmbench.Lmbench(args, self.ctx)
161 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}'
162 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
163 self.assertRaises(AssertionError, l.run, self.result)
165 def test_successful_latency_for_cache_run_sla(self, mock_ssh):
168 "test_type": "latency_for_cache",
174 "sla": {"max_latency": 35}
176 l = lmbench.Lmbench(args, self.ctx)
178 sample_output = "{\"L1cache\": 1.6}"
179 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
181 expected_result = jsonutils.loads(sample_output)
182 self.assertEqual(self.result, expected_result)
184 def test_unsuccessful_script_error(self, mock_ssh):
186 options = {"test_type": "bandwidth"}
187 args = {"options": options}
188 l = lmbench.Lmbench(args, self.ctx)
190 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
191 self.assertRaises(RuntimeError, l.run, self.result)
197 if __name__ == '__main__':