summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorKen Pepple <ken.pepple@gmail.com>2011-02-11 13:53:54 -0800
committerKen Pepple <ken.pepple@gmail.com>2011-02-11 13:53:54 -0800
commit40ec6d45a25bf997ae62dbbf08494aa39f047e33 (patch)
tree5566bf6bd6379fbb2a76b55ff69c26e874843aa5 /nova
parente4061a0f5d06dfd6136c5dda94945214cc9a2cf5 (diff)
downloadnova-40ec6d45a25bf997ae62dbbf08494aa39f047e33.tar.gz
nova-40ec6d45a25bf997ae62dbbf08494aa39f047e33.tar.xz
nova-40ec6d45a25bf997ae62dbbf08494aa39f047e33.zip
updated tests and added more error checking
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/instance_types.py12
-rw-r--r--nova/db/sqlalchemy/api.py14
-rw-r--r--nova/tests/test_instance_types.py17
-rw-r--r--nova/tests/test_nova_manage.py21
4 files changed, 39 insertions, 25 deletions
diff --git a/nova/compute/instance_types.py b/nova/compute/instance_types.py
index 0cec4812e..f0b3fe473 100644
--- a/nova/compute/instance_types.py
+++ b/nova/compute/instance_types.py
@@ -48,7 +48,7 @@ def create(name, memory, vcpus, local_gb, flavorid):
flavorid=flavorid))
except exception.DBError:
raise exception.ApiError(_("Cannot create instance type: %s"),
- instance_type, "Invalid")
+ name)
def destroy(name):
@@ -59,9 +59,9 @@ def destroy(name):
else:
try:
db.instance_type_destroy(context.get_admin_context(), name)
- except exception.DBError:
+ except exception.NotFound:
raise exception.ApiError(_("Unknown instance type: %s"),
- instance_type, "Invalid")
+ name)
def get_all_types(inactive=0):
@@ -86,7 +86,7 @@ def get_instance_type(name):
return inst_type
except exception.DBError:
raise exception.ApiError(_("Unknown instance type: %s"),
- instance_type, "Invalid")
+ name)
def get_by_type(instance_type):
@@ -99,7 +99,7 @@ def get_by_type(instance_type):
return inst_type['name']
except exception.DBError:
raise exception.ApiError(_("Unknown instance type: %s"),
- instance_type, "Invalid")
+ instance_type)
def get_by_flavor_id(flavor_id):
@@ -112,4 +112,4 @@ def get_by_flavor_id(flavor_id):
return flavor['name']
except exception.DBError:
raise exception.ApiError(_("Unknown flavor: %s"),
- flavor_id, "Invalid")
+ flavor_id)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index f8b0559d2..323f9b965 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -2086,10 +2086,10 @@ def instance_type_get_by_flavor_id(context, id):
def instance_type_destroy(context, name):
""" Marks specific instance_type as deleted"""
session = get_session()
- try:
- instance_type_ref = session.query(models.InstanceTypes).\
- filter_by(name=name)
- instance_type_ref.update(dict(deleted=1))
- except:
- raise exception.DBError
- return instance_type_ref
+ instance_type_ref = session.query(models.InstanceTypes).\
+ filter_by(name=name)
+ records = instance_type_ref.update(dict(deleted=1))
+ if records == 0:
+ raise exception.NotFound
+ else:
+ return instance_type_ref
diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py
index 36c29d336..68ca3b842 100644
--- a/nova/tests/test_instance_types.py
+++ b/nova/tests/test_instance_types.py
@@ -62,3 +62,20 @@ class InstanceTypeTestCase(test.TestCase):
count()
inst_types = instance_types.get_all_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")
diff --git a/nova/tests/test_nova_manage.py b/nova/tests/test_nova_manage.py
index c1ef8cae9..8ab23ba2b 100644
--- a/nova/tests/test_nova_manage.py
+++ b/nova/tests/test_nova_manage.py
@@ -32,7 +32,6 @@ class NovaManageTestCase(test.TestCase):
max_flavorid = session.query(models.InstanceTypes).\
order_by("flavorid desc").first()
self.flavorid = str(max_flavorid["flavorid"] + 1)
- # self.flavorid = str(self.flavorid)
self.name = str(int(time.time()))
def teardown(self):
@@ -42,7 +41,7 @@ class NovaManageTestCase(test.TestCase):
fnull = open(os.devnull, 'w')
retcode = subprocess.call(["bin/nova-manage", "instance_type",
"create", self.name, "256", "1",
- "120", self.flavorid], stdout=fnull)
+ "10", self.flavorid], stdout=fnull)
self.assertEqual(0, retcode)
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
"delete", self.name], stdout=fnull)
@@ -67,16 +66,14 @@ class NovaManageTestCase(test.TestCase):
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
"create", self.name, "256", "0",\
"120", self.flavorid], stdout=fnull)
- # self.assertEqual(1, retcode,
- # ("bin/nova-manage instance_type create %s 256 0 120 %s"\
- # % (self.name, self.flavorid)))
+ self.assertEqual(1, retcode)
def test_should_fail_on_duplicate_flavorid(self):
fnull = open(os.devnull, 'w')
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
"create", self.name, "256", "1",\
"120", "1"], stdout=fnull)
- self.assertEqual(1, retcode)
+ self.assertEqual(3, retcode)
def test_should_fail_on_duplicate_name(self):
fnull = open(os.devnull, 'w')
@@ -87,10 +84,10 @@ class NovaManageTestCase(test.TestCase):
retcode = subprocess.call(["bin/nova-manage", "instance_type",\
"create", "fsfsfsdfsdf", "256", "1",\
"120", self.flavorid], stdout=fnull)
- self.assertEqual(1, retcode)
+ self.assertEqual(3, retcode)
- # def test_instance_type_delete_should_fail_without_valid_name(self):
- # fnull = open(os.devnull, 'w')
- # retcode = subprocess.call(["bin/nova-manage", "instance_type",\
- # "delete", "saefasff"], stdout=fnull)
- # self.assertEqual(1, retcode)
+ def test_instance_type_delete_should_fail_without_valid_name(self):
+ fnull = open(os.devnull, 'w')
+ retcode = subprocess.call(["bin/nova-manage", "instance_type",\
+ "delete", "doesntexist"], stdout=fnull)
+ self.assertEqual(1, retcode)