From 639f6f5f3c3cb8845197d433daf02ff253ce0e32 Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Tue, 23 Jun 2015 23:19:39 -0400 Subject: [PATCH] Add unit tests for the capacity filter This patch adds some unit tests for the capacity filter in the scheduler. Change-Id: I114ac8789e55da3d2a2b746e6e2d738a35e642e4 --- .../tests/unit/scheduler/test_host_filters.py | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/cinder/tests/unit/scheduler/test_host_filters.py b/cinder/tests/unit/scheduler/test_host_filters.py index b52100353..ec4f013d8 100644 --- a/cinder/tests/unit/scheduler/test_host_filters.py +++ b/cinder/tests/unit/scheduler/test_host_filters.py @@ -92,6 +92,18 @@ class CapacityFilterTestCase(HostFiltersTestCase): 'service': service}) self.assertFalse(filt_cls.host_passes(host, filter_properties)) + @mock.patch('cinder.utils.service_is_up') + def test_filter_fails_free_capacity_None(self, _mock_serv_is_up): + _mock_serv_is_up.return_value = True + filt_cls = self.class_map['CapacityFilter']() + filter_properties = {'size': 100} + service = {'disabled': False} + host = fakes.FakeHostState('host1', + {'free_capacity_gb': None, + 'updated_at': None, + 'service': service}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + @mock.patch('cinder.utils.service_is_up') def test_filter_passes_infinite(self, _mock_serv_is_up): _mock_serv_is_up.return_value = True @@ -116,6 +128,73 @@ class CapacityFilterTestCase(HostFiltersTestCase): 'service': service}) self.assertTrue(filt_cls.host_passes(host, filter_properties)) + @mock.patch('cinder.utils.service_is_up') + def test_filter_passes_total_infinite(self, _mock_serv_is_up): + _mock_serv_is_up.return_value = True + filt_cls = self.class_map['CapacityFilter']() + filter_properties = {'size': 100} + service = {'disabled': False} + host = fakes.FakeHostState('host1', + {'free_capacity_gb': 'infinite', + 'total_capacity_gb': 'infinite', + 'reserved_percentage': 0, + 'updated_at': None, + 'service': service}) + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + + @mock.patch('cinder.utils.service_is_up') + def test_filter_passes_total_unknown(self, _mock_serv_is_up): + _mock_serv_is_up.return_value = True + filt_cls = self.class_map['CapacityFilter']() + filter_properties = {'size': 100} + service = {'disabled': False} + host = fakes.FakeHostState('host1', + {'free_capacity_gb': 'unknown', + 'total_capacity_gb': 'unknown', + 'reserved_percentage': 0, + 'updated_at': None, + 'service': service}) + self.assertTrue(filt_cls.host_passes(host, filter_properties)) + + @mock.patch('cinder.utils.service_is_up') + def test_filter_fails_total_infinite(self, _mock_serv_is_up): + _mock_serv_is_up.return_value = True + filt_cls = self.class_map['CapacityFilter']() + filter_properties = {'size': 100} + service = {'disabled': False} + host = fakes.FakeHostState('host1', + {'total_capacity_gb': 'infinite', + 'reserved_percentage': 5, + 'updated_at': None, + 'service': service}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + + @mock.patch('cinder.utils.service_is_up') + def test_filter_fails_total_unknown(self, _mock_serv_is_up): + _mock_serv_is_up.return_value = True + filt_cls = self.class_map['CapacityFilter']() + filter_properties = {'size': 100} + service = {'disabled': False} + host = fakes.FakeHostState('host1', + {'total_capacity_gb': 'unknown', + 'reserved_percentage': 5, + 'updated_at': None, + 'service': service}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + + @mock.patch('cinder.utils.service_is_up') + def test_filter_fails_total_zero(self, _mock_serv_is_up): + _mock_serv_is_up.return_value = True + filt_cls = self.class_map['CapacityFilter']() + filter_properties = {'size': 100} + service = {'disabled': False} + host = fakes.FakeHostState('host1', + {'total_capacity_gb': 0, + 'reserved_percentage': 5, + 'updated_at': None, + 'service': service}) + self.assertFalse(filt_cls.host_passes(host, filter_properties)) + @mock.patch('cinder.utils.service_is_up') def test_filter_thin_true_passes(self, _mock_serv_is_up): _mock_serv_is_up.return_value = True -- 2.45.2