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.assertTrue(p.setup_done)
58 def test_fio_job_file_successful_setup(self, mock_ssh):
61 'job_file': 'job_file.ini',
62 'directory': '/FIO_Test'
64 args = {'options': options}
65 p = fio.Fio(args, self.ctx)
68 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
69 self.assertIsNotNone(p.client)
70 self.assertTrue(p.setup_done)
72 def test_fio_successful_no_sla(self, mock_ssh):
75 'filename': '/home/ubuntu/data.raw',
80 args = {'options': options}
81 p = fio.Fio(args, self.ctx)
84 p.client = mock_ssh.SSH.from_node()
86 sample_output = self._read_sample_output(self.sample_output['rw'])
87 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
91 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
92 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
93 '"write_lat": 233.55}'
94 expected_result = jsonutils.loads(expected_result)
95 self.assertEqual(result, expected_result)
97 def test_fio_successful_read_no_sla(self, mock_ssh):
100 'filename': '/home/ubuntu/data.raw',
105 args = {'options': options}
106 p = fio.Fio(args, self.ctx)
109 p.client = mock_ssh.SSH.from_node()
111 sample_output = self._read_sample_output(self.sample_output['read'])
112 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
116 expected_result = '{"read_bw": 36113, "read_iops": 9028,' \
118 expected_result = jsonutils.loads(expected_result)
119 self.assertEqual(result, expected_result)
121 def test_fio_successful_write_no_sla(self, mock_ssh):
124 'filename': '/home/ubuntu/data.raw',
129 args = {'options': options}
130 p = fio.Fio(args, self.ctx)
133 p.client = mock_ssh.SSH.from_node()
135 sample_output = self._read_sample_output(self.sample_output['write'])
136 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
140 expected_result = '{"write_bw": 35107, "write_iops": 8776,'\
141 '"write_lat": 111.74}'
142 expected_result = jsonutils.loads(expected_result)
143 self.assertEqual(result, expected_result)
145 def test_fio_successful_lat_sla(self, mock_ssh):
148 'filename': '/home/ubuntu/data.raw',
155 'sla': {'write_lat': 300.1}
157 p = fio.Fio(args, self.ctx)
160 p.client = mock_ssh.SSH.from_node()
162 sample_output = self._read_sample_output(self.sample_output['rw'])
163 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
167 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
168 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
169 '"write_lat": 233.55}'
170 expected_result = jsonutils.loads(expected_result)
171 self.assertEqual(result, expected_result)
173 def test_fio_unsuccessful_lat_sla(self, mock_ssh):
176 'filename': '/home/ubuntu/data.raw',
183 'sla': {'write_lat': 200.1}
185 p = fio.Fio(args, self.ctx)
188 p.client = mock_ssh.SSH.from_node()
190 sample_output = self._read_sample_output(self.sample_output['rw'])
191 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
192 self.assertRaises(AssertionError, p.run, result)
194 def test_fio_successful_bw_iops_sla(self, mock_ssh):
197 'filename': '/home/ubuntu/data.raw',
204 'sla': {'read_iops': 20000}
206 p = fio.Fio(args, self.ctx)
209 p.client = mock_ssh.SSH.from_node()
211 sample_output = self._read_sample_output(self.sample_output['rw'])
212 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
216 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
217 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
218 '"write_lat": 233.55}'
219 expected_result = jsonutils.loads(expected_result)
220 self.assertEqual(result, expected_result)
222 def test_fio_unsuccessful_bw_iops_sla(self, mock_ssh):
225 'filename': '/home/ubuntu/data.raw',
232 'sla': {'read_iops': 30000}
234 p = fio.Fio(args, self.ctx)
237 p.client = mock_ssh.SSH.from_node()
239 sample_output = self._read_sample_output(self.sample_output['rw'])
240 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
241 self.assertRaises(AssertionError, p.run, result)
243 def test_fio_unsuccessful_script_error(self, mock_ssh):
246 'filename': '/home/ubuntu/data.raw',
251 args = {'options': options}
252 p = fio.Fio(args, self.ctx)
255 p.client = mock_ssh.SSH.from_node()
257 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
258 self.assertRaises(RuntimeError, p.run, result)
260 def _read_sample_output(self, file_name):
261 curr_path = os.path.dirname(os.path.abspath(__file__))
262 output = os.path.join(curr_path, file_name)
263 with open(output) as f:
264 sample_output = f.read()
272 if __name__ == '__main__':