summaryrefslogtreecommitdiff
path: root/openstack_dashboard/test/api_tests/heat_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstack_dashboard/test/api_tests/heat_tests.py')
-rw-r--r--openstack_dashboard/test/api_tests/heat_tests.py358
1 files changed, 0 insertions, 358 deletions
diff --git a/openstack_dashboard/test/api_tests/heat_tests.py b/openstack_dashboard/test/api_tests/heat_tests.py
deleted file mode 100644
index d241277..0000000
--- a/openstack_dashboard/test/api_tests/heat_tests.py
+++ /dev/null
@@ -1,358 +0,0 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12import six
13
14from django.conf import settings
15from django.test.utils import override_settings
16
17from horizon import exceptions
18from openstack_dashboard import api
19from openstack_dashboard.test import helpers as test
20
21
22class HeatApiTests(test.APITestCase):
23 def test_stack_list(self):
24 api_stacks = self.stacks.list()
25 limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
26
27 heatclient = self.stub_heatclient()
28 heatclient.stacks = self.mox.CreateMockAnything()
29 heatclient.stacks.list(limit=limit,
30 sort_dir='desc',
31 sort_key='created_at',) \
32 .AndReturn(iter(api_stacks))
33 self.mox.ReplayAll()
34 stacks, has_more, has_prev = api.heat.stacks_list(self.request)
35 self.assertItemsEqual(stacks, api_stacks)
36 self.assertFalse(has_more)
37 self.assertFalse(has_prev)
38
39 @override_settings(API_RESULT_PAGE_SIZE=2)
40 def test_stack_list_sort_options(self):
41 # Verify that sort_dir and sort_key work
42 api_stacks = self.stacks.list()
43 limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
44 sort_dir = 'asc'
45 sort_key = 'size'
46
47 heatclient = self.stub_heatclient()
48 heatclient.stacks = self.mox.CreateMockAnything()
49 heatclient.stacks.list(limit=limit,
50 sort_dir=sort_dir,
51 sort_key=sort_key,) \
52 .AndReturn(iter(api_stacks))
53 self.mox.ReplayAll()
54
55 stacks, has_more, has_prev = api.heat.stacks_list(self.request,
56 sort_dir=sort_dir,
57 sort_key=sort_key)
58 self.assertItemsEqual(stacks, api_stacks)
59 self.assertFalse(has_more)
60 self.assertFalse(has_prev)
61
62 @override_settings(API_RESULT_PAGE_SIZE=20)
63 def test_stack_list_pagination_less_page_size(self):
64 api_stacks = self.stacks.list()
65 page_size = settings.API_RESULT_PAGE_SIZE
66 sort_dir = 'desc'
67 sort_key = 'created_at'
68
69 heatclient = self.stub_heatclient()
70 heatclient.stacks = self.mox.CreateMockAnything()
71 heatclient.stacks.list(limit=page_size + 1,
72 sort_dir=sort_dir,
73 sort_key=sort_key,) \
74 .AndReturn(iter(api_stacks))
75 self.mox.ReplayAll()
76
77 stacks, has_more, has_prev = api.heat.stacks_list(self.request,
78 sort_dir=sort_dir,
79 sort_key=sort_key,
80 paginate=True)
81 expected_stacks = api_stacks[:page_size]
82 self.assertItemsEqual(stacks, expected_stacks)
83 self.assertFalse(has_more)
84 self.assertFalse(has_prev)
85
86 @override_settings(API_RESULT_PAGE_SIZE=10)
87 def test_stack_list_pagination_equal_page_size(self):
88 api_stacks = self.stacks.list()
89 page_size = settings.API_RESULT_PAGE_SIZE
90 sort_dir = 'desc'
91 sort_key = 'created_at'
92
93 heatclient = self.stub_heatclient()
94 heatclient.stacks = self.mox.CreateMockAnything()
95 heatclient.stacks.list(limit=page_size + 1,
96 sort_dir=sort_dir,
97 sort_key=sort_key,) \
98 .AndReturn(iter(api_stacks))
99 self.mox.ReplayAll()
100
101 stacks, has_more, has_prev = api.heat.stacks_list(self.request,
102 sort_dir=sort_dir,
103 sort_key=sort_key,
104 paginate=True)
105 expected_stacks = api_stacks[:page_size]
106 self.assertItemsEqual(stacks, expected_stacks)
107 self.assertFalse(has_more)
108 self.assertFalse(has_prev)
109
110 @override_settings(API_RESULT_PAGE_SIZE=2)
111 def test_stack_list_pagination_marker(self):
112 page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20)
113 sort_dir = 'desc'
114 sort_key = 'created_at'
115 marker = 'nonsense'
116
117 api_stacks = self.stacks.list()
118
119 heatclient = self.stub_heatclient()
120 heatclient.stacks = self.mox.CreateMockAnything()
121 heatclient.stacks.list(limit=page_size + 1,
122 marker=marker,
123 sort_dir=sort_dir,
124 sort_key=sort_key,) \
125 .AndReturn(iter(api_stacks[:page_size + 1]))
126 self.mox.ReplayAll()
127
128 stacks, has_more, has_prev = api.heat.stacks_list(self.request,
129 marker=marker,
130 paginate=True,
131 sort_dir=sort_dir,
132 sort_key=sort_key,)
133
134 self.assertEqual(len(stacks), page_size)
135 self.assertItemsEqual(stacks, api_stacks[:page_size])
136 self.assertTrue(has_more)
137 self.assertTrue(has_prev)
138
139 @override_settings(API_RESULT_PAGE_SIZE=2)
140 def test_stack_list_pagination_marker_prev(self):
141 page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20)
142 sort_dir = 'asc'
143 sort_key = 'created_at'
144 marker = 'nonsense'
145
146 api_stacks = self.stacks.list()
147
148 heatclient = self.stub_heatclient()
149 heatclient.stacks = self.mox.CreateMockAnything()
150 heatclient.stacks.list(limit=page_size + 1,
151 marker=marker,
152 sort_dir=sort_dir,
153 sort_key=sort_key,) \
154 .AndReturn(iter(api_stacks[:page_size + 1]))
155 self.mox.ReplayAll()
156
157 stacks, has_more, has_prev = api.heat.stacks_list(self.request,
158 marker=marker,
159 paginate=True,
160 sort_dir=sort_dir,
161 sort_key=sort_key,)
162
163 self.assertEqual(len(stacks), page_size)
164 self.assertItemsEqual(stacks, api_stacks[:page_size])
165 self.assertTrue(has_more)
166 self.assertTrue(has_prev)
167
168 def test_template_get(self):
169 api_stacks = self.stacks.list()
170 stack_id = api_stacks[0].id
171 mock_data_template = self.stack_templates.list()[0]
172
173 heatclient = self.stub_heatclient()
174 heatclient.stacks = self.mox.CreateMockAnything()
175 heatclient.stacks.template(stack_id).AndReturn(mock_data_template)
176 self.mox.ReplayAll()
177
178 template = api.heat.template_get(self.request, stack_id)
179 self.assertEqual(mock_data_template.data, template.data)
180
181 def test_stack_create(self):
182 api_stacks = self.stacks.list()
183 stack = api_stacks[0]
184
185 heatclient = self.stub_heatclient()
186 heatclient.stacks = self.mox.CreateMockAnything()
187 form_data = {'timeout_mins': 600}
188 password = 'secret'
189 heatclient.stacks.create(**form_data).AndReturn(stack)
190 self.mox.ReplayAll()
191
192 returned_stack = api.heat.stack_create(self.request,
193 password,
194 **form_data)
195 from heatclient.v1 import stacks
196 self.assertIsInstance(returned_stack, stacks.Stack)
197
198 def test_stack_update(self):
199 api_stacks = self.stacks.list()
200 stack = api_stacks[0]
201 stack_id = stack.id
202
203 heatclient = self.stub_heatclient()
204 heatclient.stacks = self.mox.CreateMockAnything()
205 form_data = {'timeout_mins': 600}
206 password = 'secret'
207 heatclient.stacks.update(stack_id, **form_data).AndReturn(stack)
208 self.mox.ReplayAll()
209
210 returned_stack = api.heat.stack_update(self.request,
211 stack_id,
212 password,
213 **form_data)
214 from heatclient.v1 import stacks
215 self.assertIsInstance(returned_stack, stacks.Stack)
216
217 def test_snapshot_create(self):
218 stack_id = self.stacks.first().id
219 snapshot_create = self.stack_snapshot_create.list()[0]
220
221 heatclient = self.stub_heatclient()
222 heatclient.stacks = self.mox.CreateMockAnything()
223 heatclient.stacks.snapshot(stack_id).AndReturn(snapshot_create)
224 self.mox.ReplayAll()
225
226 returned_snapshot_create_info = api.heat.snapshot_create(self.request,
227 stack_id)
228
229 self.assertEqual(returned_snapshot_create_info, snapshot_create)
230
231 def test_snapshot_list(self):
232 stack_id = self.stacks.first().id
233 snapshot_list = self.stack_snapshot.list()
234
235 heatclient = self.stub_heatclient()
236 heatclient.stacks = self.mox.CreateMockAnything()
237 heatclient.stacks.snapshot_list(stack_id).AndReturn(snapshot_list)
238 self.mox.ReplayAll()
239
240 returned_snapshots = api.heat.snapshot_list(self.request, stack_id)
241
242 self.assertItemsEqual(returned_snapshots, snapshot_list)
243
244 def test_get_template_files_with_template_data(self):
245 tmpl = '''
246 # comment
247
248 heat_template_version: 2013-05-23
249 resources:
250 server1:
251 type: OS::Nova::Server
252 properties:
253 flavor: m1.medium
254 image: cirros
255 '''
256 expected_files = {}
257 files = api.heat.get_template_files(template_data=tmpl)[0]
258 self.assertEqual(files, expected_files)
259
260 def test_get_template_files(self):
261 tmpl = '''
262 # comment
263
264 heat_template_version: 2013-05-23
265 resources:
266 server1:
267 type: OS::Nova::Server
268 properties:
269 flavor: m1.medium
270 image: cirros
271 user_data_format: RAW
272 user_data:
273 get_file: http://test.example/example
274 '''
275 expected_files = {u'http://test.example/example': b'echo "test"'}
276 url = 'http://test.example/example'
277 data = b'echo "test"'
278 self.mox.StubOutWithMock(six.moves.urllib.request, 'urlopen')
279 six.moves.urllib.request.urlopen(url).AndReturn(
280 six.BytesIO(data))
281 self.mox.ReplayAll()
282 files = api.heat.get_template_files(template_data=tmpl)[0]
283 self.assertEqual(files, expected_files)
284
285 def test_get_template_files_with_template_url(self):
286 url = 'https://test.example/example.yaml'
287 data = b'''
288 # comment
289
290 heat_template_version: 2013-05-23
291 resources:
292 server1:
293 type: OS::Nova::Server
294 properties:
295 flavor: m1.medium
296 image: cirros
297 user_data_format: RAW
298 user_data:
299 get_file: http://test.example/example
300 '''
301 url2 = 'http://test.example/example'
302 data2 = b'echo "test"'
303 expected_files = {'http://test.example/example': b'echo "test"'}
304 self.mox.StubOutWithMock(six.moves.urllib.request, 'urlopen')
305 six.moves.urllib.request.urlopen(url).AndReturn(
306 six.BytesIO(data))
307 six.moves.urllib.request.urlopen(url2).AndReturn(
308 six.BytesIO(data2))
309 self.mox.ReplayAll()
310 files = api.heat.get_template_files(template_url=url)[0]
311 self.assertEqual(files, expected_files)
312
313 def test_get_template_files_invalid(self):
314 tmpl = '''
315 # comment
316
317 heat_template_version: 2013-05-23
318 resources:
319 server1:
320 type: OS::Nova::Server
321 properties:
322 flavor: m1.medium
323 image: cirros
324 user_data_format: RAW
325 user_data:
326 get_file: file:///example
327 '''
328 try:
329 api.heat.get_template_files(template_data=tmpl)[0]
330 except exceptions.GetFileError:
331 self.assertRaises(exceptions.GetFileError)
332
333 def test_template_version_list(self):
334 api_template_versions = self.template_versions.list()
335
336 heatclient = self.stub_heatclient()
337 heatclient.template_versions = self.mox.CreateMockAnything()
338 heatclient.template_versions.list().AndReturn(api_template_versions)
339 self.mox.ReplayAll()
340
341 template_versions = api.heat.template_version_list(self.request)
342
343 self.assertItemsEqual(template_versions, api_template_versions)
344
345 def test_template_function_list(self):
346 template_version = self.template_versions.first().version
347 api_template_functions = self.template_functions.list()
348
349 heatclient = self.stub_heatclient()
350 heatclient.template_versions = self.mox.CreateMockAnything()
351 heatclient.template_versions.get(
352 template_version).AndReturn(api_template_functions)
353 self.mox.ReplayAll()
354
355 template_functions = api.heat.template_function_list(
356 self.request, template_version)
357
358 self.assertItemsEqual(template_functions, api_template_functions)