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