~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/tests/test_instance_types.py

  • Committer: Tarmac
  • Author(s): Rick Harris
  • Date: 2011-09-22 16:42:20 UTC
  • mfrom: (1590.1.11 flavor_min_filter)
  • Revision ID: tarmac-20110922164220-ndscikwberuj3c7f
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
        self.assertRaises(exception.InstanceTypeNotFound,
162
162
                          instance_types.get_instance_type_by_name,
163
163
                          self._nonexistent_flavor_id())
 
164
 
 
165
 
 
166
class InstanceTypeFilteringTest(test.TestCase):
 
167
    """Test cases for the filter option available for instance_type_get_all"""
 
168
    def setUp(self):
 
169
        super(InstanceTypeFilteringTest, self).setUp()
 
170
        self.context = context.get_admin_context()
 
171
 
 
172
    def assertFilterResults(self, filters, expected):
 
173
        inst_types = db.api.instance_type_get_all(
 
174
                self.context, filters=filters)
 
175
        inst_names = [i['name'] for i in inst_types]
 
176
        self.assertEqual(inst_names, expected)
 
177
 
 
178
    def test_no_filters(self):
 
179
        filters = None
 
180
        expected = ['m1.large', 'm1.medium', 'm1.small', 'm1.tiny',
 
181
                    'm1.xlarge']
 
182
        self.assertFilterResults(filters, expected)
 
183
 
 
184
    def test_min_memory_mb_filter(self):
 
185
        """Exclude tiny instance which is 512 MB"""
 
186
        filters = dict(min_memory_mb=513)
 
187
        expected = ['m1.large', 'm1.medium', 'm1.small', 'm1.xlarge']
 
188
        self.assertFilterResults(filters, expected)
 
189
 
 
190
    def test_min_local_gb_filter(self):
 
191
        """Exclude everything but large and xlarge which have >= 80 GB"""
 
192
        filters = dict(min_local_gb=80)
 
193
        expected = ['m1.large', 'm1.xlarge']
 
194
        self.assertFilterResults(filters, expected)
 
195
 
 
196
    def test_min_memory_mb_AND_local_gb_filter(self):
 
197
        """Exclude everything but large and xlarge which have >= 80 GB"""
 
198
        filters = dict(min_memory_mb=16384, min_local_gb=80)
 
199
        expected = ['m1.xlarge']
 
200
        self.assertFilterResults(filters, expected)