| 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 |
import testtools |
| 15 |
|
| 16 |
from magnum_tempest_plugin.common import datagen |
| 17 |
from magnum_tempest_plugin.tests.api import base |
| 18 |
|
| 19 |
|
| 20 |
class ClusterTemplateAdminTestTemplate(base.BaseTempestTest): |
| 21 |
|
| 22 |
"""Template for Tests for clustertemplate admin operations.""" |
| 23 |
|
| 24 |
def __init__(self, *args, **kwargs): |
| 25 |
super().__init__(*args, **kwargs) |
| 26 |
self.cluster_templates = [] |
| 27 |
|
| 28 |
def tearDown(self): |
| 29 |
for cluster_template_id in self.cluster_templates: |
| 30 |
self._delete_cluster_template(cluster_template_id) |
| 31 |
self.cluster_templates.remove(cluster_template_id) |
| 32 |
super().tearDown() |
| 33 |
|
| 34 |
def _create_cluster_template(self, cmodel_model): |
| 35 |
resp, model = \ |
| 36 |
self.ct_admin_client.post_cluster_template(cmodel_model) |
| 37 |
self.assertEqual(201, resp.status) |
| 38 |
self.cluster_templates.append(model.uuid) |
| 39 |
return resp, model |
| 40 |
|
| 41 |
def _delete_cluster_template(self, model_id): |
| 42 |
resp, model = \ |
| 43 |
self.ct_admin_client.delete_cluster_template(model_id) |
| 44 |
self.assertEqual(204, resp.status) |
| 45 |
return resp, model |
| 46 |
|
| 47 |
@testtools.testcase.attr('positive') |
| 48 |
def test_create_get_public_cluster_template(self): |
| 49 |
gen_model = datagen.valid_cluster_template(is_public=True) |
| 50 |
resp, model = self._create_cluster_template(gen_model) |
| 51 |
|
| 52 |
resp, model = \ |
| 53 |
self.ct_admin_client.get_cluster_template(model.uuid) |
| 54 |
self.assertEqual(200, resp.status) |
| 55 |
self.assertTrue(model.public) |
| 56 |
|
| 57 |
@testtools.testcase.attr('positive') |
| 58 |
def test_update_cluster_template_public_by_uuid(self): |
| 59 |
path = "/public" |
| 60 |
gen_model = \ |
| 61 |
datagen.cluster_template_data_with_valid_keypair_image_flavor() |
| 62 |
resp, old_model = self._create_cluster_template(gen_model) |
| 63 |
|
| 64 |
patch_model = datagen.cluster_template_replace_patch_data(path, |
| 65 |
value=True) |
| 66 |
resp, new_model = self.ct_admin_client.patch_cluster_template( |
| 67 |
old_model.uuid, patch_model) |
| 68 |
self.assertEqual(200, resp.status) |
| 69 |
|
| 70 |
resp, model = self.ct_admin_client.get_cluster_template( |
| 71 |
new_model.uuid) |
| 72 |
self.assertEqual(200, resp.status) |
| 73 |
self.assertTrue(model.public) |