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.storage.fio.Fio
12 from __future__ import absolute_import
18 from oslo_serialization import jsonutils
20 from yardstick.benchmark.scenarios.storage import fio
23 @mock.patch('yardstick.benchmark.scenarios.storage.fio.ssh')
24 class FioTestCase(unittest.TestCase):
31 'key_filename': 'mykey.key'
34 self.sample_output = {
35 'read': 'fio_read_sample_output.json',
36 'write': 'fio_write_sample_output.json',
37 'rw': 'fio_rw_sample_output.json'
40 def test_fio_successful_setup(self, mock_ssh):
43 'filename': '/home/ubuntu/data.raw',
48 args = {'options': options}
49 p = fio.Fio(args, self.ctx)
52 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
53 self.assertIsNotNone(p.client)
54 self.assertTrue(p.setup_done)
56 def test_fio_job_file_successful_setup(self, mock_ssh):
59 'job_file': 'job_file.ini',
60 'directory': '/FIO_Test'
62 args = {'options': options}
63 p = fio.Fio(args, self.ctx)
64 mock_ssh.SSH.from_node().execute.return_value = (0, '/dev/vdb', '')
67 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
68 self.assertIsNotNone(p.client)
69 self.assertTrue(p.setup_done)
71 def test_fio_job_file_no_disk__setup(self, mock_ssh):
74 'job_file': 'job_file.ini',
75 'directory': '/FIO_Test'
77 args = {'options': options}
78 p = fio.Fio(args, self.ctx)
79 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
82 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
83 self.assertIsNotNone(p.client)
84 self.assertTrue(p.setup_done)
86 def test_fio_successful_no_sla(self, mock_ssh):
89 'filename': '/home/ubuntu/data.raw',
94 args = {'options': options}
95 p = fio.Fio(args, self.ctx)
98 p.client = mock_ssh.SSH.from_node()
100 sample_output = self._read_sample_output(self.sample_output['rw'])
101 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
105 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
106 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
107 '"write_lat": 233.55}'
108 expected_result = jsonutils.loads(expected_result)
109 self.assertEqual(result, expected_result)
111 def test_fio_successful_read_no_sla(self, mock_ssh):
114 'filename': '/home/ubuntu/data.raw',
119 args = {'options': options}
120 p = fio.Fio(args, self.ctx)
123 p.client = mock_ssh.SSH.from_node()
125 sample_output = self._read_sample_output(self.sample_output['read'])
126 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
130 expected_result = '{"read_bw": 36113, "read_iops": 9028,' \
132 expected_result = jsonutils.loads(expected_result)
133 self.assertEqual(result, expected_result)
135 def test_fio_successful_write_no_sla(self, mock_ssh):
138 'filename': '/home/ubuntu/data.raw',
143 args = {'options': options}
144 p = fio.Fio(args, self.ctx)
147 p.client = mock_ssh.SSH.from_node()
149 sample_output = self._read_sample_output(self.sample_output['write'])
150 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
154 expected_result = '{"write_bw": 35107, "write_iops": 8776,'\
155 '"write_lat": 111.74}'
156 expected_result = jsonutils.loads(expected_result)
157 self.assertEqual(result, expected_result)
159 def test_fio_successful_lat_sla(self, mock_ssh):
162 'filename': '/home/ubuntu/data.raw',
169 'sla': {'write_lat': 300.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, '')
181 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
182 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
183 '"write_lat": 233.55}'
184 expected_result = jsonutils.loads(expected_result)
185 self.assertEqual(result, expected_result)
187 def test_fio_unsuccessful_lat_sla(self, mock_ssh):
190 'filename': '/home/ubuntu/data.raw',
197 'sla': {'write_lat': 200.1}
199 p = fio.Fio(args, self.ctx)
202 p.client = mock_ssh.SSH.from_node()
204 sample_output = self._read_sample_output(self.sample_output['rw'])
205 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
206 self.assertRaises(AssertionError, p.run, result)
208 def test_fio_successful_bw_iops_sla(self, mock_ssh):
211 'filename': '/home/ubuntu/data.raw',
218 'sla': {'read_iops': 20000}
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, '')
230 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
231 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
232 '"write_lat": 233.55}'
233 expected_result = jsonutils.loads(expected_result)
234 self.assertEqual(result, expected_result)
236 def test_fio_unsuccessful_bw_iops_sla(self, mock_ssh):
239 'filename': '/home/ubuntu/data.raw',
246 'sla': {'read_iops': 30000}
248 p = fio.Fio(args, self.ctx)
251 p.client = mock_ssh.SSH.from_node()
253 sample_output = self._read_sample_output(self.sample_output['rw'])
254 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
255 self.assertRaises(AssertionError, p.run, result)
257 def test_fio_unsuccessful_script_error(self, mock_ssh):
260 'filename': '/home/ubuntu/data.raw',
265 args = {'options': options}
266 p = fio.Fio(args, self.ctx)
269 p.client = mock_ssh.SSH.from_node()
271 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
272 self.assertRaises(RuntimeError, p.run, result)
274 def _read_sample_output(self, file_name):
275 curr_path = os.path.dirname(os.path.abspath(__file__))
276 output = os.path.join(curr_path, file_name)
277 with open(output) as f:
278 sample_output = f.read()