3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd 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.compute.ramspeed.Ramspeed
14 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.common import utils
22 from yardstick.benchmark.scenarios.compute import ramspeed
25 @mock.patch('yardstick.benchmark.scenarios.compute.ramspeed.ssh')
26 class RamspeedTestCase(unittest.TestCase):
33 'key_filename': "mykey.key"
39 def test_ramspeed_successful_setup(self, mock_ssh):
41 r = ramspeed.Ramspeed({}, self.ctx)
42 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
45 self.assertIsNotNone(r.client)
46 self.assertTrue(r.setup_done, True)
48 def test_ramspeed_successful__run_no_sla(self, mock_ssh):
55 args = {"options": options}
56 r = ramspeed.Ramspeed(args, self.ctx)
58 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
59 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
60 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
61 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
62 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
63 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
64 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
65 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
66 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
67 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
68 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
69 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
70 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
71 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
72 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
73 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
74 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
75 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
76 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
77 "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
78 "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
79 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
81 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
82 self.assertEqual(self.result, expected_result)
84 def test_ramspeed_successful_run_sla(self, mock_ssh):
91 args = {"options": options, "sla": {"min_bandwidth": 6000}}
92 r = ramspeed.Ramspeed(args, self.ctx)
94 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
95 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
96 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
97 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
98 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
99 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
100 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
101 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
102 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
103 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
104 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
105 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
106 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
107 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
108 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
109 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
110 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
111 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
112 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
113 "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
114 "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
115 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
117 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
118 self.assertEqual(self.result, expected_result)
120 def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
126 args = {"options": options, "sla": {"min_bandwidth": 100000}}
127 r = ramspeed.Ramspeed(args, self.ctx)
129 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
130 "Block_size(kb)": 1, "Bandwidth(MBps)": 5000.18}, {"Test_type":\
131 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 5000.89},\
132 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4,\
133 "Bandwidth(MBps)": 5000.56}, {"Test_type": "INTEGER & WRITING",\
134 "Block_size(kb)": 8, "Bandwidth(MBps)": 19906.94}, {"Test_type":\
135 "INTEGER & WRITING", "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74},\
136 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32,\
137 "Bandwidth(MBps)": 19395.65}, {"Test_type": "INTEGER & WRITING",\
138 "Block_size(kb)": 64, "Bandwidth(MBps)": 17623.14}, {"Test_type":\
139 "INTEGER & WRITING", "Block_size(kb)": 128, "Bandwidth(MBps)": 17677.36},\
140 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 256, "Bandwidth(MBps)":\
141 16113.49}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 512,\
142 "Bandwidth(MBps)": 14659.19}, {"Test_type": "INTEGER & WRITING",\
143 "Block_size(kb)": 1024, "Bandwidth(MBps)": 14680.75}, {"Test_type":\
144 "INTEGER & WRITING", "Block_size(kb)": 2048, "Bandwidth(MBps)": 14756.45},\
145 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4096, "Bandwidth(MBps)":\
146 14604.44}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8192,\
147 "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\
148 "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\
149 "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
150 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
151 self.assertRaises(AssertionError, r.run, self.result)
153 def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
159 args = {"options": options}
160 r = ramspeed.Ramspeed(args, self.ctx)
162 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
163 self.assertRaises(RuntimeError, r.run, self.result)
165 def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh):
172 args = {"options": options}
173 r = ramspeed.Ramspeed(args, self.ctx)
175 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
176 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
177 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
178 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
179 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
180 "Bandwidth(MBps)": 9401.58}]}'
181 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
183 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
184 self.assertEqual(self.result, expected_result)
186 def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
193 args = {"options": options, "sla": {"min_bandwidth": 6000}}
194 r = ramspeed.Ramspeed(args, self.ctx)
196 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
197 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
198 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
199 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
200 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
201 "Bandwidth(MBps)": 9401.58}]}'
202 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
204 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
205 self.assertEqual(self.result, expected_result)
207 def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
214 args = {"options": options, "sla": {"min_bandwidth": 86000}}
215 r = ramspeed.Ramspeed(args, self.ctx)
217 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
218 "Bandwidth(MBps)": 4000.97}, {"Test_type": "INTEGER Scale:",\
219 "Bandwidth(MBps)": 4400.59}, {"Test_type": "INTEGER Add:",\
220 "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\
221 "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\
222 "Bandwidth(MBps)": 2401.58}]}'
223 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
224 self.assertRaises(AssertionError, r.run, self.result)
226 def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh):
232 args = {'options': options}
233 r = ramspeed.Ramspeed(args, self.ctx)
235 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'No such type_id: 30 for \
237 self.assertRaises(RuntimeError, r.run, self.result)
243 if __name__ == '__main__':