Fix creation of share group types using share type names
Before it was possible to create share group types mapping them to
share types using only share type IDs and when we were providing its
names we were getting DB error and HTTP 500 as a response.
Fix it by properly looking for share type by both its unique values -
ID and name. Also, raise proper 404 error when nothing is found.
Add functional tests covering this case.
Change-Id: I216f935383a87f6d679c431bc46cfa8977a6d8ab
Depends-On: Ic555d241f98d0fa027897c69a7115d1be88f6c96
Closes-Bug: #1659625
diff --git a/manila_tempest_tests/tests/api/admin/test_share_group_types.py b/manila_tempest_tests/tests/api/admin/test_share_group_types.py
index a6bda73..532e773 100644
--- a/manila_tempest_tests/tests/api/admin/test_share_group_types.py
+++ b/manila_tempest_tests/tests/api/admin/test_share_group_types.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import ddt
from tempest import config
from tempest.lib.common.utils import data_utils
import testtools
@@ -27,6 +28,7 @@
@testtools.skipUnless(
CONF.share.run_share_group_tests, 'Share Group tests disabled.')
@base.skip_if_microversion_lt(constants.MIN_SHARE_GROUP_MICROVERSION)
+@ddt.ddt
class ShareGroupTypesTest(base.BaseSharesAdminTest):
@classmethod
@@ -44,13 +46,14 @@
cls.share_type2 = share_type['share_type']
@tc.attr(base.TAG_POSITIVE, base.TAG_API)
- def test_create_get_delete_share_group_type_min(self):
+ @ddt.data('id', 'name')
+ def test_create_get_delete_share_group_type_min(self, st_key):
name = data_utils.rand_name("tempest-manila")
# Create share group type
sg_type_c = self.create_share_group_type(
name=name,
- share_types=self.share_type['id'],
+ share_types=self.share_type[st_key],
cleanup_in_class=False,
version=constants.MIN_SHARE_GROUP_MICROVERSION)
@@ -76,12 +79,13 @@
share_group_type_id=sg_type_r['id'])
@tc.attr(base.TAG_POSITIVE, base.TAG_API)
- def test_create_share_group_type_multiple_share_types_min(self):
+ @ddt.data('id', 'name')
+ def test_create_share_group_type_multiple_share_types_min(self, st_key):
name = data_utils.rand_name("tempest-manila")
sg_type = self.create_share_group_type(
name=name,
- share_types=[self.share_type['id'], self.share_type2['id']],
+ share_types=[self.share_type[st_key], self.share_type2[st_key]],
cleanup_in_class=False,
version=constants.MIN_SHARE_GROUP_MICROVERSION)
diff --git a/manila_tempest_tests/tests/api/admin/test_share_group_types_negative.py b/manila_tempest_tests/tests/api/admin/test_share_group_types_negative.py
index e7f6824..18e8cdd 100644
--- a/manila_tempest_tests/tests/api/admin/test_share_group_types_negative.py
+++ b/manila_tempest_tests/tests/api/admin/test_share_group_types_negative.py
@@ -40,10 +40,19 @@
client=cls.admin_shares_v2_client)
@tc.attr(base.TAG_NEGATIVE, base.TAG_API)
- def test_create_share_ggroup_with_nonexistent_share_type(self):
+ def test_create_share_group_type_without_name(self):
self.assertRaises(
lib_exc.BadRequest,
self.admin_shares_v2_client.create_share_group_type,
+ name=None,
+ share_types=data_utils.rand_name("fake"))
+
+ @tc.attr(base.TAG_NEGATIVE, base.TAG_API)
+ def test_create_share_group_type_with_nonexistent_share_type(self):
+ self.assertRaises(
+ lib_exc.NotFound,
+ self.admin_shares_v2_client.create_share_group_type,
+ name=data_utils.rand_name("sgt_name_should_have_not_been_created"),
share_types=data_utils.rand_name("fake"))
@tc.attr(base.TAG_NEGATIVE, base.TAG_API)