Fixed share size validation while creating from snapshot.
Fixes bug 1233755 Change-Id: Ie8689ccc5c3094d8a5303e3cafe842c0f3b964f3
This commit is contained in:
parent
cd6b68fa7e
commit
a2b6193e0b
@ -86,12 +86,7 @@ class API(base.Base):
|
|||||||
msg = _('status must be available')
|
msg = _('status must be available')
|
||||||
raise exception.InvalidShareSnapshot(reason=msg)
|
raise exception.InvalidShareSnapshot(reason=msg)
|
||||||
if not size:
|
if not size:
|
||||||
size = snapshot['share_size']
|
size = snapshot['size']
|
||||||
else:
|
|
||||||
if size < snapshot['share_size']:
|
|
||||||
msg = (_("Share size '%s' must be equal or greater "
|
|
||||||
"than snapshot size") % size)
|
|
||||||
raise exception.InvalidInput(reason=msg)
|
|
||||||
|
|
||||||
snapshot_id = snapshot['id']
|
snapshot_id = snapshot['id']
|
||||||
else:
|
else:
|
||||||
@ -111,6 +106,11 @@ class API(base.Base):
|
|||||||
% size)
|
% size)
|
||||||
raise exception.InvalidInput(reason=msg)
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
|
if snapshot and size < snapshot['size']:
|
||||||
|
msg = (_("Share size '%s' must be equal or greater "
|
||||||
|
"than snapshot size") % size)
|
||||||
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
#TODO(rushiagr): Find a suitable place to keep all the allowed
|
#TODO(rushiagr): Find a suitable place to keep all the allowed
|
||||||
# share types so that it becomes easier to add one
|
# share types so that it becomes easier to add one
|
||||||
if share_proto.lower() not in ['nfs', 'cifs']:
|
if share_proto.lower() not in ['nfs', 'cifs']:
|
||||||
|
@ -59,6 +59,7 @@ def fake_snapshot(id, **kwargs):
|
|||||||
snapshot = {
|
snapshot = {
|
||||||
'id': id,
|
'id': id,
|
||||||
'share_size': 1,
|
'share_size': 1,
|
||||||
|
'size': 1,
|
||||||
'user_id': 'fakeuser',
|
'user_id': 'fakeuser',
|
||||||
'project_id': 'fakeproject',
|
'project_id': 'fakeproject',
|
||||||
'share_id': None,
|
'share_id': None,
|
||||||
@ -263,6 +264,13 @@ class ShareAPITestCase(test.TestCase):
|
|||||||
'fakedesc', snapshot=snapshot,
|
'fakedesc', snapshot=snapshot,
|
||||||
availability_zone='fakeaz')
|
availability_zone='fakeaz')
|
||||||
|
|
||||||
|
def test_create_from_snapshot_larger_size(self):
|
||||||
|
snapshot = fake_snapshot(1, size=100, status='available')
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
self.assertRaises(exception.InvalidInput, self.api.create,
|
||||||
|
self.context, 'nfs', 1, 'fakename', 'fakedesc',
|
||||||
|
availability_zone='fakeaz', snapshot=snapshot)
|
||||||
|
|
||||||
def test_create_wrong_size_0(self):
|
def test_create_wrong_size_0(self):
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
self.assertRaises(exception.InvalidInput, self.api.create,
|
self.assertRaises(exception.InvalidInput, self.api.create,
|
||||||
|
Loading…
Reference in New Issue
Block a user