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
19 from yardstick.benchmark.scenarios.storage import fio
22 @mock.patch('yardstick.benchmark.scenarios.storage.fio.ssh')
23 class FioTestCase(unittest.TestCase):
30 'key_filename': 'mykey.key'
33 self.sample_output = {
34 'read': 'fio_read_sample_output.json',
35 'write': 'fio_write_sample_output.json',
36 'rw': 'fio_rw_sample_output.json'
39 def test_fio_successful_setup(self, mock_ssh):
42 'filename': '/home/ubuntu/data.raw',
47 args = {'options': options}
48 p = fio.Fio(args, self.ctx)
51 mock_ssh.SSH().execute.return_value = (0, '', '')
52 self.assertIsNotNone(p.client)
53 self.assertEqual(p.setup_done, True)
55 def test_fio_successful_no_sla(self, mock_ssh):
58 'filename': '/home/ubuntu/data.raw',
63 args = {'options': options}
64 p = fio.Fio(args, self.ctx)
67 p.client = mock_ssh.SSH()
69 sample_output = self._read_sample_output(self.sample_output['rw'])
70 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
74 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
75 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
76 '"write_lat": 233.55}'
77 expected_result = json.loads(expected_result)
78 self.assertEqual(result, expected_result)
80 def test_fio_successful_read_no_sla(self, mock_ssh):
83 'filename': '/home/ubuntu/data.raw',
88 args = {'options': options}
89 p = fio.Fio(args, self.ctx)
92 p.client = mock_ssh.SSH()
94 sample_output = self._read_sample_output(self.sample_output['read'])
95 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
99 expected_result = '{"read_bw": 36113, "read_iops": 9028,' \
101 expected_result = json.loads(expected_result)
102 self.assertEqual(result, expected_result)
104 def test_fio_successful_write_no_sla(self, mock_ssh):
107 'filename': '/home/ubuntu/data.raw',
112 args = {'options': options}
113 p = fio.Fio(args, self.ctx)
116 p.client = mock_ssh.SSH()
118 sample_output = self._read_sample_output(self.sample_output['write'])
119 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
123 expected_result = '{"write_bw": 35107, "write_iops": 8776,'\
124 '"write_lat": 111.74}'
125 expected_result = json.loads(expected_result)
126 self.assertEqual(result, expected_result)
128 def test_fio_successful_lat_sla(self, mock_ssh):
131 'filename': '/home/ubuntu/data.raw',
138 'sla': {'write_lat': 300.1}
140 p = fio.Fio(args, self.ctx)
143 p.client = mock_ssh.SSH()
145 sample_output = self._read_sample_output(self.sample_output['rw'])
146 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
150 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
151 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
152 '"write_lat": 233.55}'
153 expected_result = json.loads(expected_result)
154 self.assertEqual(result, expected_result)
157 def test_fio_unsuccessful_lat_sla(self, mock_ssh):
160 'filename': '/home/ubuntu/data.raw',
167 'sla': {'write_lat': 200.1}
169 p = fio.Fio(args, self.ctx)
172 p.client = mock_ssh.SSH()
174 sample_output = self._read_sample_output(self.sample_output['rw'])
175 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
176 self.assertRaises(AssertionError, p.run, result)
178 def test_fio_successful_bw_iops_sla(self, mock_ssh):
181 'filename': '/home/ubuntu/data.raw',
188 'sla': {'read_iops': 20000}
190 p = fio.Fio(args, self.ctx)
193 p.client = mock_ssh.SSH()
195 sample_output = self._read_sample_output(self.sample_output['rw'])
196 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
200 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
201 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
202 '"write_lat": 233.55}'
203 expected_result = json.loads(expected_result)
204 self.assertEqual(result, expected_result)
206 def test_fio_unsuccessful_bw_iops_sla(self, mock_ssh):
209 'filename': '/home/ubuntu/data.raw',
216 'sla': {'read_iops': 30000}
218 p = fio.Fio(args, self.ctx)
221 p.client = mock_ssh.SSH()
223 sample_output = self._read_sample_output(self.sample_output['rw'])
224 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
225 self.assertRaises(AssertionError, p.run, result)
227 def test_fio_unsuccessful_script_error(self, mock_ssh):
230 'filename': '/home/ubuntu/data.raw',
235 args = {'options': options}
236 p = fio.Fio(args, self.ctx)
239 p.client = mock_ssh.SSH()
241 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
242 self.assertRaises(RuntimeError, p.run, result)
244 def _read_sample_output(self, file_name):
245 curr_path = os.path.dirname(os.path.abspath(__file__))
246 output = os.path.join(curr_path, file_name)
247 with open(output) as f:
248 sample_output = f.read()
254 if __name__ == '__main__':