improve test coverage for instance types / flavors

This commit is contained in:
Ken Pepple
2011-08-20 12:41:38 -07:00
parent b7154220ae
commit 0544f5c910

View File

@@ -47,6 +47,29 @@ class InstanceTypeTestCase(test.TestCase):
self.id = max_id["id"] + 1
self.name = str(int(time.time()))
def _nonexistant_flavor_name(self):
"""return an instance type name not in the DB"""
nonexistant_flavor = "sdfsfsdf"
flavors = instance_types.get_all_types()
while flavors.has_key(nonexistant_flavor):
nonexistant_flavor = nonexistant_flavor.join("z")
else:
return nonexistant_flavor
def _nonexistant_flavor_id(self):
"""return an instance type ID not in the DB"""
nonexistant_flavor = 2700
flavor_ids = [ value["id"] for key, value in\
instance_types.get_all_types().iteritems() ]
while nonexistant_flavor in flavor_ids:
nonexistant_flavor += 1
else:
return nonexistant_flavor
def _existing_flavor(self):
"""return first instance type name"""
return instance_types.get_all_types().keys()[0]
def test_instance_type_create_then_delete(self):
"""Ensure instance types can be created"""
starting_inst_list = instance_types.get_all_types()
@@ -87,7 +110,8 @@ class InstanceTypeTestCase(test.TestCase):
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")
instance_types.destroy,
self._nonexistant_flavor_name())
def test_repeated_inst_types_should_raise_api_error(self):
"""Ensures that instance duplicates raises ApiError"""
@@ -97,3 +121,43 @@ class InstanceTypeTestCase(test.TestCase):
self.assertRaises(
exception.ApiError,
instance_types.create, new_name, 256, 1, 120, self.flavorid)
def test_will_not_destroy_with_no_name(self):
"""Ensure destroy sad path of no name raises error"""
self.assertRaises(exception.ApiError,
instance_types.destroy,
self._nonexistant_flavor_name())
def test_will_not_purge_without_name(self):
"""Ensure purge without a name raises error"""
self.assertRaises(exception.InvalidInstanceType,
instance_types.purge, None)
def test_will_not_purge_with_wrong_name(self):
"""Ensure purge without correct name raises error"""
self.assertRaises(exception.ApiError,
instance_types.purge,
self._nonexistant_flavor_name())
def test_will_not_get_bad_default_instance_type(self):
"""ensures error raised on bad default instance type"""
FLAGS.default_instance_type = self._nonexistant_flavor_name()
self.assertRaises(exception.InstanceTypeNotFoundByName,
instance_types.get_default_instance_type)
def test_will_not_get_instance_type_by_name_with_no_name(self):
"""Ensure get by name returns default flavor with no name"""
self.assertEqual(instance_types.get_default_instance_type(),
instance_types.get_instance_type_by_name(None))
def test_will_not_get_instance_type_with_bad_name(self):
"""Ensure get by name returns default flavor with bad name"""
self.assertRaises(exception.InstanceTypeNotFound,
instance_types.get_instance_type,
self._nonexistant_flavor_name())
def test_will_not_get_flavor_by_bad_flavor_id(self):
"""Ensure get by flavor raises error with wrong flavorid"""
self.assertRaises(exception.InstanceTypeNotFound,
instance_types.get_instance_type_by_name,
self._nonexistant_flavor_id())