From b9ebff14caddf42b629ba00bc9ea52ac2b39117b Mon Sep 17 00:00:00 2001 From: Jiao Pengju Date: Thu, 23 Nov 2017 14:31:33 +0800 Subject: [PATCH] Fix share can not be found by name in admin context Currently, when using admin context to execute 'manila show ' to show a share detail which is not owned by admin, it always fails with 'No share with a name or ID of exists'. This patch will fix it. Change-Id: I96339778fa69c379863078250d5dfa7172f2c1b2 Closes-Bug: #1721787 --- manilaclient/base.py | 3 ++- manilaclient/tests/unit/test_base.py | 6 ++++++ manilaclient/tests/unit/v2/test_shell.py | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/manilaclient/base.py b/manilaclient/base.py index 0964ea31a..f7bb498de 100644 --- a/manilaclient/base.py +++ b/manilaclient/base.py @@ -208,7 +208,8 @@ class ManagerWithFind(Manager): found = [] searches = list(kwargs.items()) - for obj in self.list(): + search_opts = {'all_tenants': 1} + for obj in self.list(search_opts=search_opts): try: if all(getattr(obj, attr) == value for (attr, value) in searches): diff --git a/manilaclient/tests/unit/test_base.py b/manilaclient/tests/unit/test_base.py index 45b421b0e..2ec701c09 100644 --- a/manilaclient/tests/unit/test_base.py +++ b/manilaclient/tests/unit/test_base.py @@ -9,6 +9,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from mock import mock from manilaclient.common.apiclient import base as common_base from manilaclient import exceptions @@ -60,3 +61,8 @@ class BaseTest(utils.TestCase): self.assertRaises(exceptions.NotFound, cs.shares.find, vegetable='carrot') + + def test_findall_with_all_tenants(self): + cs.shares.list = mock.Mock(return_value=[]) + cs.shares.findall() + cs.shares.list.assert_called_once_with(search_opts={'all_tenants': 1}) diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 517ba3134..9b2abc488 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -349,7 +349,7 @@ class ShellTest(test_utils.TestCase): self.run_command, 'list --snapshot not_found_expected', ) - self.assert_called('GET', '/snapshots/detail') + self.assert_called('GET', '/snapshots/detail?all_tenants=1') def test_list_filter_by_host(self): for separator in self.separators: @@ -395,7 +395,7 @@ class ShellTest(test_utils.TestCase): self.run_command, 'list --share-network not_found_expected', ) - self.assert_called('GET', '/share-networks/detail') + self.assert_called('GET', '/share-networks/detail?all_tenants=1') @mock.patch.object(cliutils, 'print_list', mock.Mock()) def test_share_instance_list(self):