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
20 from yardstick.common import exceptions as y_exc
23 # pylint: disable=unused-argument
24 # disable this for now because I keep forgetting mock patch arg ordering
27 @mock.patch('yardstick.benchmark.scenarios.compute.lmbench.ssh')
28 class LmbenchTestCase(unittest.TestCase):
35 'key_filename': "mykey.key"
41 def test_successful_setup(self, mock_ssh):
43 l = lmbench.Lmbench({}, self.ctx)
44 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
47 self.assertIsNotNone(l.client)
48 self.assertTrue(l.setup_done)
50 def test_unsuccessful_unknown_type_run(self, mock_ssh):
55 args = {'options': options}
57 l = lmbench.Lmbench(args, self.ctx)
59 self.assertRaises(RuntimeError, l.run, self.result)
61 def test_successful_latency_run_no_sla(self, mock_ssh):
64 "test_type": "latency",
68 args = {'options': options}
69 l = lmbench.Lmbench(args, self.ctx)
71 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
72 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
74 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
75 self.assertEqual(self.result, expected_result)
77 def test_successful_bandwidth_run_no_sla(self, mock_ssh):
80 "test_type": "bandwidth",
85 args = {"options": options}
86 l = lmbench.Lmbench(args, self.ctx)
88 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
89 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
91 expected_result = jsonutils.loads(sample_output)
92 self.assertEqual(self.result, expected_result)
94 def test_successful_latency_run_sla(self, mock_ssh):
97 "test_type": "latency",
103 "sla": {"max_latency": 35}
105 l = lmbench.Lmbench(args, self.ctx)
107 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
108 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
110 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
111 self.assertEqual(self.result, expected_result)
113 def test_successful_bandwidth_run_sla(self, mock_ssh):
116 "test_type": "bandwidth",
123 "sla": {"min_bandwidth": 10000}
125 l = lmbench.Lmbench(args, self.ctx)
127 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
128 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
130 expected_result = jsonutils.loads(sample_output)
131 self.assertEqual(self.result, expected_result)
133 def test_unsuccessful_latency_run_sla(self, mock_ssh):
136 "test_type": "latency",
142 "sla": {"max_latency": 35}
144 l = lmbench.Lmbench(args, self.ctx)
146 sample_output = '[{"latency": 37.5, "size": 0.00049}]'
147 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
148 self.assertRaises(y_exc.SLAValidationError, l.run, self.result)
150 def test_unsuccessful_bandwidth_run_sla(self, mock_ssh):
153 "test_type": "bandwidth",
160 "sla": {"min_bandwidth": 10000}
162 l = lmbench.Lmbench(args, self.ctx)
164 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}'
165 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
166 self.assertRaises(y_exc.SLAValidationError, l.run, self.result)
168 def test_successful_latency_for_cache_run_sla(self, mock_ssh):
171 "test_type": "latency_for_cache",
177 "sla": {"max_latency": 35}
179 l = lmbench.Lmbench(args, self.ctx)
181 sample_output = "{\"L1cache\": 1.6}"
182 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
184 expected_result = jsonutils.loads(sample_output)
185 self.assertEqual(self.result, expected_result)
187 def test_unsuccessful_script_error(self, mock_ssh):
189 options = {"test_type": "bandwidth"}
190 args = {"options": options}
191 l = lmbench.Lmbench(args, self.ctx)
193 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
194 self.assertRaises(RuntimeError, l.run, self.result)