From af47d85f020c3455eb8f4efd824b8da14289dd9b Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Thu, 19 Jan 2012 21:56:58 -0800 Subject: Support filter based on CPU core (over)allocation Change-Id: Ieb15c71e7a335fc642687fe59a3cc2f9929ade26 --- nova/tests/scheduler/fakes.py | 22 +++++++++++----------- nova/tests/scheduler/test_distributed_scheduler.py | 5 +++-- nova/tests/scheduler/test_host_filters.py | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 13 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/scheduler/fakes.py b/nova/tests/scheduler/fakes.py index 0b8391a4d..991ad84f1 100644 --- a/nova/tests/scheduler/fakes.py +++ b/nova/tests/scheduler/fakes.py @@ -23,27 +23,27 @@ from nova.scheduler import zone_manager COMPUTE_NODES = [ - dict(id=1, local_gb=1024, memory_mb=1024, + dict(id=1, local_gb=1024, memory_mb=1024, vcpus=1, service=dict(host='host1', disabled=False)), - dict(id=2, local_gb=2048, memory_mb=2048, + dict(id=2, local_gb=2048, memory_mb=2048, vcpus=2, service=dict(host='host2', disabled=True)), - dict(id=3, local_gb=4096, memory_mb=4096, + dict(id=3, local_gb=4096, memory_mb=4096, vcpus=4, service=dict(host='host3', disabled=False)), - dict(id=4, local_gb=8192, memory_mb=8192, + dict(id=4, local_gb=8192, memory_mb=8192, vcpus=8, service=dict(host='host4', disabled=False)), # Broken entry - dict(id=5, local_gb=1024, memory_mb=1024, service=None), + dict(id=5, local_gb=1024, memory_mb=1024, vcpus=1, service=None), ] INSTANCES = [ - dict(local_gb=512, memory_mb=512, host='host1'), - dict(local_gb=512, memory_mb=512, host='host2'), - dict(local_gb=512, memory_mb=512, host='host2'), - dict(local_gb=1024, memory_mb=1024, host='host3'), + dict(local_gb=512, memory_mb=512, vcpus=1, host='host1'), + dict(local_gb=512, memory_mb=512, vcpus=1, host='host2'), + dict(local_gb=512, memory_mb=512, vcpus=1, host='host2'), + dict(local_gb=1024, memory_mb=1024, vcpus=1, host='host3'), # Broken host - dict(local_gb=1024, memory_mb=1024, host=None), + dict(local_gb=1024, memory_mb=1024, vcpus=1, host=None), # No matching host - dict(local_gb=1024, memory_mb=1024, host='host5'), + dict(local_gb=1024, memory_mb=1024, vcpus=1, host='host5'), ] diff --git a/nova/tests/scheduler/test_distributed_scheduler.py b/nova/tests/scheduler/test_distributed_scheduler.py index 3e909d005..ca498f7aa 100644 --- a/nova/tests/scheduler/test_distributed_scheduler.py +++ b/nova/tests/scheduler/test_distributed_scheduler.py @@ -260,7 +260,8 @@ class DistributedSchedulerTestCase(test.TestCase): 'instance_type': {'memory_mb': 512, 'local_gb': 512}, 'instance_properties': {'project_id': 1, 'memory_mb': 512, - 'local_gb': 512}} + 'local_gb': 512, + 'vcpus': 1}} filter_properties = {'local_zone_only': True} self.mox.ReplayAll() weighted_hosts = sched._schedule(fake_context, 'compute', @@ -299,5 +300,5 @@ class DistributedSchedulerTestCase(test.TestCase): self.assertEquals(weight, 1.0) hostinfo = host_manager.HostState('host', 'compute') hostinfo.update_from_compute_node(dict(memory_mb=1000, - local_gb=0)) + local_gb=0, vcpus=1)) self.assertEquals(1000 - 128, fn(hostinfo, {})) diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index 8462422ad..6b5f6d736 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -415,3 +415,25 @@ class HostFiltersTestCase(test.TestCase): raw = ['=', '$foo', 2, 2] filter_properties = {'query': json.dumps(raw)} self.assertTrue(filt_cls.host_passes(host, filter_properties)) + + def test_core_filter_passes(self): + filt_cls = filters.CoreFilter() + filter_properties = {'instance_type': {'vcpus': 1}} + self.flags(cpu_allocation_ratio=2) + host = fakes.FakeHostState('host1', 'compute', + {'vcpus_total': 4, 'vcpus_used': 7}) + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + + def test_core_filter_fails_safe(self): + filt_cls = filters.CoreFilter() + filter_properties = {'instance_type': {'vcpus': 1}} + host = fakes.FakeHostState('host1', 'compute', {}) + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + + def test_core_filter_fails(self): + filt_cls = filters.CoreFilter() + filter_properties = {'instance_type': {'vcpus': 1}} + self.flags(cpu_allocation_ratio=2) + host = fakes.FakeHostState('host1', 'compute', + {'vcpus_total': 4, 'vcpus_used': 8}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) -- cgit