From e842fff31fd77289507d89387a62eee288aea6bc Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Fri, 11 Oct 2013 17:06:33 -0700 Subject: [PATCH] Make scheduler disk_filter take swap into account The disk_filter, which makes sure a node has enough disk space for an instance doesn't take the swap partition into account, but swap takes up disk space so it should. Change-Id: I0779dcf0f1cd60017b5b49ca38c0a15b23d802d7 Closes-Bug: #1239009 --- nova/scheduler/filters/disk_filter.py | 5 +++-- nova/tests/scheduler/test_host_filters.py | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nova/scheduler/filters/disk_filter.py b/nova/scheduler/filters/disk_filter.py index da62077b5e8b..066474cb35da 100644 --- a/nova/scheduler/filters/disk_filter.py +++ b/nova/scheduler/filters/disk_filter.py @@ -34,8 +34,9 @@ class DiskFilter(filters.BaseHostFilter): def host_passes(self, host_state, filter_properties): """Filter based on disk usage.""" instance_type = filter_properties.get('instance_type') - requested_disk = 1024 * (instance_type['root_gb'] + - instance_type['ephemeral_gb']) + requested_disk = (1024 * (instance_type['root_gb'] + + instance_type['ephemeral_gb']) + + instance_type['swap']) free_disk_mb = host_state.free_disk_mb total_usable_disk_mb = host_state.total_usable_disk_gb * 1024 diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index 3bacb99905bd..478f94ba3518 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -588,7 +588,7 @@ class HostFiltersTestCase(test.NoDBTestCase): filt_cls = self.class_map['DiskFilter']() self.flags(disk_allocation_ratio=1.0) filter_properties = {'instance_type': {'root_gb': 1, - 'ephemeral_gb': 1}} + 'ephemeral_gb': 1, 'swap': 512}} service = {'disabled': False} host = fakes.FakeHostState('host1', 'node1', {'free_disk_mb': 11 * 1024, 'total_usable_disk_gb': 13, @@ -599,8 +599,8 @@ class HostFiltersTestCase(test.NoDBTestCase): self._stub_service_is_up(True) filt_cls = self.class_map['DiskFilter']() self.flags(disk_allocation_ratio=1.0) - filter_properties = {'instance_type': {'root_gb': 11, - 'ephemeral_gb': 1}} + filter_properties = {'instance_type': {'root_gb': 10, + 'ephemeral_gb': 1, 'swap': 1024}} service = {'disabled': False} host = fakes.FakeHostState('host1', 'node1', {'free_disk_mb': 11 * 1024, 'total_usable_disk_gb': 13, @@ -612,7 +612,7 @@ class HostFiltersTestCase(test.NoDBTestCase): filt_cls = self.class_map['DiskFilter']() self.flags(disk_allocation_ratio=10.0) filter_properties = {'instance_type': {'root_gb': 100, - 'ephemeral_gb': 19}} + 'ephemeral_gb': 18, 'swap': 1024}} service = {'disabled': False} # 1GB used... so 119GB allowed... host = fakes.FakeHostState('host1', 'node1', @@ -626,7 +626,7 @@ class HostFiltersTestCase(test.NoDBTestCase): filt_cls = self.class_map['DiskFilter']() self.flags(disk_allocation_ratio=10.0) filter_properties = {'instance_type': {'root_gb': 100, - 'ephemeral_gb': 20}} + 'ephemeral_gb': 19, 'swap': 1024}} service = {'disabled': False} # 1GB used... so 119GB allowed... host = fakes.FakeHostState('host1', 'node1',