From a2b6193e0bda4a11553d219a44f4734b9ee9ffa3 Mon Sep 17 00:00:00 2001 From: Yulia Portnova Date: Wed, 2 Oct 2013 11:14:39 +0300 Subject: [PATCH] Fixed share size validation while creating from snapshot. Fixes bug 1233755 Change-Id: Ie8689ccc5c3094d8a5303e3cafe842c0f3b964f3 --- manila/share/api.py | 12 ++++++------ manila/tests/test_share_api.py | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/manila/share/api.py b/manila/share/api.py index 701137d187..3aedd921fa 100644 --- a/manila/share/api.py +++ b/manila/share/api.py @@ -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']: diff --git a/manila/tests/test_share_api.py b/manila/tests/test_share_api.py index b77f6c2553..4cd5bd1632 100644 --- a/manila/tests/test_share_api.py +++ b/manila/tests/test_share_api.py @@ -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,