Debian Codegraph @

magnum_tempest_plugin/common/templates/cluster_template.py

raw
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.
12
13
14 from tempest.lib.common.utils import data_utils
15 from tempest.lib import exceptions
16 import testtools
17
18 from magnum_tempest_plugin.common import datagen
19 from magnum_tempest_plugin.tests.api import base
20
21
22 class ClusterTemplateTestTemplate(base.BaseTempestTest):
23
24 """Template for tests for clustertemplate CRUD."""
25
26 def __init__(self, *args, **kwargs):
27 super().__init__(*args, **kwargs)
28 self.cluster_templates = []
29
30 def tearDown(self):
31 for cluster_template_id in self.cluster_templates:
32 self._delete_cluster_template(cluster_template_id)
33 self.cluster_templates.remove(cluster_template_id)
34 super().tearDown()
35
36 def _create_cluster_template(self, cmodel_model):
37 resp, model = \
38 self.ct_member_client.post_cluster_template(cmodel_model)
39 self.assertEqual(201, resp.status)
40 self.cluster_templates.append(model.uuid)
41 return resp, model
42
43 def _delete_cluster_template(self, model_id):
44 resp, model = \
45 self.ct_member_client.delete_cluster_template(model_id)
46 self.assertEqual(204, resp.status)
47 return resp, model
48
49 @testtools.testcase.attr('positive')
50 def test_list_cluster_templates(self):
51 gen_model = \
52 datagen.cluster_template_data_with_valid_keypair_image_flavor()
53 _, temp_model = self._create_cluster_template(gen_model)
54 resp, model = self.ct_reader_client.list_cluster_templates()
55 self.assertEqual(200, resp.status)
56 self.assertGreater(len(model.clustertemplates), 0)
57 self.assertIn(
58 temp_model.uuid,
59 list([x['uuid'] for x in model.clustertemplates]))
60
61 @testtools.testcase.attr('positive')
62 def test_create_cluster_template(self):
63 gen_model = \
64 datagen.cluster_template_data_with_valid_keypair_image_flavor()
65 resp, model = self._create_cluster_template(gen_model)
66
67 @testtools.testcase.attr('positive')
68 def test_create_get_public_cluster_template(self):
69 gen_model = datagen.valid_cluster_template(is_public=True)
70 self.assertRaises(
71 exceptions.Forbidden,
72 self.ct_member_client.post_cluster_template, gen_model)
73
74 @testtools.testcase.attr('positive')
75 def test_update_cluster_template_public_by_uuid(self):
76 path = "/public"
77 gen_model = \
78 datagen.cluster_template_data_with_valid_keypair_image_flavor()
79 resp, old_model = self._create_cluster_template(gen_model)
80
81 patch_model = datagen.cluster_template_replace_patch_data(path,
82 value=True)
83 self.assertRaises(
84 exceptions.Forbidden,
85 self.ct_member_client.patch_cluster_template,
86 old_model.uuid, patch_model)
87
88 @testtools.testcase.attr('positive')
89 def test_update_cluster_template_by_uuid(self):
90 gen_model = \
91 datagen.cluster_template_data_with_valid_keypair_image_flavor()
92 resp, old_model = self._create_cluster_template(gen_model)
93
94 patch_model = datagen.cluster_template_name_patch_data()
95 resp, new_model = self.ct_member_client.patch_cluster_template(
96 old_model.uuid, patch_model)
97 self.assertEqual(200, resp.status)
98
99 resp, model = \
100 self.ct_reader_client.get_cluster_template(new_model.uuid)
101 self.assertEqual(200, resp.status)
102 self.assertEqual(old_model.uuid, new_model.uuid)
103 self.assertEqual(model.name, new_model.name)
104
105 @testtools.testcase.attr('positive')
106 def test_delete_cluster_template_by_uuid(self):
107 gen_model = \
108 datagen.cluster_template_data_with_valid_keypair_image_flavor()
109 resp, model = self._create_cluster_template(gen_model)
110 resp, _ = self.ct_member_client.delete_cluster_template(
111 model.uuid)
112 self.assertEqual(204, resp.status)
113 self.cluster_templates.remove(model.uuid)
114
115 @testtools.testcase.attr('positive')
116 def test_delete_cluster_template_by_name(self):
117 gen_model = \
118 datagen.cluster_template_data_with_valid_keypair_image_flavor()
119 resp, model = self._create_cluster_template(gen_model)
120 resp, _ = self.ct_member_client.delete_cluster_template(
121 model.name)
122 self.assertEqual(204, resp.status)
123 self.cluster_templates.remove(model.uuid)
124
125 @testtools.testcase.attr('negative')
126 def test_get_cluster_template_by_uuid_404(self):
127 self.assertRaises(
128 exceptions.NotFound,
129 self.ct_reader_client.get_cluster_template,
130 data_utils.rand_uuid())
131
132 @testtools.testcase.attr('negative')
133 def test_update_cluster_template_404(self):
134 patch_model = datagen.cluster_template_name_patch_data()
135
136 self.assertRaises(
137 exceptions.NotFound,
138 self.ct_member_client.patch_cluster_template,
139 data_utils.rand_uuid(), patch_model)
140
141 @testtools.testcase.attr('negative')
142 def test_delete_cluster_template_404(self):
143 self.assertRaises(
144 exceptions.NotFound,
145 self.ct_member_client.delete_cluster_template,
146 data_utils.rand_uuid())
147
148 @testtools.testcase.attr('negative')
149 def test_get_cluster_template_by_name_404(self):
150 self.assertRaises(
151 exceptions.NotFound,
152 self.ct_reader_client.get_cluster_template, 'fooo')
153
154 @testtools.testcase.attr('negative')
155 def test_update_cluster_template_name_not_found(self):
156 patch_model = datagen.cluster_template_name_patch_data()
157
158 self.assertRaises(
159 exceptions.NotFound,
160 self.ct_member_client.patch_cluster_template,
161 'fooo', patch_model)
162
163 @testtools.testcase.attr('negative')
164 def test_delete_cluster_template_by_name_404(self):
165 self.assertRaises(
166 exceptions.NotFound,
167 self.ct_reader_client.get_cluster_template, 'fooo')
168
169 @testtools.testcase.attr('negative')
170 def test_create_cluster_template_missing_image(self):
171 gen_model = datagen.cluster_template_data_with_missing_image()
172 self.assertRaises(
173 exceptions.BadRequest,
174 self.ct_member_client.post_cluster_template, gen_model)
175
176 @testtools.testcase.attr('negative')
177 def test_create_cluster_template_missing_flavor(self):
178 gen_model = datagen.cluster_template_data_with_missing_flavor()
179 self.assertRaises(
180 exceptions.BadRequest,
181 self.ct_member_client.post_cluster_template, gen_model)
182
183 @testtools.testcase.attr('positive')
184 def test_create_cluster_template_missing_keypair(self):
185 gen_model = \
186 datagen.cluster_template_data_with_missing_keypair()
187 resp, model = self._create_cluster_template(gen_model)
188
189 @testtools.testcase.attr('negative')
190 def test_update_cluster_template_invalid_patch(self):
191 # get json object
192 gen_model = \
193 datagen.cluster_template_data_with_valid_keypair_image_flavor()
194 resp, old_model = self._create_cluster_template(gen_model)
195
196 self.assertRaises(
197 exceptions.BadRequest,
198 self.ct_member_client.patch_cluster_template,
199 data_utils.rand_uuid(), gen_model)
200
201 @testtools.testcase.attr('negative')
202 def test_create_cluster_template_invalid_network_driver(self):
203 gen_model = \
204 datagen.cluster_template_data_with_valid_keypair_image_flavor()
205 gen_model.network_driver = 'invalid_network_driver'
206 self.assertRaises(
207 exceptions.BadRequest,
208 self.ct_member_client.post_cluster_template, gen_model)
209
210 @testtools.testcase.attr('negative')
211 def test_create_cluster_template_invalid_volume_driver(self):
212 gen_model = \
213 datagen.cluster_template_data_with_valid_keypair_image_flavor()
214 gen_model.volume_driver = 'invalid_volume_driver'
215 self.assertRaises(
216 exceptions.BadRequest,
217 self.ct_member_client.post_cluster_template, gen_model)