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):
27 'host': '172.16.0.137',
29 'key_filename': 'mykey.key'
31 self.sample_output = {
32 'read': 'fio_read_sample_output.json',
33 'write': 'fio_write_sample_output.json',
34 'rw': 'fio_rw_sample_output.json'
37 def test_fio_successful_setup(self, mock_ssh):
41 'filename': '/home/ec2-user/data.raw',
46 args = {'options': options}
49 mock_ssh.SSH().execute.return_value = (0, '', '')
50 self.assertIsNotNone(p.client)
51 self.assertEqual(p.setup_done, True)
53 def test_fio_successful_no_sla(self, mock_ssh):
57 'filename': '/home/ec2-user/data.raw',
62 args = {'options': options}
63 p.client = mock_ssh.SSH()
65 sample_output = self._read_sample_output(self.sample_output['rw'])
66 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
70 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
71 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
72 '"write_lat": 233.55}'
73 expected_result = json.loads(expected_result)
74 self.assertEqual(result, expected_result)
76 def test_fio_successful_read_no_sla(self, mock_ssh):
80 'filename': '/home/ec2-user/data.raw',
85 args = {'options': options}
86 p.client = mock_ssh.SSH()
88 sample_output = self._read_sample_output(self.sample_output['read'])
89 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
93 expected_result = '{"read_bw": 36113, "read_iops": 9028,' \
95 expected_result = json.loads(expected_result)
96 self.assertEqual(result, expected_result)
98 def test_fio_successful_write_no_sla(self, mock_ssh):
100 p = fio.Fio(self.ctx)
102 'filename': '/home/ec2-user/data.raw',
107 args = {'options': options}
108 p.client = mock_ssh.SSH()
110 sample_output = self._read_sample_output(self.sample_output['write'])
111 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
115 expected_result = '{"write_bw": 35107, "write_iops": 8776,'\
116 '"write_lat": 111.74}'
117 expected_result = json.loads(expected_result)
118 self.assertEqual(result, expected_result)
120 def test_fio_successful_lat_sla(self, mock_ssh):
122 p = fio.Fio(self.ctx)
124 'filename': '/home/ec2-user/data.raw',
131 'sla': {'write_lat': 300.1}
134 p.client = mock_ssh.SSH()
136 sample_output = self._read_sample_output(self.sample_output['rw'])
137 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
141 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
142 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
143 '"write_lat": 233.55}'
144 expected_result = json.loads(expected_result)
145 self.assertEqual(result, expected_result)
148 def test_fio_unsuccessful_lat_sla(self, mock_ssh):
150 p = fio.Fio(self.ctx)
152 'filename': '/home/ec2-user/data.raw',
159 'sla': {'write_lat': 200.1}
162 p.client = mock_ssh.SSH()
164 sample_output = self._read_sample_output(self.sample_output['rw'])
165 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
166 self.assertRaises(AssertionError, p.run, args)
168 def test_fio_successful_bw_iops_sla(self, mock_ssh):
170 p = fio.Fio(self.ctx)
172 'filename': '/home/ec2-user/data.raw',
179 'sla': {'read_iops': 20000}
182 p.client = mock_ssh.SSH()
184 sample_output = self._read_sample_output(self.sample_output['rw'])
185 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
189 expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
190 '"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
191 '"write_lat": 233.55}'
192 expected_result = json.loads(expected_result)
193 self.assertEqual(result, expected_result)
195 def test_fio_unsuccessful_bw_iops_sla(self, mock_ssh):
197 p = fio.Fio(self.ctx)
199 'filename': '/home/ec2-user/data.raw',
206 'sla': {'read_iops': 30000}
209 p.client = mock_ssh.SSH()
211 sample_output = self._read_sample_output(self.sample_output['rw'])
212 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
213 self.assertRaises(AssertionError, p.run, args)
215 def test_fio_unsuccessful_script_error(self, mock_ssh):
217 p = fio.Fio(self.ctx)
219 'filename': '/home/ec2-user/data.raw',
224 args = {'options': options}
225 p.client = mock_ssh.SSH()
227 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
228 self.assertRaises(RuntimeError, p.run, args)
230 def _read_sample_output(self, file_name):
231 curr_path = os.path.dirname(os.path.abspath(__file__))
232 output = os.path.join(curr_path, file_name)
233 with open(output) as f:
234 sample_output = f.read()
240 if __name__ == '__main__':