From: Xing Yang Date: Wed, 24 Jun 2015 03:19:39 +0000 (-0400) Subject: Add unit tests for the capacity filter X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=639f6f5f3c3cb8845197d433daf02ff253ce0e32;p=openstack-build%2Fcinder-build.git Add unit tests for the capacity filter This patch adds some unit tests for the capacity filter in the scheduler. Change-Id: I114ac8789e55da3d2a2b746e6e2d738a35e642e4 --- 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