1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd 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.compute.ramspeed.Ramspeed
12 from __future__ import absolute_import
17 from oslo_serialization import jsonutils
19 from yardstick.common import utils
20 from yardstick.benchmark.scenarios.compute import ramspeed
23 @mock.patch('yardstick.benchmark.scenarios.compute.ramspeed.ssh')
24 class RamspeedTestCase(unittest.TestCase):
31 'key_filename': "mykey.key"
37 def test_ramspeed_successful_setup(self, mock_ssh):
39 r = ramspeed.Ramspeed({}, self.ctx)
40 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
43 self.assertIsNotNone(r.client)
44 self.assertTrue(r.setup_done, True)
46 def test_ramspeed_successful__run_no_sla(self, mock_ssh):
53 args = {"options": options}
54 r = ramspeed.Ramspeed(args, self.ctx)
56 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
57 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
58 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
59 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
60 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
61 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
62 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
63 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
64 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
65 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
66 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
67 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
68 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
69 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
70 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
71 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
72 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
73 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
74 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
75 "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
76 "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
77 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
79 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
80 self.assertEqual(self.result, expected_result)
82 def test_ramspeed_successful_run_sla(self, mock_ssh):
89 args = {"options": options, "sla": {"min_bandwidth": 6000}}
90 r = ramspeed.Ramspeed(args, self.ctx)
92 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
93 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
94 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
95 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
96 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
97 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
98 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
99 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
100 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
101 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
102 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
103 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
104 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
105 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
106 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
107 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
108 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
109 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
110 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
111 "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
112 "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
113 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
115 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
116 self.assertEqual(self.result, expected_result)
118 def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
124 args = {"options": options, "sla": {"min_bandwidth": 100000}}
125 r = ramspeed.Ramspeed(args, self.ctx)
127 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
128 "Block_size(kb)": 1, "Bandwidth(MBps)": 5000.18}, {"Test_type":\
129 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 5000.89},\
130 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4,\
131 "Bandwidth(MBps)": 5000.56}, {"Test_type": "INTEGER & WRITING",\
132 "Block_size(kb)": 8, "Bandwidth(MBps)": 19906.94}, {"Test_type":\
133 "INTEGER & WRITING", "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74},\
134 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32,\
135 "Bandwidth(MBps)": 19395.65}, {"Test_type": "INTEGER & WRITING",\
136 "Block_size(kb)": 64, "Bandwidth(MBps)": 17623.14}, {"Test_type":\
137 "INTEGER & WRITING", "Block_size(kb)": 128, "Bandwidth(MBps)": 17677.36},\
138 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 256, "Bandwidth(MBps)":\
139 16113.49}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 512,\
140 "Bandwidth(MBps)": 14659.19}, {"Test_type": "INTEGER & WRITING",\
141 "Block_size(kb)": 1024, "Bandwidth(MBps)": 14680.75}, {"Test_type":\
142 "INTEGER & WRITING", "Block_size(kb)": 2048, "Bandwidth(MBps)": 14756.45},\
143 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4096, "Bandwidth(MBps)":\
144 14604.44}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8192,\
145 "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\
146 "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\
147 "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
148 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
149 self.assertRaises(AssertionError, r.run, self.result)
151 def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
157 args = {"options": options}
158 r = ramspeed.Ramspeed(args, self.ctx)
160 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
161 self.assertRaises(RuntimeError, r.run, self.result)
163 def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh):
170 args = {"options": options}
171 r = ramspeed.Ramspeed(args, self.ctx)
173 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
174 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
175 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
176 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
177 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
178 "Bandwidth(MBps)": 9401.58}]}'
179 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
181 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
182 self.assertEqual(self.result, expected_result)
184 def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
191 args = {"options": options, "sla": {"min_bandwidth": 6000}}
192 r = ramspeed.Ramspeed(args, self.ctx)
194 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
195 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
196 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
197 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
198 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
199 "Bandwidth(MBps)": 9401.58}]}'
200 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
202 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
203 self.assertEqual(self.result, expected_result)
205 def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
212 args = {"options": options, "sla": {"min_bandwidth": 86000}}
213 r = ramspeed.Ramspeed(args, self.ctx)
215 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
216 "Bandwidth(MBps)": 4000.97}, {"Test_type": "INTEGER Scale:",\
217 "Bandwidth(MBps)": 4400.59}, {"Test_type": "INTEGER Add:",\
218 "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\
219 "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\
220 "Bandwidth(MBps)": 2401.58}]}'
221 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
222 self.assertRaises(AssertionError, r.run, self.result)
224 def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh):
230 args = {'options': options}
231 r = ramspeed.Ramspeed(args, self.ctx)
233 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'No such type_id: 30 for \
235 self.assertRaises(RuntimeError, r.run, self.result)