Merge "Check share-network in 'share create' API"
This commit is contained in:
commit
77a4e7258a
@ -356,14 +356,14 @@ class ShareMixin(object):
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
req_share_type = share.get('share_type', share.get('volume_type'))
|
||||
|
||||
share_type = None
|
||||
if req_share_type:
|
||||
try:
|
||||
if not uuidutils.is_uuid_like(req_share_type):
|
||||
kwargs['share_type'] = \
|
||||
share_types.get_share_type_by_name(
|
||||
context, req_share_type)
|
||||
share_type = share_types.get_share_type_by_name(
|
||||
context, req_share_type)
|
||||
else:
|
||||
kwargs['share_type'] = share_types.get_share_type(
|
||||
share_type = share_types.get_share_type(
|
||||
context, req_share_type)
|
||||
except exception.ShareTypeNotFound:
|
||||
msg = _("Share type not found.")
|
||||
@ -371,8 +371,22 @@ class ShareMixin(object):
|
||||
elif not snapshot:
|
||||
def_share_type = share_types.get_default_share_type()
|
||||
if def_share_type:
|
||||
kwargs['share_type'] = def_share_type
|
||||
share_type = def_share_type
|
||||
|
||||
# Only use in create share feature. Create share from snapshot
|
||||
# and create share with consistency group features not
|
||||
# need this check.
|
||||
if (not share_network_id and not snapshot
|
||||
and not share.get('consistency_group_id')
|
||||
and share_type and share_type.get('extra_specs')
|
||||
and (strutils.bool_from_string(share_type.get('extra_specs').
|
||||
get('driver_handles_share_servers')))):
|
||||
msg = _('Share network must be set when the '
|
||||
'driver_handles_share_servers is true.')
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
if share_type:
|
||||
kwargs['share_type'] = share_type
|
||||
new_share = self.share_api.create(context,
|
||||
share_proto,
|
||||
size,
|
||||
|
@ -192,6 +192,24 @@ class ShareAPITest(test.TestCase):
|
||||
self.controller.create, req, {'share': self.share})
|
||||
share_types.get_default_share_type.assert_called_once_with()
|
||||
|
||||
def test_share_create_with_dhss_true_and_network_notexist(self):
|
||||
fake_share_type = {
|
||||
'id': 'fake_volume_type_id',
|
||||
'name': 'fake_volume_type_name',
|
||||
'extra_specs': {
|
||||
'driver_handles_share_servers': True,
|
||||
}
|
||||
}
|
||||
self.mock_object(
|
||||
share_types, 'get_default_share_type',
|
||||
mock.Mock(return_value=fake_share_type),
|
||||
)
|
||||
CONF.set_default("default_share_type", fake_share_type['name'])
|
||||
req = fakes.HTTPRequest.blank('/shares')
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.create, req, {'share': self.share})
|
||||
share_types.get_default_share_type.assert_called_once_with()
|
||||
|
||||
def test_share_create_with_share_net(self):
|
||||
shr = {
|
||||
"size": 100,
|
||||
|
@ -102,7 +102,7 @@ class SharesAdminQuotasNegativeTest(base.BaseSharesAdminTest):
|
||||
|
||||
# try schedule share with size, bigger than gigabytes quota
|
||||
self.assertRaises(lib_exc.OverLimit,
|
||||
self.shares_client.create_share,
|
||||
self.create_share,
|
||||
size=overquota)
|
||||
|
||||
@test.attr(type=["gate", "smoke", "negative"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user