Container Infrastructure Management Service for OpenStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_cluster_template_admin.py 3.3KB

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