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.storage.fio.Fio
14 from __future__ import absolute_import
20 from oslo_serialization import jsonutils
22 from yardstick.benchmark.scenarios.storage import fio
25 @mock.patch('yardstick.benchmark.scenarios.storage.fio.ssh')
26 class FioTestCase(unittest.TestCase):
33 'key_filename': 'mykey.key'
36 self.sample_output = {
37 'read': 'fio_read_sample_output.json',
38 'write': 'fio_write_sample_output.json',
39 'rw': 'fio_rw_sample_output.json'
42 def test_fio_successful_setup(self, mock_ssh):
45 'filename': '/home/ubuntu/data.raw',
50 args = {'options': options}
51 p = fio.Fio(args, self.ctx)
54 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
55 self.assertIsNotNone(p.client)
56 self.assertEqual(p.setup_done, True)
58 def test_fio_successful_no_sla(self, mock_ssh):
61 'filename': '/home/ubuntu/data.raw',
66 args = {'options': options}
67 p = fio.Fio(args, self.ctx)
70 p.client = mock_ssh.SSH.from_node()
72 sample_output = self._read_sample_output(self.sample_output['rw'])
73 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
77 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
78 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
79 '"write_lat": 233.55}'
80 expected_result = jsonutils.loads(expected_result)
81 self.assertEqual(result, expected_result)
83 def test_fio_successful_read_no_sla(self, mock_ssh):
86 'filename': '/home/ubuntu/data.raw',
91 args = {'options': options}
92 p = fio.Fio(args, self.ctx)
95 p.client = mock_ssh.SSH.from_node()
97 sample_output = self._read_sample_output(self.sample_output['read'])
98 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
102 expected_result = '{"read_bw": 36113, "read_iops": 9028,' \
104 expected_result = jsonutils.loads(expected_result)
105 self.assertEqual(result, expected_result)
107 def test_fio_successful_write_no_sla(self, mock_ssh):
110 'filename': '/home/ubuntu/data.raw',
115 args = {'options': options}
116 p = fio.Fio(args, self.ctx)
119 p.client = mock_ssh.SSH.from_node()
121 sample_output = self._read_sample_output(self.sample_output['write'])
122 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
126 expected_result = '{"write_bw": 35107, "write_iops": 8776,'\
127 '"write_lat": 111.74}'
128 expected_result = jsonutils.loads(expected_result)
129 self.assertEqual(result, expected_result)
131 def test_fio_successful_lat_sla(self, mock_ssh):
134 'filename': '/home/ubuntu/data.raw',
141 'sla': {'write_lat': 300.1}
143 p = fio.Fio(args, self.ctx)
146 p.client = mock_ssh.SSH.from_node()
148 sample_output = self._read_sample_output(self.sample_output['rw'])
149 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
153 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
154 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
155 '"write_lat": 233.55}'
156 expected_result = jsonutils.loads(expected_result)
157 self.assertEqual(result, expected_result)
159 def test_fio_unsuccessful_lat_sla(self, mock_ssh):
162 'filename': '/home/ubuntu/data.raw',
169 'sla': {'write_lat': 200.1}
171 p = fio.Fio(args, self.ctx)
174 p.client = mock_ssh.SSH.from_node()
176 sample_output = self._read_sample_output(self.sample_output['rw'])
177 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
178 self.assertRaises(AssertionError, p.run, result)
180 def test_fio_successful_bw_iops_sla(self, mock_ssh):
183 'filename': '/home/ubuntu/data.raw',
190 'sla': {'read_iops': 20000}
192 p = fio.Fio(args, self.ctx)
195 p.client = mock_ssh.SSH.from_node()
197 sample_output = self._read_sample_output(self.sample_output['rw'])
198 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
202 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
203 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
204 '"write_lat": 233.55}'
205 expected_result = jsonutils.loads(expected_result)
206 self.assertEqual(result, expected_result)
208 def test_fio_unsuccessful_bw_iops_sla(self, mock_ssh):
211 'filename': '/home/ubuntu/data.raw',
218 'sla': {'read_iops': 30000}
220 p = fio.Fio(args, self.ctx)
223 p.client = mock_ssh.SSH.from_node()
225 sample_output = self._read_sample_output(self.sample_output['rw'])
226 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
227 self.assertRaises(AssertionError, p.run, result)
229 def test_fio_unsuccessful_script_error(self, mock_ssh):
232 'filename': '/home/ubuntu/data.raw',
237 args = {'options': options}
238 p = fio.Fio(args, self.ctx)
241 p.client = mock_ssh.SSH.from_node()
243 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
244 self.assertRaises(RuntimeError, p.run, result)
246 def _read_sample_output(self, file_name):
247 curr_path = os.path.dirname(os.path.abspath(__file__))
248 output = os.path.join(curr_path, file_name)
249 with open(output) as f:
250 sample_output = f.read()
258 if __name__ == '__main__':