3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd.
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.storage.storperf.StorPerf
14 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.benchmark.scenarios.storage import storperf
24 def mocked_requests_config_post(*args, **kwargs):
25 class MockResponseConfigPost:
27 def __init__(self, json_data, status_code):
28 self.content = json_data
29 self.status_code = status_code
31 return MockResponseConfigPost(
32 '{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622",'
33 '"stack_created": "false"}',
37 def mocked_requests_config_get(*args, **kwargs):
38 class MockResponseConfigGet:
40 def __init__(self, json_data, status_code):
41 self.content = json_data
42 self.status_code = status_code
44 return MockResponseConfigGet(
45 '{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622",'
46 '"stack_created": "true"}',
50 def mocked_requests_job_get(*args, **kwargs):
51 class MockResponseJobGet:
53 def __init__(self, json_data, status_code):
54 self.content = json_data
55 self.status_code = status_code
57 return MockResponseJobGet(
58 '{"status": "completed",\
59 "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}',
63 def mocked_requests_job_post(*args, **kwargs):
64 class MockResponseJobPost:
66 def __init__(self, json_data, status_code):
67 self.content = json_data
68 self.status_code = status_code
70 return MockResponseJobPost('{"job_id": \
71 "d46bfb8c-36f4-4a40-813b-c4b4a437f728"}', 200)
74 def mocked_requests_job_delete(*args, **kwargs):
75 class MockResponseJobDelete:
77 def __init__(self, json_data, status_code):
78 self.content = json_data
79 self.status_code = status_code
81 return MockResponseJobDelete('{}', 200)
84 def mocked_requests_delete(*args, **kwargs):
85 class MockResponseDelete:
87 def __init__(self, json_data, status_code):
88 self.json_data = json_data
89 self.status_code = status_code
91 return MockResponseDelete('{}', 200)
94 def mocked_requests_delete_failed(*args, **kwargs):
95 class MockResponseDeleteFailed:
97 def __init__(self, json_data, status_code):
98 self.json_data = json_data
99 self.status_code = status_code
101 if args[0] == "http://172.16.0.137:5000/api/v1.0/configurations":
102 return MockResponseDeleteFailed('{"message": "Teardown failed"}', 400)
104 return MockResponseDeleteFailed('{}', 404)
107 class StorPerfTestCase(unittest.TestCase):
112 'ip': '172.16.0.137',
114 'key_filename': "mykey.key"
120 @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.post',
121 side_effect=mocked_requests_config_post)
122 @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.get',
123 side_effect=mocked_requests_config_get)
124 def test_successful_setup(self, mock_post, mock_get):
127 "public_network": 'ext-net',
132 "StorPerf_ip": "192.168.23.2",
133 "query_interval": 10,
141 s = storperf.StorPerf(args, self.ctx)
145 self.assertTrue(s.setup_done)
147 @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.post',
148 side_effect=mocked_requests_job_post)
149 @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.get',
150 side_effect=mocked_requests_job_get)
152 'yardstick.benchmark.scenarios.storage.storperf.requests.delete',
153 side_effect=mocked_requests_job_delete)
154 def test_successful_run(self, mock_post, mock_get, mock_delete):
157 "public_network": 'ext-net',
162 "StorPerf_ip": "192.168.23.2",
163 "query_interval": 10,
171 s = storperf.StorPerf(args, self.ctx)
174 sample_output = '{"status": "completed",\
175 "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}'
177 expected_result = jsonutils.loads(sample_output)
181 self.assertEqual(self.result, expected_result)
184 'yardstick.benchmark.scenarios.storage.storperf.requests.delete',
185 side_effect=mocked_requests_delete)
186 def test_successful_teardown(self, mock_delete):
189 "public_network": 'ext-net',
194 "StorPerf_ip": "192.168.23.2",
195 "query_interval": 10,
203 s = storperf.StorPerf(args, self.ctx)
207 self.assertFalse(s.setup_done)
210 'yardstick.benchmark.scenarios.storage.storperf.requests.delete',
211 side_effect=mocked_requests_delete_failed)
212 def test_failed_teardown(self, mock_delete):
215 "public_network": 'ext-net',
220 "StorPerf_ip": "192.168.23.2",
221 "query_interval": 10,
229 s = storperf.StorPerf(args, self.ctx)
231 self.assertRaises(AssertionError, s.teardown(), self.result)
237 if __name__ == '__main__':