Fix _list_view function for count

When doing `manila list --count True` without shares, the user gets
an error. This happens because _list_view do not handle count
properly for 0 shares. This patch-set adds a fix for this case.

Change-Id: Ic6b45260ae39da9ec2c29d05c76d85be1e20635d
Closes-bug: #1822815
This commit is contained in:
SolKuczala 2019-07-31 20:47:36 +00:00 committed by Victoria Martinez de la Cruz
parent 7698687e85
commit 60254a4fd2
3 changed files with 44 additions and 1 deletions

View File

@ -178,7 +178,7 @@ class ViewBuilder(common.ViewBuilder):
self._collection_name)
shares_dict = dict(shares=shares_list)
if count:
if count is not None:
shares_dict['count'] = count
if shares_links:
shares_dict['shares_links'] = shares_links

View File

@ -1634,6 +1634,45 @@ class ShareAPITest(test.TestCase):
api_version.APIVersionRequest('2.42')):
self.assertEqual(3, result['count'])
@ddt.data({'use_admin_context': True, 'version': '2.42'},
{'use_admin_context': False, 'version': '2.42'})
@ddt.unpack
def test_share_list_summary_with_search_opt_count_0(self,
use_admin_context,
version):
search_opts = {
'sort_key': 'fake_sort_key',
'sort_dir': 'fake_sort_dir',
'with_count': 'true'
}
if use_admin_context:
search_opts['host'] = 'fake_host'
# fake_key should be filtered
url = '/shares?fake_key=fake_value'
for k, v in search_opts.items():
url = url + '&' + k + '=' + v
req = fakes.HTTPRequest.blank(url, version=version,
use_admin_context=use_admin_context)
self.mock_object(share_api.API, 'get_all',
mock.Mock(return_value=[]))
result = self.controller.index(req)
search_opts_expected = {}
if use_admin_context:
search_opts_expected.update({'fake_key': 'fake_value'})
search_opts_expected['host'] = search_opts['host']
share_api.API.get_all.assert_called_once_with(
req.environ['manila.context'],
sort_key=search_opts['sort_key'],
sort_dir=search_opts['sort_dir'],
search_opts=search_opts_expected,
)
self.assertEqual(0, len(result['shares']))
self.assertEqual(0, result['count'])
def test_share_list_summary(self):
self.mock_object(share_api.API, 'get_all',
stubs.stub_share_get_all_by_project)

View File

@ -0,0 +1,4 @@
fixes:
- Launchpad bug `1822815 <https://bugs.launchpad.net/manila/+bug/1822815>`_
has been fixed. The user no longer gets an error if the list command has
no rows when executing `manila list --count True`.