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 ##############################################################################
10 # Unittest for yardstick.benchmark.scenarios.compute.lmbench.Lmbench
12 from __future__ import absolute_import
17 from oslo_serialization import jsonutils
19 from yardstick.benchmark.scenarios.compute import lmbench
22 # pylint: disable=unused-argument
23 # disable this for now because I keep forgetting mock patch arg ordering
26 @mock.patch('yardstick.benchmark.scenarios.compute.lmbench.ssh')
27 class LmbenchTestCase(unittest.TestCase):
34 'key_filename': "mykey.key"
40 def test_successful_setup(self, mock_ssh):
42 l = lmbench.Lmbench({}, self.ctx)
43 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
46 self.assertIsNotNone(l.client)
47 self.assertTrue(l.setup_done)
49 def test_unsuccessful_unknown_type_run(self, mock_ssh):
54 args = {'options': options}
56 l = lmbench.Lmbench(args, self.ctx)
58 self.assertRaises(RuntimeError, l.run, self.result)
60 def test_successful_latency_run_no_sla(self, mock_ssh):
63 "test_type": "latency",
67 args = {'options': options}
68 l = lmbench.Lmbench(args, self.ctx)
70 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
71 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
73 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
74 self.assertEqual(self.result, expected_result)
76 def test_successful_bandwidth_run_no_sla(self, mock_ssh):
79 "test_type": "bandwidth",
84 args = {"options": options}
85 l = lmbench.Lmbench(args, self.ctx)
87 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
88 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
90 expected_result = jsonutils.loads(sample_output)
91 self.assertEqual(self.result, expected_result)
93 def test_successful_latency_run_sla(self, mock_ssh):
96 "test_type": "latency",
102 "sla": {"max_latency": 35}
104 l = lmbench.Lmbench(args, self.ctx)
106 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
107 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
109 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
110 self.assertEqual(self.result, expected_result)
112 def test_successful_bandwidth_run_sla(self, mock_ssh):
115 "test_type": "bandwidth",
122 "sla": {"min_bandwidth": 10000}
124 l = lmbench.Lmbench(args, self.ctx)
126 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
127 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
129 expected_result = jsonutils.loads(sample_output)
130 self.assertEqual(self.result, expected_result)
132 def test_unsuccessful_latency_run_sla(self, mock_ssh):
135 "test_type": "latency",
141 "sla": {"max_latency": 35}
143 l = lmbench.Lmbench(args, self.ctx)
145 sample_output = '[{"latency": 37.5, "size": 0.00049}]'
146 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
147 self.assertRaises(AssertionError, l.run, self.result)
149 def test_unsuccessful_bandwidth_run_sla(self, mock_ssh):
152 "test_type": "bandwidth",
159 "sla": {"min_bandwidth": 10000}
161 l = lmbench.Lmbench(args, self.ctx)
163 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}'
164 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
165 self.assertRaises(AssertionError, l.run, self.result)
167 def test_successful_latency_for_cache_run_sla(self, mock_ssh):
170 "test_type": "latency_for_cache",
176 "sla": {"max_latency": 35}
178 l = lmbench.Lmbench(args, self.ctx)
180 sample_output = "{\"L1cache\": 1.6}"
181 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
183 expected_result = jsonutils.loads(sample_output)
184 self.assertEqual(self.result, expected_result)
186 def test_unsuccessful_script_error(self, mock_ssh):
188 options = {"test_type": "bandwidth"}
189 args = {"options": options}
190 l = lmbench.Lmbench(args, self.ctx)
192 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
193 self.assertRaises(RuntimeError, l.run, self.result)