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
21 from yardstick.common import exceptions as y_exc
24 @mock.patch('yardstick.benchmark.scenarios.storage.fio.ssh')
25 class FioTestCase(unittest.TestCase):
32 'key_filename': 'mykey.key'
35 self.sample_output = {
36 'read': 'fio_read_sample_output.json',
37 'write': 'fio_write_sample_output.json',
38 'rw': 'fio_rw_sample_output.json'
41 def test_fio_successful_setup(self, mock_ssh):
44 'filename': '/home/ubuntu/data.raw',
49 args = {'options': options}
50 p = fio.Fio(args, self.ctx)
53 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
54 self.assertIsNotNone(p.client)
55 self.assertTrue(p.setup_done)
57 def test_fio_job_file_successful_setup(self, mock_ssh):
60 'job_file': 'job_file.ini',
61 'directory': '/FIO_Test'
63 args = {'options': options}
64 p = fio.Fio(args, self.ctx)
65 mock_ssh.SSH.from_node().execute.return_value = (0, '/dev/vdb', '')
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_job_file_no_disk__setup(self, mock_ssh):
75 'job_file': 'job_file.ini',
76 'directory': '/FIO_Test'
78 args = {'options': options}
79 p = fio.Fio(args, self.ctx)
80 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
83 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
84 self.assertIsNotNone(p.client)
85 self.assertTrue(p.setup_done)
87 def test_fio_successful_no_sla(self, mock_ssh):
90 'filename': '/home/ubuntu/data.raw',
95 args = {'options': options}
96 p = fio.Fio(args, self.ctx)
99 p.client = mock_ssh.SSH.from_node()
101 sample_output = self._read_sample_output(self.sample_output['rw'])
102 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
106 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
107 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
108 '"write_lat": 233.55}'
109 expected_result = jsonutils.loads(expected_result)
110 self.assertEqual(result, expected_result)
112 def test_fio_successful_read_no_sla(self, mock_ssh):
115 'filename': '/home/ubuntu/data.raw',
120 args = {'options': options}
121 p = fio.Fio(args, self.ctx)
124 p.client = mock_ssh.SSH.from_node()
126 sample_output = self._read_sample_output(self.sample_output['read'])
127 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
131 expected_result = '{"read_bw": 36113, "read_iops": 9028,' \
133 expected_result = jsonutils.loads(expected_result)
134 self.assertEqual(result, expected_result)
136 def test_fio_successful_write_no_sla(self, mock_ssh):
139 'filename': '/home/ubuntu/data.raw',
144 args = {'options': options}
145 p = fio.Fio(args, self.ctx)
148 p.client = mock_ssh.SSH.from_node()
150 sample_output = self._read_sample_output(self.sample_output['write'])
151 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
155 expected_result = '{"write_bw": 35107, "write_iops": 8776,'\
156 '"write_lat": 111.74}'
157 expected_result = jsonutils.loads(expected_result)
158 self.assertEqual(result, expected_result)
160 def test_fio_successful_lat_sla(self, mock_ssh):
163 'filename': '/home/ubuntu/data.raw',
170 'sla': {'write_lat': 300.1}
172 p = fio.Fio(args, self.ctx)
175 p.client = mock_ssh.SSH.from_node()
177 sample_output = self._read_sample_output(self.sample_output['rw'])
178 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
182 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
183 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
184 '"write_lat": 233.55}'
185 expected_result = jsonutils.loads(expected_result)
186 self.assertEqual(result, expected_result)
188 def test_fio_unsuccessful_lat_sla(self, mock_ssh):
191 'filename': '/home/ubuntu/data.raw',
198 'sla': {'write_lat': 200.1}
200 p = fio.Fio(args, self.ctx)
203 p.client = mock_ssh.SSH.from_node()
205 sample_output = self._read_sample_output(self.sample_output['rw'])
206 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
207 self.assertRaises(y_exc.SLAValidationError, p.run, result)
209 def test_fio_successful_bw_iops_sla(self, mock_ssh):
212 'filename': '/home/ubuntu/data.raw',
219 'sla': {'read_iops': 20000}
221 p = fio.Fio(args, self.ctx)
224 p.client = mock_ssh.SSH.from_node()
226 sample_output = self._read_sample_output(self.sample_output['rw'])
227 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
231 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
232 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
233 '"write_lat": 233.55}'
234 expected_result = jsonutils.loads(expected_result)
235 self.assertEqual(result, expected_result)
237 def test_fio_unsuccessful_bw_iops_sla(self, mock_ssh):
240 'filename': '/home/ubuntu/data.raw',
247 'sla': {'read_iops': 30000}
249 p = fio.Fio(args, self.ctx)
252 p.client = mock_ssh.SSH.from_node()
254 sample_output = self._read_sample_output(self.sample_output['rw'])
255 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
256 self.assertRaises(y_exc.SLAValidationError, p.run, result)
258 def test_fio_unsuccessful_script_error(self, mock_ssh):
261 'filename': '/home/ubuntu/data.raw',
266 args = {'options': options}
267 p = fio.Fio(args, self.ctx)
270 p.client = mock_ssh.SSH.from_node()
272 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
273 self.assertRaises(RuntimeError, p.run, result)
275 def _read_sample_output(self, file_name):
276 curr_path = os.path.dirname(os.path.abspath(__file__))
277 output = os.path.join(curr_path, file_name)
278 with open(output) as f:
279 sample_output = f.read()