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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. resp, model = self._create_cluster_template(gen_model)
  70. resp, model = \
  71. self.cluster_template_client.get_cluster_template(model.uuid)
  72. self.assertEqual(200, resp.status)
  73. self.assertTrue(model.public)
  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. patch_model = datagen.cluster_template_replace_patch_data(path,
  81. value=True)
  82. resp, new_model = self.cluster_template_client.patch_cluster_template(
  83. old_model.uuid, patch_model)
  84. self.assertEqual(200, resp.status)
  85. resp, model = self.cluster_template_client.get_cluster_template(
  86. new_model.uuid)
  87. self.assertEqual(200, resp.status)
  88. self.assertTrue(model.public)
  89. @testtools.testcase.attr('positive')
  90. def test_update_cluster_template_by_uuid(self):
  91. gen_model = \
  92. datagen.cluster_template_data_with_valid_keypair_image_flavor()
  93. resp, old_model = self._create_cluster_template(gen_model)
  94. patch_model = datagen.cluster_template_name_patch_data()
  95. resp, new_model = self.cluster_template_client.patch_cluster_template(
  96. old_model.uuid, patch_model)
  97. self.assertEqual(200, resp.status)
  98. resp, model = \
  99. self.cluster_template_client.get_cluster_template(new_model.uuid)
  100. self.assertEqual(200, resp.status)
  101. self.assertEqual(old_model.uuid, new_model.uuid)
  102. self.assertEqual(model.name, new_model.name)
  103. @testtools.testcase.attr('positive')
  104. def test_delete_cluster_template_by_uuid(self):
  105. gen_model = \
  106. datagen.cluster_template_data_with_valid_keypair_image_flavor()
  107. resp, model = self._create_cluster_template(gen_model)
  108. resp, _ = self.cluster_template_client.delete_cluster_template(
  109. model.uuid)
  110. self.assertEqual(204, resp.status)
  111. self.cluster_templates.remove(model.uuid)
  112. @testtools.testcase.attr('positive')
  113. def test_delete_cluster_template_by_name(self):
  114. gen_model = \
  115. datagen.cluster_template_data_with_valid_keypair_image_flavor()
  116. resp, model = self._create_cluster_template(gen_model)
  117. resp, _ = self.cluster_template_client.delete_cluster_template(
  118. model.name)
  119. self.assertEqual(204, resp.status)
  120. self.cluster_templates.remove(model.uuid)
  121. @testtools.testcase.attr('negative')
  122. def test_get_cluster_template_by_uuid_404(self):
  123. self.assertRaises(
  124. exceptions.NotFound,
  125. self.cluster_template_client.get_cluster_template,
  126. data_utils.rand_uuid())
  127. @testtools.testcase.attr('negative')
  128. def test_update_cluster_template_404(self):
  129. patch_model = datagen.cluster_template_name_patch_data()
  130. self.assertRaises(
  131. exceptions.NotFound,
  132. self.cluster_template_client.patch_cluster_template,
  133. data_utils.rand_uuid(), patch_model)
  134. @testtools.testcase.attr('negative')
  135. def test_delete_cluster_template_404(self):
  136. self.assertRaises(
  137. exceptions.NotFound,
  138. self.cluster_template_client.delete_cluster_template,
  139. data_utils.rand_uuid())
  140. @testtools.testcase.attr('negative')
  141. def test_get_cluster_template_by_name_404(self):
  142. self.assertRaises(
  143. exceptions.NotFound,
  144. self.cluster_template_client.get_cluster_template, 'fooo')
  145. @testtools.testcase.attr('negative')
  146. def test_update_cluster_template_name_not_found(self):
  147. patch_model = datagen.cluster_template_name_patch_data()
  148. self.assertRaises(
  149. exceptions.NotFound,
  150. self.cluster_template_client.patch_cluster_template,
  151. 'fooo', patch_model)
  152. @testtools.testcase.attr('negative')
  153. def test_delete_cluster_template_by_name_404(self):
  154. self.assertRaises(
  155. exceptions.NotFound,
  156. self.cluster_template_client.get_cluster_template, 'fooo')
  157. @testtools.testcase.attr('negative')
  158. def test_create_cluster_template_missing_image(self):
  159. gen_model = datagen.cluster_template_data_with_missing_image()
  160. self.assertRaises(
  161. exceptions.BadRequest,
  162. self.cluster_template_client.post_cluster_template, gen_model)
  163. @testtools.testcase.attr('negative')
  164. def test_create_cluster_template_missing_flavor(self):
  165. gen_model = datagen.cluster_template_data_with_missing_flavor()
  166. self.assertRaises(
  167. exceptions.BadRequest,
  168. self.cluster_template_client.post_cluster_template, gen_model)
  169. @testtools.testcase.attr('positive')
  170. def test_create_cluster_template_missing_keypair(self):
  171. gen_model = \
  172. datagen.cluster_template_data_with_missing_keypair()
  173. resp, model = self._create_cluster_template(gen_model)
  174. @testtools.testcase.attr('negative')
  175. def test_update_cluster_template_invalid_patch(self):
  176. # get json object
  177. gen_model = \
  178. datagen.cluster_template_data_with_valid_keypair_image_flavor()
  179. resp, old_model = self._create_cluster_template(gen_model)
  180. self.assertRaises(
  181. exceptions.BadRequest,
  182. self.cluster_template_client.patch_cluster_template,
  183. data_utils.rand_uuid(), gen_model)
  184. @testtools.testcase.attr('negative')
  185. def test_create_cluster_template_invalid_network_driver(self):
  186. gen_model = \
  187. datagen.cluster_template_data_with_valid_keypair_image_flavor()
  188. gen_model.network_driver = 'invalid_network_driver'
  189. self.assertRaises(
  190. exceptions.BadRequest,
  191. self.cluster_template_client.post_cluster_template, gen_model)
  192. @testtools.testcase.attr('negative')
  193. def test_create_cluster_template_invalid_volume_driver(self):
  194. gen_model = \
  195. datagen.cluster_template_data_with_valid_keypair_image_flavor()
  196. gen_model.volume_driver = 'invalid_volume_driver'
  197. self.assertRaises(
  198. exceptions.BadRequest,
  199. self.cluster_template_client.post_cluster_template, gen_model)