Skip to content

Commit a2b6193

Browse files
committed
Fixed share size validation while creating from snapshot.
Fixes bug 1233755 Change-Id: Ie8689ccc5c3094d8a5303e3cafe842c0f3b964f3
1 parent cd6b68f commit a2b6193

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

manila/share/api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ def create(self, context, share_proto, size, name, description,
8686
msg = _('status must be available')
8787
raise exception.InvalidShareSnapshot(reason=msg)
8888
if not size:
89-
size = snapshot['share_size']
90-
else:
91-
if size < snapshot['share_size']:
92-
msg = (_("Share size '%s' must be equal or greater "
93-
"than snapshot size") % size)
94-
raise exception.InvalidInput(reason=msg)
89+
size = snapshot['size']
9590

9691
snapshot_id = snapshot['id']
9792
else:
@@ -111,6 +106,11 @@ def as_int(s):
111106
% size)
112107
raise exception.InvalidInput(reason=msg)
113108

109+
if snapshot and size < snapshot['size']:
110+
msg = (_("Share size '%s' must be equal or greater "
111+
"than snapshot size") % size)
112+
raise exception.InvalidInput(reason=msg)
113+
114114
#TODO(rushiagr): Find a suitable place to keep all the allowed
115115
# share types so that it becomes easier to add one
116116
if share_proto.lower() not in ['nfs', 'cifs']:

manila/tests/test_share_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def fake_snapshot(id, **kwargs):
5959
snapshot = {
6060
'id': id,
6161
'share_size': 1,
62+
'size': 1,
6263
'user_id': 'fakeuser',
6364
'project_id': 'fakeproject',
6465
'share_id': None,
@@ -263,6 +264,13 @@ def test_create_from_snapshot_not_available(self):
263264
'fakedesc', snapshot=snapshot,
264265
availability_zone='fakeaz')
265266

267+
def test_create_from_snapshot_larger_size(self):
268+
snapshot = fake_snapshot(1, size=100, status='available')
269+
self.mox.ReplayAll()
270+
self.assertRaises(exception.InvalidInput, self.api.create,
271+
self.context, 'nfs', 1, 'fakename', 'fakedesc',
272+
availability_zone='fakeaz', snapshot=snapshot)
273+
266274
def test_create_wrong_size_0(self):
267275
self.mox.ReplayAll()
268276
self.assertRaises(exception.InvalidInput, self.api.create,

0 commit comments

Comments
 (0)