summaryrefslogtreecommitdiffstats
path: root/nova/tests/scheduler/test_host_filters.py
diff options
context:
space:
mode:
Diffstat (limited to 'nova/tests/scheduler/test_host_filters.py')
-rw-r--r--nova/tests/scheduler/test_host_filters.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py
index 48d4db1fd..8832f5c2b 100644
--- a/nova/tests/scheduler/test_host_filters.py
+++ b/nova/tests/scheduler/test_host_filters.py
@@ -536,6 +536,64 @@ class HostFiltersTestCase(test.NoDBTestCase):
self.assertTrue(filt_cls.host_passes(host, filter_properties))
self.assertEqual(2048 * 2.0, host.limits['memory_mb'])
+ def test_aggregate_ram_filter_value_error(self):
+ self._stub_service_is_up(True)
+ filt_cls = self.class_map['AggregateRamFilter']()
+ self.flags(ram_allocation_ratio=1.0)
+ filter_properties = {'context': self.context,
+ 'instance_type': {'memory_mb': 1024}}
+ capabilities = {'enabled': True}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1', 'node1',
+ {'free_ram_mb': 1024, 'total_usable_ram_mb': 1024,
+ 'capabilities': capabilities, 'service': service})
+ self._create_aggregate_with_host(name='fake_aggregate',
+ hosts=['host1'],
+ metadata={'ram_allocation_ratio': 'XXX'})
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ self.assertEqual(1024 * 1.0, host.limits['memory_mb'])
+
+ def test_aggregate_ram_filter_default_value(self):
+ self._stub_service_is_up(True)
+ filt_cls = self.class_map['AggregateRamFilter']()
+ self.flags(ram_allocation_ratio=1.0)
+ filter_properties = {'context': self.context,
+ 'instance_type': {'memory_mb': 1024}}
+ capabilities = {'enabled': True}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1', 'node1',
+ {'free_ram_mb': 1023, 'total_usable_ram_mb': 1024,
+ 'capabilities': capabilities, 'service': service})
+ # False: fallback to default flag w/o aggregates
+ self.assertFalse(filt_cls.host_passes(host, filter_properties))
+ self._create_aggregate_with_host(name='fake_aggregate',
+ hosts=['host1'],
+ metadata={'ram_allocation_ratio': '2.0'})
+ # True: use ratio from aggregates
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ self.assertEqual(1024 * 2.0, host.limits['memory_mb'])
+
+ def test_aggregate_ram_filter_conflict_values(self):
+ self._stub_service_is_up(True)
+ filt_cls = self.class_map['AggregateRamFilter']()
+ self.flags(ram_allocation_ratio=1.0)
+ filter_properties = {'context': self.context,
+ 'instance_type': {'memory_mb': 1024}}
+ capabilities = {'enabled': True}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1', 'node1',
+ {'free_ram_mb': 1023, 'total_usable_ram_mb': 1024,
+ 'capabilities': capabilities, 'service': service})
+ self._create_aggregate_with_host(name='fake_aggregate1',
+ hosts=['host1'],
+ metadata={'ram_allocation_ratio': '1.5'})
+ self._create_aggregate_with_host(name='fake_aggregate2',
+ hosts=['host1'],
+ metadata={'ram_allocation_ratio': '2.0'})
+ # use the minimum ratio from aggregates
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ self.assertEqual(1024 * 1.5, host.limits['memory_mb'])
+
def test_disk_filter_passes(self):
self._stub_service_is_up(True)
filt_cls = self.class_map['DiskFilter']()
@@ -1310,6 +1368,52 @@ class HostFiltersTestCase(test.NoDBTestCase):
{'vcpus_total': 4, 'vcpus_used': 8})
self.assertFalse(filt_cls.host_passes(host, filter_properties))
+ def test_aggregate_core_filter_value_error(self):
+ filt_cls = self.class_map['AggregateCoreFilter']()
+ filter_properties = {'context': self.context,
+ 'instance_type': {'vcpus': 1}}
+ self.flags(cpu_allocation_ratio=2)
+ host = fakes.FakeHostState('host1', 'node1',
+ {'vcpus_total': 4, 'vcpus_used': 7})
+ self._create_aggregate_with_host(name='fake_aggregate',
+ hosts=['host1'],
+ metadata={'cpu_allocation_ratio': 'XXX'})
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ self.assertEqual(4 * 2, host.limits['vcpu'])
+
+ def test_aggregate_core_filter_default_value(self):
+ filt_cls = self.class_map['AggregateCoreFilter']()
+ filter_properties = {'context': self.context,
+ 'instance_type': {'vcpus': 1}}
+ self.flags(cpu_allocation_ratio=2)
+ host = fakes.FakeHostState('host1', 'node1',
+ {'vcpus_total': 4, 'vcpus_used': 8})
+ # False: fallback to default flag w/o aggregates
+ self.assertFalse(filt_cls.host_passes(host, filter_properties))
+ self._create_aggregate_with_host(name='fake_aggregate',
+ hosts=['host1'],
+ metadata={'cpu_allocation_ratio': '3'})
+ # True: use ratio from aggregates
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
+ self.assertEqual(4 * 3, host.limits['vcpu'])
+
+ def test_aggregate_core_filter_conflict_values(self):
+ filt_cls = self.class_map['AggregateCoreFilter']()
+ filter_properties = {'context': self.context,
+ 'instance_type': {'vcpus': 1}}
+ self.flags(cpu_allocation_ratio=1)
+ host = fakes.FakeHostState('host1', 'node1',
+ {'vcpus_total': 4, 'vcpus_used': 8})
+ self._create_aggregate_with_host(name='fake_aggregate1',
+ hosts=['host1'],
+ metadata={'cpu_allocation_ratio': '2'})
+ self._create_aggregate_with_host(name='fake_aggregate2',
+ hosts=['host1'],
+ metadata={'cpu_allocation_ratio': '3'})
+ # use the minimum ratio from aggregates
+ self.assertFalse(filt_cls.host_passes(host, filter_properties))
+ self.assertEqual(4 * 2, host.limits['vcpu'])
+
@staticmethod
def _make_zone_request(zone, is_admin=False):
ctxt = context.RequestContext('fake', 'fake', is_admin=is_admin)