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.py 9.1KB

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