From 8ee10c55b045ab6d85b41dddbbb95384d009fb9b Mon Sep 17 00:00:00 2001 From: jiataotj Date: Tue, 28 May 2013 18:20:15 +0800 Subject: Add invalid number checking in flavor creation api Flavor creation api doesn't check whether 'memory_mb' argument number is integer,add invalid number checking into the flavor creation function to remind the user to input right value Fixes bug #1171278 Change-Id: I8308f66c485d8c872864661148e9eac7b685e406 --- .../api/openstack/compute/contrib/test_flavor_manage.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py index df2c3d392..459dae932 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py @@ -218,3 +218,18 @@ class FlavorManageTest(test.TestCase): req.body = jsonutils.dumps(expected) res = req.get_response(self.app) self.assertEqual(res.status_int, 409) + + def test_invalid_memory_mb(self): + """Check negative and decimal number can't be accepted.""" + + self.stubs.UnsetAll() + self.assertRaises(exception.InvalidInput, flavors.create, "abc", + -512, 2, 1, 1, 1234, 512, 1, True) + self.assertRaises(exception.InvalidInput, flavors.create, "abcd", + 512.2, 2, 1, 1, 1234, 512, 1, True) + self.assertRaises(exception.InvalidInput, flavors.create, "abcde", + None, 2, 1, 1, 1234, 512, 1, True) + self.assertRaises(exception.InvalidInput, flavors.create, "abcdef", + 512, 2, None, 1, 1234, 512, 1, True) + self.assertRaises(exception.InvalidInput, flavors.create, "abcdef", + "test_memory_mb", 2, None, 1, 1234, 512, 1, True) -- cgit