This patch adds flavor filtering, specifically the ability to flavor on minRam, minDisk, or both, per the 1.1 OSAPI spec.

In addition, this patch refactors instance_type_get_all to return a *list* of instance_types instead of a *dict*. This makes it more consistent with the rest of the DB API.
This commit is contained in:
Rick Harris
2011-09-22 16:42:20 +00:00
committed by Tarmac
2 changed files with 39 additions and 2 deletions

View File

@@ -161,3 +161,40 @@ class InstanceTypeTestCase(test.TestCase):
self.assertRaises(exception.InstanceTypeNotFound,
instance_types.get_instance_type_by_name,
self._nonexistent_flavor_id())
class InstanceTypeFilteringTest(test.TestCase):
"""Test cases for the filter option available for instance_type_get_all"""
def setUp(self):
super(InstanceTypeFilteringTest, self).setUp()
self.context = context.get_admin_context()
def assertFilterResults(self, filters, expected):
inst_types = db.api.instance_type_get_all(
self.context, filters=filters)
inst_names = [i['name'] for i in inst_types]
self.assertEqual(inst_names, expected)
def test_no_filters(self):
filters = None
expected = ['m1.large', 'm1.medium', 'm1.small', 'm1.tiny',
'm1.xlarge']
self.assertFilterResults(filters, expected)
def test_min_memory_mb_filter(self):
"""Exclude tiny instance which is 512 MB"""
filters = dict(min_memory_mb=513)
expected = ['m1.large', 'm1.medium', 'm1.small', 'm1.xlarge']
self.assertFilterResults(filters, expected)
def test_min_local_gb_filter(self):
"""Exclude everything but large and xlarge which have >= 80 GB"""
filters = dict(min_local_gb=80)
expected = ['m1.large', 'm1.xlarge']
self.assertFilterResults(filters, expected)
def test_min_memory_mb_AND_local_gb_filter(self):
"""Exclude everything but large and xlarge which have >= 80 GB"""
filters = dict(min_memory_mb=16384, min_local_gb=80)
expected = ['m1.xlarge']
self.assertFilterResults(filters, expected)

View File

@@ -99,8 +99,8 @@ def stub_out_db_instance_api(stubs):
"""Stubs out the db.instance_get_fixed_address method."""
return '10.10.10.10'
def fake_instance_type_get_all(context, inactive=0):
return INSTANCE_TYPES
def fake_instance_type_get_all(context, inactive=0, filters=None):
return INSTANCE_TYPES.values()
def fake_instance_type_get_by_name(context, name):
return INSTANCE_TYPES[name]