"volume node info collection broken."))
return False
+ free_space = host_state.free_capacity_gb
+ if free_space == 'infinite' or free_space == 'unknown':
+ # NOTE(zhiteng) for those back-ends cannot report actual
+ # available capacity, we assume it is able to serve the
+ # request. Even if it was not, the retry mechanism is
+ # able to handle the failure by rescheduling
+ return True
reserved = float(host_state.reserved_percentage) / 100
- free = math.floor(host_state.free_capacity_gb * (1 - reserved))
+ free = math.floor(free_space * (1 - reserved))
return free >= volume_size
def consume_from_volume(self, volume):
"""Incrementally update host state from an volume"""
volume_gb = volume['size']
- self.free_capacity_gb -= volume_gb
+ if self.free_capacity_gb == 'infinite':
+ # There's virtually infinite space on back-end
+ pass
+ elif self.free_capacity_gb == 'unknown':
+ # Unable to determine the actual free space on back-end
+ pass
+ else:
+ self.free_capacity_gb -= volume_gb
self.updated = timeutils.utcnow()
def __repr__(self):
'updated_at': None,
'service': service})
self.assertFalse(filt_cls.host_passes(host, filter_properties))
+
+ def test_capacity_filter_passes_infinite(self):
+ self._stub_service_is_up(True)
+ filt_cls = self.class_map['CapacityFilter']()
+ filter_properties = {'size': 100}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1',
+ {'free_capacity_gb': 'infinite',
+ 'updated_at': None,
+ 'service': service})
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
+
+ def test_capacity_filter_passes_unknown(self):
+ self._stub_service_is_up(True)
+ filt_cls = self.class_map['CapacityFilter']()
+ filter_properties = {'size': 100}
+ service = {'disabled': False}
+ host = fakes.FakeHostState('host1',
+ {'free_capacity_gb': 'unknown',
+ 'updated_at': None,
+ 'service': service})
+ self.assertTrue(filt_cls.host_passes(host, filter_properties))
fake_host.update_from_volume_capability(volume_capability)
self.assertEqual(fake_host.free_capacity_gb, 512)
+
+ def test_update_from_volume_infinite_capability(self):
+ fake_host = host_manager.HostState('host1')
+ self.assertEqual(fake_host.free_capacity_gb, 0)
+
+ volume_capability = {'total_capacity_gb': 'infinite',
+ 'free_capacity_gb': 'infinite',
+ 'reserved_percentage': 0,
+ 'timestamp': None}
+
+ fake_host.update_from_volume_capability(volume_capability)
+ self.assertEqual(fake_host.total_capacity_gb, 'infinite')
+ self.assertEqual(fake_host.free_capacity_gb, 'infinite')
+
+ def test_update_from_volume_unknown_capability(self):
+ fake_host = host_manager.HostState('host1')
+ self.assertEqual(fake_host.free_capacity_gb, 0)
+
+ volume_capability = {'total_capacity_gb': 'infinite',
+ 'free_capacity_gb': 'unknown',
+ 'reserved_percentage': 0,
+ 'timestamp': None}
+
+ fake_host.update_from_volume_capability(volume_capability)
+ self.assertEqual(fake_host.total_capacity_gb, 'infinite')
+ self.assertEqual(fake_host.free_capacity_gb, 'unknown')