Fix share can not be found by name in admin context

Currently, when using admin context to execute 'manila
show <share-name>' to show a share detail which is not
owned by admin, it always fails with 'No share with a
name or ID of <share-name> exists'. This patch will fix
it.

Change-Id: I96339778fa69c379863078250d5dfa7172f2c1b2
Closes-Bug: #1721787
(cherry picked from commit b9ebff14ca)
This commit is contained in:
Jiao Pengju 2017-11-23 14:31:33 +08:00 committed by Tom Barron
parent 7b88b1dce9
commit e657bfe743
3 changed files with 10 additions and 3 deletions

View File

@ -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):

View File

@ -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})

View File

@ -332,7 +332,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:
@ -378,7 +378,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):