From c87bcc8eae7f3b8681e9e9590546a20c46637eb5 Mon Sep 17 00:00:00 2001 From: Joshua McKenty Date: Thu, 24 Jun 2010 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 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/nova/tests/storage_unittest.py b/nova/tests/storage_unittest.py index 84f3126c..4f2a60b2 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 e96a4705..adf2d147 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