Merge "Make V2.1 servers filtering (--tenant-id) same as V2"

This commit is contained in:
Jenkins 2015-01-20 16:04:13 +00:00 committed by Gerrit Code Review
commit 7d0bbaf4ca
2 changed files with 9 additions and 24 deletions

View File

@ -318,15 +318,21 @@ class ServersController(wsgi.Controller):
# disabled. Note that the tenant_id parameter is filtered out
# by remove_invalid_options above unless the requestor is an
# admin.
if 'tenant_id' in search_opts and 'all_tenants' not in search_opts:
# TODO(gmann): 'all_tenants' flag should not be required while
# searching with 'tenant_id'. Ref bug# 1185290
# +microversions to achieve above mentioned behavior by
# uncommenting below code.
# if 'tenant_id' in search_opts and 'all_tenants' not in search_opts:
# We do not need to add the all_tenants flag if the tenant
# id associated with the token is the tenant id
# specified. This is done so a request that does not need
# the all_tenants flag does not fail because of lack of
# policy permission for compute:get_all_tenants when it
# doesn't actually need it.
if context.project_id != search_opts.get('tenant_id'):
search_opts['all_tenants'] = 1
# if context.project_id != search_opts.get('tenant_id'):
# search_opts['all_tenants'] = 1
# If all tenants is passed with 0 or false as the value
# then remove it from the search options. Nothing passed as

View File

@ -737,27 +737,6 @@ class ServersControllerTest(ControllerTest):
servers = self.controller.index(req)['servers']
self.assertEqual(len(servers), 1)
def test_tenant_id_filter_implies_all_tenants(self):
def fake_get_all(context, filters=None, limit=None, marker=None,
columns_to_join=None, use_slave=False,
expected_attrs=None, sort_keys=None, sort_dirs=None):
self.assertNotEqual(filters, None)
# The project_id assertion checks that the project_id
# filter is set to that specified in the request url and
# not that of the context, verifying that the all_tenants
# flag was enabled
self.assertEqual(filters['project_id'], 'newfake')
self.assertFalse(filters.get('tenant_id'))
return [fakes.stub_instance(100)]
self.stubs.Set(db, 'instance_get_all_by_filters_sort',
fake_get_all)
req = fakes.HTTPRequestV3.blank('/servers?tenant_id=newfake',
use_admin_context=True)
servers = self.controller.index(req)['servers']
self.assertEqual(len(servers), 1)
def test_all_tenants_param_normal(self):
def fake_get_all(context, filters=None, limit=None, marker=None,
columns_to_join=None, use_slave=False,