Merge "Add unit tests for the exact filters"

This commit is contained in:
Jenkins 2015-06-17 21:53:19 +00:00 committed by Gerrit Code Review
commit 93dbdf5202
3 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,45 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.scheduler.filters import exact_core_filter
from nova import test
from nova.tests.unit.scheduler import fakes
class TestExactCoreFilter(test.NoDBTestCase):
def setUp(self):
super(TestExactCoreFilter, self).setUp()
self.filt_cls = exact_core_filter.ExactCoreFilter()
def test_exact_core_filter_passes(self):
filter_properties = {'instance_type': {'vcpus': 1}}
host = self._get_host({'vcpus_total': 3, 'vcpus_used': 2})
self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
def test_exact_core_filter_fails(self):
filter_properties = {'instance_type': {'vcpus': 2}}
host = self._get_host({'vcpus_total': 3, 'vcpus_used': 2})
self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def test_exact_core_filter_passes_no_instance_type(self):
filter_properties = {}
host = self._get_host({'vcpus_total': 3, 'vcpus_used': 2})
self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
def test_exact_core_filter_fails_host_vcpus_not_set(self):
filter_properties = {'instance_type': {'vcpus': 1}}
host = self._get_host({})
self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def _get_host(self, host_attributes):
return fakes.FakeHostState('host1', 'node1', host_attributes)

View File

@ -0,0 +1,47 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.scheduler.filters import exact_disk_filter
from nova import test
from nova.tests.unit.scheduler import fakes
class TestExactDiskFilter(test.NoDBTestCase):
def setUp(self):
super(TestExactDiskFilter, self).setUp()
self.filt_cls = exact_disk_filter.ExactDiskFilter()
def test_exact_disk_filter_passes(self):
filter_properties = {
'instance_type': {
'root_gb': 1,
'ephemeral_gb': 1,
'swap': 1024
}
}
host = self._get_host({'free_disk_mb': 3 * 1024})
self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
def test_exact_disk_filter_fails(self):
filter_properties = {
'instance_type': {
'root_gb': 1,
'ephemeral_gb': 1,
'swap': 1024
}
}
host = self._get_host({'free_disk_mb': 2 * 1024})
self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def _get_host(self, host_attributes):
return fakes.FakeHostState('host1', 'node1', host_attributes)

View File

@ -0,0 +1,35 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.scheduler.filters import exact_ram_filter
from nova import test
from nova.tests.unit.scheduler import fakes
class TestRamFilter(test.NoDBTestCase):
def setUp(self):
super(TestRamFilter, self).setUp()
self.filt_cls = exact_ram_filter.ExactRamFilter()
def test_exact_ram_filter_passes(self):
filter_properties = {'instance_type': {'memory_mb': 1024}}
host = self._get_host({'free_ram_mb': 1024})
self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
def test_exact_ram_filter_fails(self):
filter_properties = {'instance_type': {'memory_mb': 512}}
host = self._get_host({'free_ram_mb': 1024})
self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def _get_host(self, host_attributes):
return fakes.FakeHostState('host1', 'node1', host_attributes)