From 91a2b1253b022d9842c65f76a3b4fe5445c957af Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 21 Sep 2011 16:29:36 +0000 Subject: [PATCH] Adding flavor filtering --- nova/tests/test_instance_types.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index 09f53223..1ed34fba 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -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)