From 0912a1c2d55e031287ca5dd5c8df0597667ad12d Mon Sep 17 00:00:00 2001 From: Joshua McKenty Date: 2010年6月24日 04:11:56 +0100 Subject: [PATCH] Adding basic validation of volume size on creation, plus tests for it. --- nova/tests/storage_unittest.py | 7 +++++++ nova/validate.py | 8 ++++---- nova/volume/storage.py | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/nova/tests/storage_unittest.py b/nova/tests/storage_unittest.py index 84f3126c04a3..4f2a60b25020 100644 --- a/nova/tests/storage_unittest.py +++ b/nova/tests/storage_unittest.py @@ -59,6 +59,13 @@ class StorageTestCase(test.TrialTestCase): self.assertRaises(exception.Error, storage.get_volume, volume_id) + + def test_too_big_volume(self): + vol_size = '1001' + user_id = 'fake' + self.assertRaises(TypeError, + self.mystorage.create_volume, + vol_size, user_id) def test_run_attach_detach_volume(self): # Create one volume and one node to test with diff --git a/nova/validate.py b/nova/validate.py index e96a4705957b..adf2d147c181 100644 --- a/nova/validate.py +++ b/nova/validate.py @@ -35,7 +35,7 @@ def rangetest(**argchecks): # validate ranges for both+defaults # for all args to be checked if argname in kargs: # was passed by name - if kargs[argname] < low or kargs[argname]> high: + if float(kargs[argname]) < low or float(kargs[argname])> high: errmsg = '{0} argument "{1}" not in {2}..{3}' errmsg = errmsg.format(funcname, argname, low, high) raise TypeError(errmsg) @@ -43,9 +43,9 @@ def rangetest(**argchecks): # validate ranges for both+defaults elif argname in positionals: # was passed by position position = positionals.index(argname) - if pargs[position] < low or pargs[position]> high: - errmsg = '{0} argument "{1}" not in {2}..{3}' - errmsg = errmsg.format(funcname, argname, low, high) + if float(pargs[position]) < low or float(pargs[position])> high: + errmsg = '{0} argument "{1}" with value of {4} not in {2}..{3}' + errmsg = errmsg.format(funcname, argname, low, high, pargs[position]) raise TypeError(errmsg) else: pass diff --git a/nova/volume/storage.py b/nova/volume/storage.py index 993e01bb749d..5ebd8b9417ad 100644 --- a/nova/volume/storage.py +++ b/nova/volume/storage.py @@ -35,6 +35,7 @@ from nova import exception from nova import flags from nova import rpc from nova import utils +from nova import validate FLAGS = flags.FLAGS @@ -84,6 +85,7 @@ class BlockStore(object): #TODO: aggregate the state of the system pass + @validate.rangetest(size=(0, 100)) def create_volume(self, size, user_id): """ Creates an exported volume (fake or real),

AltStyle によって変換されたページ (->オリジナル) /