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')
|
||||
raise exception.InvalidShareSnapshot(reason=msg)
|
||||
if not size:
|
||||
size = snapshot['share_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)
|
||||
size = snapshot['size']
|
||||
|
||||
snapshot_id = snapshot['id']
|
||||
else:
|
||||
@ -111,6 +106,11 @@ class API(base.Base):
|
||||
% size)
|
||||
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
|
||||
# share types so that it becomes easier to add one
|
||||
if share_proto.lower() not in ['nfs', 'cifs']:
|
||||
|
@ -59,6 +59,7 @@ def fake_snapshot(id, **kwargs):
|
||||
snapshot = {
|
||||
'id': id,
|
||||
'share_size': 1,
|
||||
'size': 1,
|
||||
'user_id': 'fakeuser',
|
||||
'project_id': 'fakeproject',
|
||||
'share_id': None,
|
||||
@ -263,6 +264,13 @@ class ShareAPITestCase(test.TestCase):
|
||||
'fakedesc', snapshot=snapshot,
|
||||
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):
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(exception.InvalidInput, self.api.create,
|
||||
|
Loading…
Reference in New Issue
Block a user