standardize ssh auth
[yardstick.git] / tests / unit / benchmark / scenarios / compute / test_ramspeed.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 #
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 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.compute.ramspeed.Ramspeed
13
14 from __future__ import absolute_import
15
16 import unittest
17
18 import mock
19 from oslo_serialization import jsonutils
20
21 from yardstick.benchmark.scenarios.compute import ramspeed
22
23
24 @mock.patch('yardstick.benchmark.scenarios.compute.ramspeed.ssh')
25 class RamspeedTestCase(unittest.TestCase):
26
27     def setUp(self):
28         self.ctx = {
29             'host': {
30                 'ip': '172.16.0.137',
31                 'user': 'root',
32                 'key_filename': "mykey.key"
33             }
34         }
35
36         self.result = {}
37
38     def test_ramspeed_successful_setup(self, mock_ssh):
39
40         r = ramspeed.Ramspeed({}, self.ctx)
41         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
42
43         r.setup()
44         self.assertIsNotNone(r.client)
45         self.assertTrue(r.setup_done, True)
46
47     def test_ramspeed_successful__run_no_sla(self, mock_ssh):
48
49         options = {
50             "test_id": 1,
51             "load": 16,
52             "block_size": 32
53         }
54         args = {"options": options}
55         r = ramspeed.Ramspeed(args, self.ctx)
56
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, '')
79         r.run(self.result)
80         expected_result = jsonutils.loads(sample_output)
81         self.assertEqual(self.result, expected_result)
82
83     def test_ramspeed_successful_run_sla(self, mock_ssh):
84
85         options = {
86             "test_id": 1,
87             "load": 16,
88             "block_size": 32
89         }
90         args = {"options": options, "sla": {"min_bandwidth": 6000}}
91         r = ramspeed.Ramspeed(args, self.ctx)
92
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, '')
115         r.run(self.result)
116         expected_result = jsonutils.loads(sample_output)
117         self.assertEqual(self.result, expected_result)
118
119     def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
120         options = {
121             "test_id": 1,
122             "load": 8,
123             "block_size": 64
124         }
125         args = {"options": options, "sla": {"min_bandwidth": 100000}}
126         r = ramspeed.Ramspeed(args, self.ctx)
127
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(AssertionError, r.run, self.result)
151
152     def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
153         options = {
154             "test_id": 1,
155             "load": 16,
156             "block_size": 32
157         }
158         args = {"options": options}
159         r = ramspeed.Ramspeed(args, self.ctx)
160
161         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
162         self.assertRaises(RuntimeError, r.run, self.result)
163
164     def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh):
165         options = {
166             "test_id": 3,
167             "load": 16,
168             "block_size": 32,
169             "iteration": 1
170         }
171         args = {"options": options}
172         r = ramspeed.Ramspeed(args, self.ctx)
173
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, '')
181         r.run(self.result)
182         expected_result = jsonutils.loads(sample_output)
183         self.assertEqual(self.result, expected_result)
184
185     def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
186         options = {
187             "test_id": 3,
188             "load": 16,
189             "block_size": 32,
190             "iteration": 1
191         }
192         args = {"options": options, "sla": {"min_bandwidth": 6000}}
193         r = ramspeed.Ramspeed(args, self.ctx)
194
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, '')
202         r.run(self.result)
203         expected_result = jsonutils.loads(sample_output)
204         self.assertEqual(self.result, expected_result)
205
206     def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
207         options = {
208             "test_id": 3,
209             "load": 16,
210             "block_size": 32,
211             "iteration": 1
212         }
213         args = {"options": options, "sla": {"min_bandwidth": 86000}}
214         r = ramspeed.Ramspeed(args, self.ctx)
215
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(AssertionError, r.run, self.result)
224
225     def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh):
226         options = {
227             "test_id": 30,
228             "load": 16,
229             "block_size": 32
230         }
231         args = {'options': options}
232         r = ramspeed.Ramspeed(args, self.ctx)
233
234         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'No such type_id: 30 for \
235                                                Ramspeed scenario')
236         self.assertRaises(RuntimeError, r.run, self.result)
237
238
239 def main():
240     unittest.main()
241
242 if __name__ == '__main__':
243     main()