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_baymodel.py 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 BayModelTest(base.BaseTempestTest):
  18. """Tests for baymodel CRUD."""
  19. def __init__(self, *args, **kwargs):
  20. super(BayModelTest, self).__init__(*args, **kwargs)
  21. self.baymodels = []
  22. self.baymodel_client = None
  23. self.keypairs_client = None
  24. def setUp(self):
  25. try:
  26. super(BayModelTest, self).setUp()
  27. (self.baymodel_client,
  28. self.keypairs_client) = self.get_clients_with_new_creds(
  29. type_of_creds='default',
  30. request_type='baymodel')
  31. except Exception:
  32. self.tearDown()
  33. raise
  34. def tearDown(self):
  35. for baymodel_id in self.baymodels:
  36. self._delete_baymodel(baymodel_id)
  37. self.baymodels.remove(baymodel_id)
  38. super(BayModelTest, self).tearDown()
  39. def _create_baymodel(self, baymodel_model):
  40. resp, model = self.baymodel_client.post_baymodel(baymodel_model)
  41. self.assertEqual(201, resp.status)
  42. self.baymodels.append(model.uuid)
  43. return resp, model
  44. def _delete_baymodel(self, baymodel_id):
  45. resp, model = self.baymodel_client.delete_baymodel(baymodel_id)
  46. self.assertEqual(204, resp.status)
  47. return resp, model
  48. @testtools.testcase.attr('positive')
  49. def test_list_baymodels(self):
  50. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  51. _, temp_model = self._create_baymodel(gen_model)
  52. resp, model = self.baymodel_client.list_baymodels()
  53. self.assertEqual(200, resp.status)
  54. self.assertGreater(len(model.baymodels), 0)
  55. self.assertIn(
  56. temp_model.uuid, list([x['uuid'] for x in model.baymodels]))
  57. @testtools.testcase.attr('positive')
  58. def test_create_baymodel(self):
  59. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  60. resp, model = self._create_baymodel(gen_model)
  61. @testtools.testcase.attr('positive')
  62. def test_create_get_public_baymodel(self):
  63. gen_model = datagen.valid_swarm_baymodel(is_public=True)
  64. resp, model = self._create_baymodel(gen_model)
  65. resp, model = self.baymodel_client.get_baymodel(model.uuid)
  66. self.assertEqual(200, resp.status)
  67. self.assertTrue(model.public)
  68. @testtools.testcase.attr('positive')
  69. def test_update_baymodel_public_by_uuid(self):
  70. path = "/public"
  71. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  72. resp, old_model = self._create_baymodel(gen_model)
  73. patch_model = datagen.baymodel_replace_patch_data(path, value=True)
  74. resp, new_model = self.baymodel_client.patch_baymodel(
  75. old_model.uuid, patch_model)
  76. self.assertEqual(200, resp.status)
  77. resp, model = self.baymodel_client.get_baymodel(new_model.uuid)
  78. self.assertEqual(200, resp.status)
  79. self.assertTrue(model.public)
  80. @testtools.testcase.attr('positive')
  81. def test_update_baymodel_by_uuid(self):
  82. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  83. resp, old_model = self._create_baymodel(gen_model)
  84. path = "/name"
  85. patch_model = datagen.baymodel_replace_patch_data(path)
  86. resp, new_model = self.baymodel_client.patch_baymodel(
  87. old_model.uuid, patch_model)
  88. self.assertEqual(200, resp.status)
  89. resp, model = self.baymodel_client.get_baymodel(new_model.uuid)
  90. self.assertEqual(200, resp.status)
  91. self.assertEqual(old_model.uuid, new_model.uuid)
  92. self.assertEqual(model.name, new_model.name)
  93. @testtools.testcase.attr('positive')
  94. def test_delete_baymodel_by_uuid(self):
  95. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  96. resp, model = self._create_baymodel(gen_model)
  97. resp, _ = self.baymodel_client.delete_baymodel(model.uuid)
  98. self.assertEqual(204, resp.status)
  99. self.baymodels.remove(model.uuid)
  100. @testtools.testcase.attr('positive')
  101. def test_delete_baymodel_by_name(self):
  102. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  103. resp, model = self._create_baymodel(gen_model)
  104. resp, _ = self.baymodel_client.delete_baymodel(model.name)
  105. self.assertEqual(204, resp.status)
  106. self.baymodels.remove(model.uuid)
  107. @testtools.testcase.attr('negative')
  108. def test_get_baymodel_by_uuid_404(self):
  109. self.assertRaises(
  110. exceptions.NotFound,
  111. self.baymodel_client.get_baymodel, data_utils.rand_uuid())
  112. @testtools.testcase.attr('negative')
  113. def test_update_baymodel_404(self):
  114. path = "/name"
  115. patch_model = datagen.baymodel_replace_patch_data(path)
  116. self.assertRaises(
  117. exceptions.NotFound,
  118. self.baymodel_client.patch_baymodel,
  119. data_utils.rand_uuid(), patch_model)
  120. @testtools.testcase.attr('negative')
  121. def test_delete_baymodel_404(self):
  122. self.assertRaises(
  123. exceptions.NotFound,
  124. self.baymodel_client.delete_baymodel, data_utils.rand_uuid())
  125. @testtools.testcase.attr('negative')
  126. def test_get_baymodel_by_name_404(self):
  127. self.assertRaises(
  128. exceptions.NotFound,
  129. self.baymodel_client.get_baymodel, 'fooo')
  130. @testtools.testcase.attr('negative')
  131. def test_update_baymodel_name_not_found(self):
  132. path = "/name"
  133. patch_model = datagen.baymodel_replace_patch_data(path)
  134. self.assertRaises(
  135. exceptions.NotFound,
  136. self.baymodel_client.patch_baymodel, 'fooo', patch_model)
  137. @testtools.testcase.attr('negative')
  138. def test_delete_baymodel_by_name_404(self):
  139. self.assertRaises(
  140. exceptions.NotFound,
  141. self.baymodel_client.get_baymodel, 'fooo')
  142. @testtools.testcase.attr('negative')
  143. def test_create_baymodel_missing_image(self):
  144. gen_model = datagen.baymodel_data_with_missing_image()
  145. self.assertRaises(
  146. exceptions.BadRequest,
  147. self.baymodel_client.post_baymodel, gen_model)
  148. @testtools.testcase.attr('negative')
  149. def test_create_baymodel_missing_flavor(self):
  150. gen_model = datagen.baymodel_data_with_missing_flavor()
  151. self.assertRaises(
  152. exceptions.BadRequest,
  153. self.baymodel_client.post_baymodel, gen_model)
  154. @testtools.testcase.attr('negative')
  155. def test_update_baymodel_invalid_patch(self):
  156. # get json object
  157. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  158. resp, old_model = self._create_baymodel(gen_model)
  159. self.assertRaises(
  160. exceptions.BadRequest,
  161. self.baymodel_client.patch_baymodel, data_utils.rand_uuid(),
  162. gen_model)
  163. @testtools.testcase.attr('negative')
  164. def test_create_baymodel_invalid_network_driver(self):
  165. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  166. gen_model.network_driver = 'invalid_network_driver'
  167. self.assertRaises(
  168. exceptions.BadRequest,
  169. self.baymodel_client.post_baymodel, gen_model)
  170. @testtools.testcase.attr('negative')
  171. def test_create_baymodel_invalid_volume_driver(self):
  172. gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
  173. gen_model.volume_driver = 'invalid_volume_driver'
  174. self.assertRaises(
  175. exceptions.BadRequest,
  176. self.baymodel_client.post_baymodel, gen_model)