Merge "fix bug in consume from share"
This commit is contained in:
commit
98dc72c72a
@ -368,6 +368,10 @@ class HostState(object):
|
|||||||
|
|
||||||
def consume_from_share(self, share):
|
def consume_from_share(self, share):
|
||||||
"""Incrementally update host state from an share."""
|
"""Incrementally update host state from an share."""
|
||||||
|
if self.provisioned_capacity_gb is not None:
|
||||||
|
self.provisioned_capacity_gb += share['size']
|
||||||
|
|
||||||
|
self.allocated_capacity_gb += share['size']
|
||||||
|
|
||||||
if (isinstance(self.free_capacity_gb, six.string_types)
|
if (isinstance(self.free_capacity_gb, six.string_types)
|
||||||
and self.free_capacity_gb != 'unknown'):
|
and self.free_capacity_gb != 'unknown'):
|
||||||
|
@ -795,10 +795,13 @@ class HostStateTestCase(test.TestCase):
|
|||||||
fake_context = context.RequestContext('user', 'project', is_admin=True)
|
fake_context = context.RequestContext('user', 'project', is_admin=True)
|
||||||
share_size = 10
|
share_size = 10
|
||||||
free_capacity = 100
|
free_capacity = 100
|
||||||
|
provisioned_capacity_gb = 50
|
||||||
fake_share = {'id': 'foo', 'size': share_size}
|
fake_share = {'id': 'foo', 'size': share_size}
|
||||||
share_capability = {
|
share_capability = {
|
||||||
'total_capacity_gb': free_capacity * 2,
|
'total_capacity_gb': free_capacity * 2,
|
||||||
'free_capacity_gb': free_capacity,
|
'free_capacity_gb': free_capacity,
|
||||||
|
'provisioned_capacity_gb': provisioned_capacity_gb,
|
||||||
|
'allocated_capacity_gb': provisioned_capacity_gb,
|
||||||
'reserved_percentage': 0,
|
'reserved_percentage': 0,
|
||||||
'timestamp': None
|
'timestamp': None
|
||||||
}
|
}
|
||||||
@ -809,11 +812,17 @@ class HostStateTestCase(test.TestCase):
|
|||||||
fake_host.consume_from_share(fake_share)
|
fake_host.consume_from_share(fake_share)
|
||||||
self.assertEqual(fake_host.free_capacity_gb,
|
self.assertEqual(fake_host.free_capacity_gb,
|
||||||
free_capacity - share_size)
|
free_capacity - share_size)
|
||||||
|
self.assertEqual(fake_host.provisioned_capacity_gb,
|
||||||
|
provisioned_capacity_gb + share_size)
|
||||||
|
self.assertEqual(fake_host.allocated_capacity_gb,
|
||||||
|
provisioned_capacity_gb + share_size)
|
||||||
|
|
||||||
def test_consume_from_share_unknown_capability(self):
|
def test_consume_from_share_unknown_capability(self):
|
||||||
share_capability = {
|
share_capability = {
|
||||||
'total_capacity_gb': 'unknown',
|
'total_capacity_gb': 'unknown',
|
||||||
'free_capacity_gb': 'unknown',
|
'free_capacity_gb': 'unknown',
|
||||||
|
'provisioned_capacity_gb': None,
|
||||||
|
'allocated_capacity_gb': 0,
|
||||||
'reserved_percentage': 0,
|
'reserved_percentage': 0,
|
||||||
'timestamp': None
|
'timestamp': None
|
||||||
}
|
}
|
||||||
@ -827,13 +836,18 @@ class HostStateTestCase(test.TestCase):
|
|||||||
fake_host.consume_from_share(fake_share)
|
fake_host.consume_from_share(fake_share)
|
||||||
self.assertEqual(fake_host.total_capacity_gb, 'unknown')
|
self.assertEqual(fake_host.total_capacity_gb, 'unknown')
|
||||||
self.assertEqual(fake_host.free_capacity_gb, 'unknown')
|
self.assertEqual(fake_host.free_capacity_gb, 'unknown')
|
||||||
|
self.assertIsNone(fake_host.provisioned_capacity_gb)
|
||||||
|
self.assertEqual(fake_host.allocated_capacity_gb, share_size)
|
||||||
|
|
||||||
def test_consume_from_share_invalid_capacity(self):
|
def test_consume_from_share_invalid_capacity(self):
|
||||||
fake_host = host_manager.PoolState('host1', {}, '_pool0')
|
fake_host = host_manager.PoolState('host1', {}, '_pool0')
|
||||||
fake_host.free_capacity_gb = 'invalid_foo_string'
|
fake_host.free_capacity_gb = 'invalid_foo_string'
|
||||||
|
fake_host.provisioned_capacity_gb = None
|
||||||
|
fake_host.allocated_capacity_gb = 0
|
||||||
|
fake_share = {'id': 'fake', 'size': 10}
|
||||||
|
|
||||||
self.assertRaises(exception.InvalidCapacity,
|
self.assertRaises(exception.InvalidCapacity,
|
||||||
fake_host.consume_from_share, 'fake')
|
fake_host.consume_from_share, fake_share)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
fixes:
|
||||||
|
- Updated the scheduler pool attributes ``provisioned_capacity_gb`` and
|
||||||
|
``allocated_capacity_gb`` to accommodate shares being created. This
|
||||||
|
helps maintain an approximate tally of these attributes in between back end
|
||||||
|
scheduler updates.
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user