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
21 from yardstick.common import exceptions as y_exc
24 @mock.patch('yardstick.benchmark.scenarios.compute.ramspeed.ssh')
25 class RamspeedTestCase(unittest.TestCase):
32 'key_filename': "mykey.key"
38 def test_ramspeed_successful_setup(self, mock_ssh):
40 r = ramspeed.Ramspeed({}, self.ctx)
41 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
44 self.assertIsNotNone(r.client)
45 self.assertTrue(r.setup_done, True)
47 def test_ramspeed_successful__run_no_sla(self, mock_ssh):
54 args = {"options": options}
55 r = ramspeed.Ramspeed(args, self.ctx)
57 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
58 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
59 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
60 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
61 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
62 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
63 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
64 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
65 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
66 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
67 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
68 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
69 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
70 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
71 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
72 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
73 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
74 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
75 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
76 "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
77 "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
78 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
80 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
81 self.assertEqual(self.result, expected_result)
83 def test_ramspeed_successful_run_sla(self, mock_ssh):
90 args = {"options": options, "sla": {"min_bandwidth": 6000}}
91 r = ramspeed.Ramspeed(args, self.ctx)
93 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
94 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
95 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
96 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
97 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
98 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
99 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
100 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
101 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
102 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
103 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
104 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
105 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
106 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
107 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
108 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
109 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
110 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
111 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
112 "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
113 "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
114 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
116 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
117 self.assertEqual(self.result, expected_result)
119 def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
125 args = {"options": options, "sla": {"min_bandwidth": 100000}}
126 r = ramspeed.Ramspeed(args, self.ctx)
128 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
129 "Block_size(kb)": 1, "Bandwidth(MBps)": 5000.18}, {"Test_type":\
130 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 5000.89},\
131 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4,\
132 "Bandwidth(MBps)": 5000.56}, {"Test_type": "INTEGER & WRITING",\
133 "Block_size(kb)": 8, "Bandwidth(MBps)": 19906.94}, {"Test_type":\
134 "INTEGER & WRITING", "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74},\
135 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32,\
136 "Bandwidth(MBps)": 19395.65}, {"Test_type": "INTEGER & WRITING",\
137 "Block_size(kb)": 64, "Bandwidth(MBps)": 17623.14}, {"Test_type":\
138 "INTEGER & WRITING", "Block_size(kb)": 128, "Bandwidth(MBps)": 17677.36},\
139 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 256, "Bandwidth(MBps)":\
140 16113.49}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 512,\
141 "Bandwidth(MBps)": 14659.19}, {"Test_type": "INTEGER & WRITING",\
142 "Block_size(kb)": 1024, "Bandwidth(MBps)": 14680.75}, {"Test_type":\
143 "INTEGER & WRITING", "Block_size(kb)": 2048, "Bandwidth(MBps)": 14756.45},\
144 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4096, "Bandwidth(MBps)":\
145 14604.44}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8192,\
146 "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\
147 "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\
148 "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
149 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
150 self.assertRaises(y_exc.SLAValidationError, r.run, self.result)
152 def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
158 args = {"options": options}
159 r = ramspeed.Ramspeed(args, self.ctx)
161 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
162 self.assertRaises(RuntimeError, r.run, self.result)
164 def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh):
171 args = {"options": options}
172 r = ramspeed.Ramspeed(args, self.ctx)
174 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
175 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
176 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
177 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
178 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
179 "Bandwidth(MBps)": 9401.58}]}'
180 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
182 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
183 self.assertEqual(self.result, expected_result)
185 def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
192 args = {"options": options, "sla": {"min_bandwidth": 6000}}
193 r = ramspeed.Ramspeed(args, self.ctx)
195 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
196 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
197 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
198 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
199 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
200 "Bandwidth(MBps)": 9401.58}]}'
201 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
203 expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
204 self.assertEqual(self.result, expected_result)
206 def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
213 args = {"options": options, "sla": {"min_bandwidth": 86000}}
214 r = ramspeed.Ramspeed(args, self.ctx)
216 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
217 "Bandwidth(MBps)": 4000.97}, {"Test_type": "INTEGER Scale:",\
218 "Bandwidth(MBps)": 4400.59}, {"Test_type": "INTEGER Add:",\
219 "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\
220 "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\
221 "Bandwidth(MBps)": 2401.58}]}'
222 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
223 self.assertRaises(y_exc.SLAValidationError, r.run, self.result)
225 def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh):
231 args = {'options': options}
232 r = ramspeed.Ramspeed(args, self.ctx)
234 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'No such type_id: 30 for \
236 self.assertRaises(RuntimeError, r.run, self.result)