Exception handling for 'nova flavor-create' arguments

Fixes client side Bug #1056935

Throws an exception if the user does not input integers for the
corresponding parameters.

Change-Id: I4c4b8148f6565bc5a3b348dbde8c2cf0da00234a
This commit is contained in:
Sathish Nagappan 2012-10-17 21:31:34 -07:00
parent e8c22cd130
commit 805ba8fdc1
2 changed files with 58 additions and 0 deletions

View File

@ -118,6 +118,41 @@ class FlavorManager(base.ManagerWithFind):
:rtype: :class:`Flavor`
"""
try:
ram = int(ram)
except:
raise exceptions.CommandError("Ram must be an integer.")
try:
vcpus = int(vcpus)
except:
raise exceptions.CommandError("VCPUs must be an integer.")
try:
disk = int(disk)
except:
raise exceptions.CommandError("Disk must be an integer.")
try:
flavorid = int(flavorid)
except:
raise exceptions.CommandError("Flavor ID must be an integer.")
try:
swap = int(swap)
except:
raise exceptions.CommandError("Swap must be an integer.")
try:
ephemerel = int(ephemeral)
except:
raise exceptions.CommandError("Ephemerel must be an integer.")
try:
rxtx_factor = int(rxtx_factor)
except:
raise exceptions.CommandError("rxtx_factor must be an integer.")
body = {
"flavor": {
"name": name,

View File

@ -88,6 +88,29 @@ class FlavorsTest(utils.TestCase):
cs.assert_called('POST', '/flavors', body)
self.assertTrue(isinstance(f, flavors.Flavor))
def test_invalid_parameters_create(self):
self.assertRaises(exceptions.CommandError, cs.flavors.create,
"flavorcreate", "invalid", 1, 10, 1234, swap=0,
ephemeral=0, rxtx_factor=1, is_public=True)
self.assertRaises(exceptions.CommandError, cs.flavors.create,
"flavorcreate", 512, "invalid", 10, 1234, swap=0,
ephemeral=0, rxtx_factor=1, is_public=True)
self.assertRaises(exceptions.CommandError, cs.flavors.create,
"flavorcreate", 512, 1, "invalid", 1234, swap=0,
ephemeral=0, rxtx_factor=1, is_public=True)
self.assertRaises(exceptions.CommandError, cs.flavors.create,
"flavorcreate", 512, 1, 10, "invalid", swap=0,
ephemeral=0, rxtx_factor=1, is_public=True)
self.assertRaises(exceptions.CommandError, cs.flavors.create,
"flavorcreate", 512, 1, 10, 1234, swap="invalid",
ephemeral=0, rxtx_factor=1, is_public=True)
self.assertRaises(exceptions.CommandError, cs.flavors.create,
"flavorcreate", 512, 1, 10, 1234, swap=0,
ephemeral="invalid", rxtx_factor=1, is_public=True)
self.assertRaises(exceptions.CommandError, cs.flavors.create,
"flavorcreate", 512, 1, 10, 1234, swap=0,
ephemeral=0, rxtx_factor="invalid", is_public=True)
def test_delete(self):
cs.flavors.delete("flavordelete")
cs.assert_called('DELETE', '/flavors/flavordelete')