updated tests and added more error checking
This commit is contained in:
@@ -623,15 +623,16 @@ class InstanceTypeCommands(object):
|
|||||||
arguments: name memory_mb vcpus local_gb"""
|
arguments: name memory_mb vcpus local_gb"""
|
||||||
try:
|
try:
|
||||||
instance_types.create(name, memory, vcpus, local_gb, flavorid)
|
instance_types.create(name, memory, vcpus, local_gb, flavorid)
|
||||||
except exception.InvalidInputException:
|
except exception.InvalidInputException, e:
|
||||||
print "Must supply valid parameters to create instance type"
|
print "Must supply valid parameters to create instance type"
|
||||||
|
print e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except exception.DBError, e:
|
except exception.DBError, e:
|
||||||
print "DB Error: %s" % e
|
print "DB Error: %s" % e
|
||||||
sys.exit(1)
|
sys.exit(2)
|
||||||
except:
|
except:
|
||||||
print "Unknown error"
|
print "Unknown error"
|
||||||
sys.exit(1)
|
sys.exit(3)
|
||||||
else:
|
else:
|
||||||
print "%s created" % name
|
print "%s created" % name
|
||||||
|
|
||||||
@@ -639,14 +640,10 @@ class InstanceTypeCommands(object):
|
|||||||
"""Marks instance types / flavors as deleted
|
"""Marks instance types / flavors as deleted
|
||||||
arguments: name"""
|
arguments: name"""
|
||||||
try:
|
try:
|
||||||
records = instance_types.destroy(name)
|
instance_types.destroy(name)
|
||||||
except exception.InvalidParameters:
|
except exception.ApiError:
|
||||||
print "Valid instance type name is required"
|
print "Valid instance type name is required"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except exception.NotFound, e:
|
|
||||||
print "Instance type name %s not found. \
|
|
||||||
No instance type deleted." % name
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
else:
|
||||||
print "%s deleted" % name
|
print "%s deleted" % name
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ def create(name, memory, vcpus, local_gb, flavorid):
|
|||||||
flavorid=flavorid))
|
flavorid=flavorid))
|
||||||
except exception.DBError:
|
except exception.DBError:
|
||||||
raise exception.ApiError(_("Cannot create instance type: %s"),
|
raise exception.ApiError(_("Cannot create instance type: %s"),
|
||||||
instance_type, "Invalid")
|
name)
|
||||||
|
|
||||||
|
|
||||||
def destroy(name):
|
def destroy(name):
|
||||||
@@ -59,9 +59,9 @@ def destroy(name):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
db.instance_type_destroy(context.get_admin_context(), name)
|
db.instance_type_destroy(context.get_admin_context(), name)
|
||||||
except exception.DBError:
|
except exception.NotFound:
|
||||||
raise exception.ApiError(_("Unknown instance type: %s"),
|
raise exception.ApiError(_("Unknown instance type: %s"),
|
||||||
instance_type, "Invalid")
|
name)
|
||||||
|
|
||||||
|
|
||||||
def get_all_types(inactive=0):
|
def get_all_types(inactive=0):
|
||||||
@@ -86,7 +86,7 @@ def get_instance_type(name):
|
|||||||
return inst_type
|
return inst_type
|
||||||
except exception.DBError:
|
except exception.DBError:
|
||||||
raise exception.ApiError(_("Unknown instance type: %s"),
|
raise exception.ApiError(_("Unknown instance type: %s"),
|
||||||
instance_type, "Invalid")
|
name)
|
||||||
|
|
||||||
|
|
||||||
def get_by_type(instance_type):
|
def get_by_type(instance_type):
|
||||||
@@ -99,7 +99,7 @@ def get_by_type(instance_type):
|
|||||||
return inst_type['name']
|
return inst_type['name']
|
||||||
except exception.DBError:
|
except exception.DBError:
|
||||||
raise exception.ApiError(_("Unknown instance type: %s"),
|
raise exception.ApiError(_("Unknown instance type: %s"),
|
||||||
instance_type, "Invalid")
|
instance_type)
|
||||||
|
|
||||||
|
|
||||||
def get_by_flavor_id(flavor_id):
|
def get_by_flavor_id(flavor_id):
|
||||||
@@ -112,4 +112,4 @@ def get_by_flavor_id(flavor_id):
|
|||||||
return flavor['name']
|
return flavor['name']
|
||||||
except exception.DBError:
|
except exception.DBError:
|
||||||
raise exception.ApiError(_("Unknown flavor: %s"),
|
raise exception.ApiError(_("Unknown flavor: %s"),
|
||||||
flavor_id, "Invalid")
|
flavor_id)
|
||||||
|
|||||||
@@ -2086,10 +2086,10 @@ def instance_type_get_by_flavor_id(context, id):
|
|||||||
def instance_type_destroy(context, name):
|
def instance_type_destroy(context, name):
|
||||||
""" Marks specific instance_type as deleted"""
|
""" Marks specific instance_type as deleted"""
|
||||||
session = get_session()
|
session = get_session()
|
||||||
try:
|
instance_type_ref = session.query(models.InstanceTypes).\
|
||||||
instance_type_ref = session.query(models.InstanceTypes).\
|
filter_by(name=name)
|
||||||
filter_by(name=name)
|
records = instance_type_ref.update(dict(deleted=1))
|
||||||
instance_type_ref.update(dict(deleted=1))
|
if records == 0:
|
||||||
except:
|
raise exception.NotFound
|
||||||
raise exception.DBError
|
else:
|
||||||
return instance_type_ref
|
return instance_type_ref
|
||||||
|
|||||||
@@ -62,3 +62,20 @@ class InstanceTypeTestCase(test.TestCase):
|
|||||||
count()
|
count()
|
||||||
inst_types = instance_types.get_all_types()
|
inst_types = instance_types.get_all_types()
|
||||||
self.assertEqual(total_instance_types, len(inst_types))
|
self.assertEqual(total_instance_types, len(inst_types))
|
||||||
|
|
||||||
|
def test_invalid_create_args_should_fail(self):
|
||||||
|
"""Ensures that instance type creation fails with invalid args"""
|
||||||
|
self.assertRaises(
|
||||||
|
exception.InvalidInputException,
|
||||||
|
instance_types.create, self.name, 0, 1, 120, self.flavorid)
|
||||||
|
self.assertRaises(
|
||||||
|
exception.InvalidInputException,
|
||||||
|
instance_types.create, self.name, 256, -1, 120, self.flavorid)
|
||||||
|
self.assertRaises(
|
||||||
|
exception.InvalidInputException,
|
||||||
|
instance_types.create, self.name, 256, 1, "aa", self.flavorid)
|
||||||
|
|
||||||
|
def test_non_existant_inst_type_shouldnt_delete(self):
|
||||||
|
"""Ensures that instance type creation fails with invalid args"""
|
||||||
|
self.assertRaises(exception.ApiError,
|
||||||
|
instance_types.destroy, "sfsfsdfdfs")
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ class NovaManageTestCase(test.TestCase):
|
|||||||
max_flavorid = session.query(models.InstanceTypes).\
|
max_flavorid = session.query(models.InstanceTypes).\
|
||||||
order_by("flavorid desc").first()
|
order_by("flavorid desc").first()
|
||||||
self.flavorid = str(max_flavorid["flavorid"] + 1)
|
self.flavorid = str(max_flavorid["flavorid"] + 1)
|
||||||
# self.flavorid = str(self.flavorid)
|
|
||||||
self.name = str(int(time.time()))
|
self.name = str(int(time.time()))
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
@@ -42,7 +41,7 @@ class NovaManageTestCase(test.TestCase):
|
|||||||
fnull = open(os.devnull, 'w')
|
fnull = open(os.devnull, 'w')
|
||||||
retcode = subprocess.call(["bin/nova-manage", "instance_type",
|
retcode = subprocess.call(["bin/nova-manage", "instance_type",
|
||||||
"create", self.name, "256", "1",
|
"create", self.name, "256", "1",
|
||||||
"120", self.flavorid], stdout=fnull)
|
"10", self.flavorid], stdout=fnull)
|
||||||
self.assertEqual(0, retcode)
|
self.assertEqual(0, retcode)
|
||||||
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
||||||
"delete", self.name], stdout=fnull)
|
"delete", self.name], stdout=fnull)
|
||||||
@@ -67,16 +66,14 @@ class NovaManageTestCase(test.TestCase):
|
|||||||
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
||||||
"create", self.name, "256", "0",\
|
"create", self.name, "256", "0",\
|
||||||
"120", self.flavorid], stdout=fnull)
|
"120", self.flavorid], stdout=fnull)
|
||||||
# self.assertEqual(1, retcode,
|
self.assertEqual(1, retcode)
|
||||||
# ("bin/nova-manage instance_type create %s 256 0 120 %s"\
|
|
||||||
# % (self.name, self.flavorid)))
|
|
||||||
|
|
||||||
def test_should_fail_on_duplicate_flavorid(self):
|
def test_should_fail_on_duplicate_flavorid(self):
|
||||||
fnull = open(os.devnull, 'w')
|
fnull = open(os.devnull, 'w')
|
||||||
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
||||||
"create", self.name, "256", "1",\
|
"create", self.name, "256", "1",\
|
||||||
"120", "1"], stdout=fnull)
|
"120", "1"], stdout=fnull)
|
||||||
self.assertEqual(1, retcode)
|
self.assertEqual(3, retcode)
|
||||||
|
|
||||||
def test_should_fail_on_duplicate_name(self):
|
def test_should_fail_on_duplicate_name(self):
|
||||||
fnull = open(os.devnull, 'w')
|
fnull = open(os.devnull, 'w')
|
||||||
@@ -87,10 +84,10 @@ class NovaManageTestCase(test.TestCase):
|
|||||||
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
||||||
"create", "fsfsfsdfsdf", "256", "1",\
|
"create", "fsfsfsdfsdf", "256", "1",\
|
||||||
"120", self.flavorid], stdout=fnull)
|
"120", self.flavorid], stdout=fnull)
|
||||||
self.assertEqual(1, retcode)
|
self.assertEqual(3, retcode)
|
||||||
|
|
||||||
# def test_instance_type_delete_should_fail_without_valid_name(self):
|
def test_instance_type_delete_should_fail_without_valid_name(self):
|
||||||
# fnull = open(os.devnull, 'w')
|
fnull = open(os.devnull, 'w')
|
||||||
# retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
|
||||||
# "delete", "saefasff"], stdout=fnull)
|
"delete", "doesntexist"], stdout=fnull)
|
||||||
# self.assertEqual(1, retcode)
|
self.assertEqual(1, retcode)
|
||||||
|
|||||||
Reference in New Issue
Block a user