From 809a52a16baaa530121a48b8bf6cfff5ed6914be Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 24 Sep 2020 16:05:38 +0100 Subject: [PATCH] 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 --- nova/tests/functional/test_scheduler.py | 67 +++++++++++++++++++++---- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/nova/tests/functional/test_scheduler.py b/nova/tests/functional/test_scheduler.py index 6c9d66d99a32..2f3f6782f6ed 100644 --- a/nova/tests/functional/test_scheduler.py +++ b/nova/tests/functional/test_scheduler.py @@ -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):