Add tests for 'AggregateInstanceExtraSpecsFilter'

There are unit tests but nothing beats a functional test to properly
tease things out.

Change-Id: Ib84bcd286ab1db35839962ee70df620bc7be45aa
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2020-09-24 16:05:38 +01:00
parent f0d17e774f
commit 809a52a16b
1 changed files with 56 additions and 11 deletions

View File

@ -23,17 +23,7 @@ CELL1_NAME = 'cell1'
CELL2_NAME = 'cell2'
class AggregateImagePropertiesIsolationTestCase(
integrated_helpers._IntegratedTestBase,
):
"""Test the AggregateImagePropertiesIsolation filter."""
def setUp(self):
self.flags(
enabled_filters=['AggregateImagePropertiesIsolation'],
group='filter_scheduler')
super().setUp()
class _AggregateTestCase(integrated_helpers._IntegratedTestBase):
def _create_aggregate(self, metadata):
aggregate = self.admin_api.post_aggregate(
@ -45,6 +35,17 @@ class AggregateImagePropertiesIsolationTestCase(
aggregate['id'], self.compute.host)
return aggregate
class AggregateImagePropertiesIsolationTestCase(_AggregateTestCase):
"""Test the AggregateImagePropertiesIsolation filter."""
def setUp(self):
self.flags(
enabled_filters=['AggregateImagePropertiesIsolation'],
group='filter_scheduler')
super().setUp()
def _create_image(self, metadata):
image = {
'id': 'c456eb30-91d7-4f43-8f46-2efd9eccd744',
@ -132,6 +133,50 @@ class AggregateImagePropertiesIsolationTestCase(
self._create_server(image_uuid=image['id'])
class AggregateInstanceExtraSpecsFilterTestCase(_AggregateTestCase):
"""Test the AggregateInstanceExtraSpecsFilter filter."""
def setUp(self):
self.flags(
enabled_filters=['AggregateInstanceExtraSpecsFilter'],
group='filter_scheduler')
super().setUp()
def test_filter_passes(self):
"""Ensure the filter allows hosts in aggregates with matching metadata.
"""
self._create_aggregate(metadata={'foo': 'bar'})
flavor_id = self._create_flavor(extra_spec={'foo': 'bar'})
self._create_server(flavor_id=flavor_id)
def test_filter_rejects(self):
"""Ensure the filter rejects hosts in aggregates with mismatched
metadata.
"""
self._create_aggregate(metadata={'foo': 'bar'})
flavor_id = self._create_flavor(extra_spec={'foo': 'baz'})
self._create_server(flavor_id=flavor_id, expected_state='ERROR')
def test_filter_passes_with_prefix(self):
"""Ensure the filter allows hosts in aggregates with matching metadata
when the namespace is used.
"""
self._create_aggregate(metadata={'foo': 'bar'})
flavor_id = self._create_flavor(
extra_spec={'aggregate_instance_extra_specs:foo': 'bar'})
self._create_server(flavor_id=flavor_id)
def test_filter_rejects_with_prefix(self):
"""Ensure the filter rejects hosts in aggregates with mismatched
metadata when the namespace is used.
"""
self._create_aggregate(metadata={'foo': 'bar'})
flavor_id = self._create_flavor(
extra_spec={'aggregate_instance_extra_specs:foo': 'baz'})
self._create_server(flavor_id=flavor_id, expected_state='ERROR')
class MultiCellSchedulerTestCase(test.TestCase,
integrated_helpers.InstanceHelperMixin):