From: Zhiteng Huang Date: Fri, 5 Dec 2014 10:01:53 +0000 (+0800) Subject: Allow HostState to handle empty capabilities X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6ac5054ceb398b55a03d311ff868e5c93a65dcbb;p=openstack-build%2Fcinder-build.git Allow HostState to handle empty capabilities In some cases, where the capabilities reported from driver is emtpy, scheduler would raise exception thus unable to correctly handle scheduling request even when other backend candidates are able to fulfill the request. This change does some modifications to HostState so that it is able to handle empty capabilities. Change-Id: Icb6522852d427dea3fbd1ec4b4cc94a184d3669d Fixes-bug: #1398875 --- diff --git a/cinder/scheduler/host_manager.py b/cinder/scheduler/host_manager.py index 9563ea172..ace38eb04 100644 --- a/cinder/scheduler/host_manager.py +++ b/cinder/scheduler/host_manager.py @@ -300,12 +300,12 @@ class PoolState(HostState): return self.update_backend(capability) - self.total_capacity_gb = capability['total_capacity_gb'] - self.free_capacity_gb = capability['free_capacity_gb'] + self.total_capacity_gb = capability.get('total_capacity_gb', 0) + self.free_capacity_gb = capability.get('free_capacity_gb', 0) self.allocated_capacity_gb = capability.get( 'allocated_capacity_gb', 0) self.QoS_support = capability.get('QoS_support', False) - self.reserved_percentage = capability['reserved_percentage'] + self.reserved_percentage = capability.get('reserved_percentage', 0) def update_pools(self, capability): # Do nothing, since we don't have pools within pool, yet diff --git a/cinder/tests/scheduler/test_host_manager.py b/cinder/tests/scheduler/test_host_manager.py index 3f51d4bbd..aaa4bf549 100644 --- a/cinder/tests/scheduler/test_host_manager.py +++ b/cinder/tests/scheduler/test_host_manager.py @@ -427,6 +427,20 @@ class HostStateTestCase(test.TestCase): self.assertEqual(fake_host.pools['_pool0'].free_capacity_gb, 'unknown') + def test_update_from_empty_volume_capability(self): + fake_host = host_manager.HostState('host1') + + vol_cap = {'timestamp': None} + + fake_host.update_from_volume_capability(vol_cap) + self.assertEqual(fake_host.total_capacity_gb, 0) + self.assertEqual(fake_host.free_capacity_gb, None) + # Pool stats has been updated + self.assertEqual(fake_host.pools['_pool0'].total_capacity_gb, + 0) + self.assertEqual(fake_host.pools['_pool0'].free_capacity_gb, + 0) + class PoolStateTestCase(test.TestCase): """Test case for HostState class."""