Add consume_from_share method to HostState class
Modify FilterScheduler._schedule_share to call new new method consume_from_share (it was calling consume_from_volume). Add HostState.consume_from_share to host_manager. Change-Id: I124674afe739ccf9648f91fcfbc63fd3be7caecc Closes-Bug: #1253860
This commit is contained in:
parent
d24b76b4d7
commit
f9636fa2c9
@ -64,7 +64,7 @@ if __name__ == '__main__':
|
||||
except (Exception, SystemExit):
|
||||
LOG.exception(_('Failed to load osapi_share'))
|
||||
|
||||
for binary in ['manila-share', 'manila-scheduler']:
|
||||
for binary in ['manila-share', 'manila-scheduler', 'manila-api']:
|
||||
try:
|
||||
servers.append(service.Service.create(binary=binary))
|
||||
except (Exception, SystemExit):
|
||||
|
@ -156,7 +156,7 @@ class FilterScheduler(driver.Scheduler):
|
||||
best_host = weighed_hosts[0]
|
||||
LOG.debug(_("Choosing for share: %(best_host)s") % locals())
|
||||
#NOTE(rushiagr): updating the available space parameters at same place
|
||||
best_host.obj.consume_from_volume(share_properties)
|
||||
best_host.obj.consume_from_share(share_properties)
|
||||
return best_host
|
||||
|
||||
def _populate_retry_share(self, filter_properties, properties):
|
||||
|
@ -132,6 +132,19 @@ class HostState(object):
|
||||
|
||||
self.updated = capability['timestamp']
|
||||
|
||||
def consume_from_share(self, share):
|
||||
"""Incrementally update host state from an share"""
|
||||
share_gb = share['size']
|
||||
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 -= share_gb
|
||||
self.updated = timeutils.utcnow()
|
||||
|
||||
|
||||
class HostManager(object):
|
||||
"""Base HostManager class."""
|
||||
|
@ -201,3 +201,49 @@ class HostStateTestCase(test.TestCase):
|
||||
fake_host.update_from_share_capability(share_capability)
|
||||
self.assertEqual(fake_host.total_capacity_gb, 'infinite')
|
||||
self.assertEqual(fake_host.free_capacity_gb, 'unknown')
|
||||
|
||||
def test_consume_from_share_capability(self):
|
||||
fake_host = host_manager.HostState('host1')
|
||||
share_size = 10
|
||||
free_capacity = 100
|
||||
fake_share = {'id': 'foo', 'size': share_size}
|
||||
|
||||
share_capability = {'total_capacity_gb': free_capacity * 2,
|
||||
'free_capacity_gb': free_capacity,
|
||||
'reserved_percentage': 0,
|
||||
'timestamp': None}
|
||||
|
||||
fake_host.update_from_share_capability(share_capability)
|
||||
fake_host.consume_from_share(fake_share)
|
||||
self.assertEqual(fake_host.free_capacity_gb,
|
||||
free_capacity - share_size)
|
||||
|
||||
def test_consume_from_share_infinite_capability(self):
|
||||
fake_host = host_manager.HostState('host1')
|
||||
share_size = 1000
|
||||
fake_share = {'id': 'foo', 'size': share_size}
|
||||
|
||||
share_capability = {'total_capacity_gb': 'infinite',
|
||||
'free_capacity_gb': 'infinite',
|
||||
'reserved_percentage': 0,
|
||||
'timestamp': None}
|
||||
|
||||
fake_host.update_from_share_capability(share_capability)
|
||||
fake_host.consume_from_share(fake_share)
|
||||
self.assertEqual(fake_host.total_capacity_gb, 'infinite')
|
||||
self.assertEqual(fake_host.free_capacity_gb, 'infinite')
|
||||
|
||||
def test_consume_from_share_unknown_capability(self):
|
||||
fake_host = host_manager.HostState('host1')
|
||||
share_size = 1000
|
||||
fake_share = {'id': 'foo', 'size': share_size}
|
||||
|
||||
share_capability = {'total_capacity_gb': 'infinite',
|
||||
'free_capacity_gb': 'unknown',
|
||||
'reserved_percentage': 0,
|
||||
'timestamp': None}
|
||||
|
||||
fake_host.update_from_share_capability(share_capability)
|
||||
fake_host.consume_from_share(fake_share)
|
||||
self.assertEqual(fake_host.total_capacity_gb, 'infinite')
|
||||
self.assertEqual(fake_host.free_capacity_gb, 'unknown')
|
||||
|
Loading…
Reference in New Issue
Block a user