From 36f6e95033111f5c0b75dba378c7ca270e1e1631 Mon Sep 17 00:00:00 2001 From: zhangqing Date: Mon, 20 Apr 2020 15:56:51 +0800 Subject: [PATCH] fix bug in consume from share update provisioned_capacity_gb and allocated_capacity_gb Closes-bug: #1872873 Change-Id: Ic239abafcb68063f3a6b007487141e5bb8315e0d (cherry picked from commit 4b471012de5613cde7ad5cc602e28fe55774e739) (cherry picked from commit 6a4eab05563d5795c7ea7f986729aeda8b95c2be) (cherry picked from commit 429b5d297b012b1d0696b6482706070eab03dc72) --- manila/scheduler/host_manager.py | 4 ++++ manila/tests/scheduler/test_host_manager.py | 16 +++++++++++++++- ...-fix-consume-from-share-eea5941de17a5bcc.yaml | 8 ++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/bug-1872873-fix-consume-from-share-eea5941de17a5bcc.yaml diff --git a/manila/scheduler/host_manager.py b/manila/scheduler/host_manager.py index aaf8065f4d..d61b93e2db 100644 --- a/manila/scheduler/host_manager.py +++ b/manila/scheduler/host_manager.py @@ -366,6 +366,10 @@ class HostState(object): def consume_from_share(self, 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) and self.free_capacity_gb != 'unknown'): diff --git a/manila/tests/scheduler/test_host_manager.py b/manila/tests/scheduler/test_host_manager.py index 4bdbe19826..ec9e28b6fa 100644 --- a/manila/tests/scheduler/test_host_manager.py +++ b/manila/tests/scheduler/test_host_manager.py @@ -794,10 +794,13 @@ class HostStateTestCase(test.TestCase): fake_context = context.RequestContext('user', 'project', is_admin=True) share_size = 10 free_capacity = 100 + provisioned_capacity_gb = 50 fake_share = {'id': 'foo', 'size': share_size} share_capability = { 'total_capacity_gb': free_capacity * 2, 'free_capacity_gb': free_capacity, + 'provisioned_capacity_gb': provisioned_capacity_gb, + 'allocated_capacity_gb': provisioned_capacity_gb, 'reserved_percentage': 0, 'timestamp': None } @@ -808,11 +811,17 @@ class HostStateTestCase(test.TestCase): fake_host.consume_from_share(fake_share) self.assertEqual(fake_host.free_capacity_gb, 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): share_capability = { 'total_capacity_gb': 'unknown', 'free_capacity_gb': 'unknown', + 'provisioned_capacity_gb': None, + 'allocated_capacity_gb': 0, 'reserved_percentage': 0, 'timestamp': None } @@ -826,13 +835,18 @@ class HostStateTestCase(test.TestCase): fake_host.consume_from_share(fake_share) self.assertEqual(fake_host.total_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): fake_host = host_manager.PoolState('host1', {}, '_pool0') 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, - fake_host.consume_from_share, 'fake') + fake_host.consume_from_share, fake_share) def test_repr(self): diff --git a/releasenotes/notes/bug-1872873-fix-consume-from-share-eea5941de17a5bcc.yaml b/releasenotes/notes/bug-1872873-fix-consume-from-share-eea5941de17a5bcc.yaml new file mode 100644 index 0000000000..8d3b616a0d --- /dev/null +++ b/releasenotes/notes/bug-1872873-fix-consume-from-share-eea5941de17a5bcc.yaml @@ -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. +