Fix count in the response of shares/snapshots list API

Share/Snapshot list API returns count of shares/snapshotsi along-with
list of resource objects. The list returned by API contains correct
entries of shares/snapshots but it returns the wrong count as it
ShareInstances/SnapshotInstances. So filter queries by unique
share_id/snapshot_id.

Closes-bug: #2033604
Change-Id: I13c415767b0d126563f9553df415de564b3901d6
This commit is contained in:
Kiran Pawar 2023-08-31 08:33:54 +00:00
parent 1764a22086
commit 9e835496dc
3 changed files with 17 additions and 4 deletions

View File

@ -2359,7 +2359,7 @@ def _share_get_all_with_filters(context, project_id=None, share_server_id=None,
# NOTE(carloss): Count must be calculated before limit and offset are
# applied into the query.
if show_count:
count = query.count()
count = query.order_by(models.Share.id).distinct().count()
if 'limit' in filters:
offset = filters.get('offset', 0)
@ -3445,7 +3445,7 @@ def _share_snapshot_get_all_with_filters(context, project_id=None,
count = None
if show_count:
count = query.count()
count = query.order_by(models.ShareSnapshot.id).distinct().count()
if limit is not None:
query = query.limit(limit)

View File

@ -685,8 +685,13 @@ class ShareDatabaseAPITestCase(test.TestCase):
@ddt.unpack
def test_share_get_all_with_count(self, filters, amount_of_shares,
expected_shares_len):
[db_utils.create_share(display_name='fake_name_%s' % str(i))
for i in range(amount_of_shares)]
c_shares = [
db_utils.create_share(display_name='fake_name_%s' % str(i))
for i in range(amount_of_shares)]
# create one more share instance
db_utils.create_share_instance(share_id=c_shares[0]['id'])
db_utils.create_share_instance(share_id=c_shares[1]['id'])
count, shares = db_api.share_get_all_with_count(
self.ctxt, filters=filters)

View File

@ -0,0 +1,8 @@
---
fixes:
- |
The 'count' returned by shares and snapshots list API is fixed to provide
correct value i.e. count of shares/snapshots instead of
shareInstances/shareSnapshotInstances respectively. Please refer to the
`Launchpad bug #2033604 <https://bugs.launchpad.net/manila/+bug/2033604>`_
for more details.