Updated context to use project_id

Fixed a bunch of deprecated warnings from oslo.context.

* Use project_id instead of tenant.
* Use user_id, domain_id etc.

Change-Id: I6e8affbabeca4162f11fb4ba47ffa2e960103ccd
This commit is contained in:
Erik Olof Gunnar Andersson 2019-06-02 13:18:49 -07:00
parent fc5700bd61
commit 03b390dee5
24 changed files with 252 additions and 238 deletions

View File

@ -140,10 +140,11 @@ class KeystoneContextMiddleware(ContextMiddleware):
self.make_context(
request,
auth_token=headers.get('X-Auth-Token'),
user=headers.get('X-User-ID'),
tenant=tenant_id,
user_id=headers.get('X-User-ID'),
project_id=tenant_id,
roles=roles,
service_catalog=catalog)
service_catalog=catalog
)
except exceptions.Forbidden:
return flask.Response(status=403)
@ -160,8 +161,8 @@ class NoAuthContextMiddleware(ContextMiddleware):
self.make_context(
request,
auth_token=headers.get('X-Auth-Token', None),
user=headers.get('X-Auth-User-ID', 'noauth-user'),
tenant=headers.get('X-Auth-Project-ID', 'noauth-project'),
user_id=headers.get('X-Auth-User-ID', 'noauth-user'),
project_id=headers.get('X-Auth-Project-ID', 'noauth-project'),
roles=headers.get('X-Roles', 'admin').split(',')
)
@ -184,9 +185,10 @@ class TestContextMiddleware(ContextMiddleware):
self.make_context(
request,
user=headers.get('X-Test-User-ID', self.default_user_id),
tenant=headers.get('X-Test-Tenant-ID', self.default_tenant_id),
all_tenants=all_tenants)
user_id=headers.get('X-Test-User-ID', self.default_user_id),
project_id=headers.get('X-Test-Tenant-ID', self.default_tenant_id),
all_tenants=all_tenants
)
class MaintenanceMiddleware(base.Middleware):

View File

@ -31,7 +31,7 @@ class QuotasController(rest.RestController):
def get_all(self):
context = pecan.request.environ['context']
quotas = self.central_api.get_quotas(context, context.tenant)
quotas = self.central_api.get_quotas(context, context.project_id)
quotas = QuotaList.from_dict(quotas)

View File

@ -31,7 +31,7 @@ class ZoneExportController(rest.RestController):
@utils.validate_uuid('export_id')
def get_all(self, export_id):
context = pecan.request.environ['context']
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('zone_export', context, target)
export = self.central_api.get_zone_export(context, export_id)

View File

@ -44,7 +44,7 @@ class InfobloxBackend(base.Backend):
def create_zone(self, context, zone):
LOG.info('Create Zone %r', zone)
dns_net_view = self.infoblox.get_dns_view(context.tenant)
dns_net_view = self.infoblox.get_dns_view(context.project_id)
self.infoblox.create_zone_auth(
fqdn=zone['name'][0:-1],
dns_view=dns_net_view

View File

@ -127,7 +127,7 @@ class PowerDNSBackend(base.Backend):
'name': zone['name'].rstrip('.'),
'master': ','.join(masters),
'type': 'SLAVE',
'account': context.tenant
'account': context.project_id
}
self._create(sess, tables.domains, domain_values)

View File

@ -653,7 +653,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def get_absolute_limits(self, context):
# NOTE(Kiall): Currently, we only have quota based limits..
return self.quota.get_quotas(context, context.tenant)
return self.quota.get_quotas(context, context.project_id)
# Quota Methods
@rpc.expected_exceptions()
@ -661,7 +661,7 @@ class Service(service.RPCService, service.Service):
target = {'tenant_id': tenant_id}
policy.check('get_quotas', context, target)
if tenant_id != context.tenant and not context.all_tenants:
if tenant_id != context.project_id and not context.all_tenants:
raise exceptions.Forbidden()
return self.quota.get_quotas(context, tenant_id)
@ -683,7 +683,7 @@ class Service(service.RPCService, service.Service):
}
policy.check('set_quota', context, target)
if tenant_id != context.tenant and not context.all_tenants:
if tenant_id != context.project_id and not context.all_tenants:
raise exceptions.Forbidden()
return self.quota.set_quota(context, tenant_id, resource, hard_limit)
@ -853,7 +853,7 @@ class Service(service.RPCService, service.Service):
"""
# Default to creating in the current users tenant
zone.tenant_id = zone.tenant_id or context.tenant
zone.tenant_id = zone.tenant_id or context.project_id
target = {
'tenant_id': zone.tenant_id,
@ -1008,7 +1008,7 @@ class Service(service.RPCService, service.Service):
sort_key=None, sort_dir=None):
"""List existing zones including the ones flagged for deletion.
"""
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_zones', context, target)
return self.storage.find_zones(context, criterion, marker, limit,
@ -1016,7 +1016,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_zone(self, context, criterion=None):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_zone', context, target)
return self.storage.find_zone(context, criterion)
@ -1375,7 +1375,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_recordsets(self, context, criterion=None, marker=None, limit=None,
sort_key=None, sort_dir=None, force_index=False):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_recordsets', context, target)
recordsets = self.storage.find_recordsets(context, criterion, marker,
@ -1386,7 +1386,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_recordset(self, context, criterion=None):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_recordset', context, target)
recordset = self.storage.find_recordset(context, criterion)
@ -1635,7 +1635,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_records(self, context, criterion=None, marker=None, limit=None,
sort_key=None, sort_dir=None):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_records', context, target)
return self.storage.find_records(context, criterion, marker, limit,
@ -1643,7 +1643,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_record(self, context, criterion=None):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_record', context, target)
return self.storage.find_record(context, criterion)
@ -1877,7 +1877,7 @@ class Service(service.RPCService, service.Service):
Returns a list of tuples with FloatingIPs and it's Record.
"""
tenant_id = tenant_id or context.tenant
tenant_id = tenant_id or context.project_id
elevated_context = context.elevated(all_tenants=True,
edit_managed_records=True)
@ -1995,7 +1995,7 @@ class Service(service.RPCService, service.Service):
def _get_floatingip(self, context, region, floatingip_id, fips):
if (region, floatingip_id) not in fips:
msg = 'FloatingIP %s in %s is not associated for tenant "%s"' % \
(floatingip_id, region, context.tenant)
(floatingip_id, region, context.project_id)
raise exceptions.NotFound(msg)
return fips[region, floatingip_id]
@ -2127,7 +2127,7 @@ class Service(service.RPCService, service.Service):
'managed_resource_id': floatingip_id,
'managed_resource_region': region,
'managed_resource_type': 'ptr:floatingip',
'managed_tenant_id': context.tenant
'managed_tenant_id': context.project_id
}
record = self.create_record(
@ -2153,7 +2153,7 @@ class Service(service.RPCService, service.Service):
edit_managed_records=True)
criterion = {
'managed_resource_id': floatingip_id,
'managed_tenant_id': context.tenant
'managed_tenant_id': context.project_id
}
try:
@ -2251,7 +2251,7 @@ class Service(service.RPCService, service.Service):
def create_pool(self, context, pool):
# Verify that there is a tenant_id
if pool.tenant_id is None:
pool.tenant_id = context.tenant
pool.tenant_id = context.project_id
policy.check('create_pool', context)
@ -2514,7 +2514,7 @@ class Service(service.RPCService, service.Service):
zone_transfer_request.key = self._transfer_key_generator()
if zone_transfer_request.tenant_id is None:
zone_transfer_request.tenant_id = context.tenant
zone_transfer_request.tenant_id = context.project_id
created_zone_transfer_request = \
self.storage.create_zone_transfer_request(
@ -2556,7 +2556,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_zone_transfer_request(self, context, criterion):
target = {
'tenant_id': context.tenant,
'tenant_id': context.project_id,
}
policy.check('find_zone_transfer_request', context, target)
return self.storage.find_zone_transfer_requests(context, criterion)
@ -2620,7 +2620,7 @@ class Service(service.RPCService, service.Service):
policy.check('create_zone_transfer_accept', context, target)
if zone_transfer_accept.tenant_id is None:
zone_transfer_accept.tenant_id = context.tenant
zone_transfer_accept.tenant_id = context.project_id
created_zone_transfer_accept = \
self.storage.create_zone_transfer_accept(
@ -2717,14 +2717,14 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
@notification('dns.zone_import.create')
def create_zone_import(self, context, request_body):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('create_zone_import', context, target)
values = {
'status': 'PENDING',
'message': None,
'zone_id': None,
'tenant_id': context.tenant,
'tenant_id': context.project_id,
'task_type': 'IMPORT'
}
zone_import = objects.ZoneImport(**values)
@ -2813,7 +2813,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_zone_imports(self, context, criterion=None, marker=None,
limit=None, sort_key=None, sort_dir=None):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_zone_imports', context, target)
criterion = {
@ -2824,7 +2824,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def get_zone_import(self, context, zone_import_id):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('get_zone_import', context, target)
return self.storage.get_zone_import(context, zone_import_id)
@ -2844,7 +2844,7 @@ class Service(service.RPCService, service.Service):
def delete_zone_import(self, context, zone_import_id):
target = {
'zone_import_id': zone_import_id,
'tenant_id': context.tenant
'tenant_id': context.project_id
}
policy.check('delete_zone_import', context, target)
@ -2859,14 +2859,14 @@ class Service(service.RPCService, service.Service):
# Try getting the zone to ensure it exists
zone = self.storage.get_zone(context, zone_id)
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('create_zone_export', context, target)
values = {
'status': 'PENDING',
'message': None,
'zone_id': zone_id,
'tenant_id': context.tenant,
'tenant_id': context.project_id,
'task_type': 'EXPORT'
}
zone_export = objects.ZoneExport(**values)
@ -2886,7 +2886,7 @@ class Service(service.RPCService, service.Service):
if synchronous:
try:
self.quota.limit_check(
context, context.tenant, api_export_size=count)
context, context.project_id, api_export_size=count)
except exceptions.OverQuota:
LOG.debug('Zone Export too large to perform synchronously')
export.status = 'ERROR'
@ -2913,7 +2913,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def find_zone_exports(self, context, criterion=None, marker=None,
limit=None, sort_key=None, sort_dir=None):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('find_zone_exports', context, target)
criterion = {
@ -2924,7 +2924,7 @@ class Service(service.RPCService, service.Service):
@rpc.expected_exceptions()
def get_zone_export(self, context, zone_export_id):
target = {'tenant_id': context.tenant}
target = {'tenant_id': context.project_id}
policy.check('get_zone_export', context, target)
return self.storage.get_zone_export(context, zone_export_id)
@ -2945,7 +2945,7 @@ class Service(service.RPCService, service.Service):
def delete_zone_export(self, context, zone_export_id):
target = {
'zone_export_id': zone_export_id,
'tenant_id': context.tenant
'tenant_id': context.project_id
}
policy.check('delete_zone_export', context, target)

View File

@ -13,11 +13,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import itertools
import copy
import itertools
from keystoneauth1.access import service_catalog as ksa_service_catalog
from keystoneauth1 import plugin
from keystoneauth1.access import service_catalog as ksa_service_catalog
from oslo_context import context
from oslo_log import log as logging
@ -43,7 +43,6 @@ class DesignateContext(context.RequestContext):
tsigkey_id=None, original_tenant=None,
edit_managed_records=False, hide_counts=False,
client_addr=None, user_auth_plugin=None, **kwargs):
super(DesignateContext, self).__init__(**kwargs)
self.user_auth_plugin = user_auth_plugin
@ -69,17 +68,19 @@ class DesignateContext(context.RequestContext):
# Override the user_identity field to account for TSIG. When a TSIG key
# is used as authentication e.g. via MiniDNS, it will act as a form
# of "user",
user = self.user or '-'
user = self.user_id or '-'
if self.tsigkey_id and not self.user:
if self.tsigkey_id and not self.user_id:
user = 'TSIG:%s' % self.tsigkey_id
user_idt = (
self.user_idt_format.format(user=user,
tenant=self.tenant or '-',
domain=self.domain or '-',
user_domain=self.user_domain or '-',
p_domain=self.project_domain or '-'))
self.user_idt_format.format(
user=user,
tenant=self.project_id or '-',
domain=self.domain_id or '-',
user_domain=self.user_domain_id or '-',
p_domain=self.project_domain_id or '-')
)
# Update the dict with Designate specific extensions and overrides
d.update({
@ -123,7 +124,7 @@ class DesignateContext(context.RequestContext):
policy.check('use_sudo', self)
LOG.info('Accepted sudo from user %(user)s to tenant %(tenant)s',
{'user': self.user, 'tenant': tenant})
{'user': self.user_id, 'tenant': tenant})
self.original_tenant = self.tenant
self.tenant = tenant

View File

@ -156,10 +156,12 @@ class SQLAlchemy(object):
# so I had to force flake8 to skip the check
if include_null_tenant:
query = query.where(or_(
table.c.tenant_id == context.tenant,
table.c.tenant_id == context.project_id,
table.c.tenant_id == None)) # NOQA
else:
query = query.where(table.c.tenant_id == context.tenant)
query = query.where(
table.c.tenant_id == context.project_id
)
return query

View File

@ -1489,8 +1489,8 @@ class SQLAlchemyStorage(sqlalchemy_base.SQLAlchemy, storage_base.Storage):
if not context.all_tenants:
query = query.where(or_(
table.c.tenant_id == context.tenant,
table.c.target_tenant_id == context.tenant))
table.c.tenant_id == context.project_id,
table.c.target_tenant_id == context.project_id))
return self._find(
context, table, objects.ZoneTransferRequest,

View File

@ -468,8 +468,8 @@ class TestCase(base.BaseTestCase):
def get_admin_context(self):
return DesignateContext.get_admin_context(
tenant=utils.generate_uuid(),
user=utils.generate_uuid())
project_id=utils.generate_uuid(),
user_id=utils.generate_uuid())
# Fixture methods
def get_quota_fixture(self, fixture=0, values=None):
@ -692,7 +692,7 @@ class TestCase(base.BaseTestCase):
fixture=fixture, values=kwargs)
if 'tenant_id' not in values:
values['tenant_id'] = context.tenant
values['tenant_id'] = context.project_id
return self.central_service.create_zone(
context, objects.Zone.from_dict(values))
@ -739,7 +739,7 @@ class TestCase(base.BaseTestCase):
values = self.get_pool_fixture(fixture=fixture, values=kwargs)
if 'tenant_id' not in values:
values['tenant_id'] = context.tenant
values['tenant_id'] = context.project_id
return self.central_service.create_pool(
context, objects.Pool.from_dict(values))
@ -778,7 +778,7 @@ class TestCase(base.BaseTestCase):
values = {}
if 'tenant_id' not in values:
values['tenant_id'] = context.tenant
values['tenant_id'] = context.project_id
if 'zone_transfer_request_id' not in values:
values['zone_transfer_request_id'] = zone_transfer_request.id
@ -797,7 +797,7 @@ class TestCase(base.BaseTestCase):
fixture = kwargs.pop('fixture', 0)
zone_import = self.get_zone_import_fixture(fixture=fixture,
values=kwargs)
values=kwargs)
return self.storage.create_zone_import(
context, objects.ZoneImport.from_dict(zone_import))
@ -807,7 +807,7 @@ class TestCase(base.BaseTestCase):
fixture = kwargs.pop('fixture', 0)
zone_export = self.get_zone_export_fixture(fixture=fixture,
values=kwargs)
values=kwargs)
return self.storage.create_zone_export(
context, objects.ZoneExport.from_dict(zone_export))

View File

@ -51,8 +51,8 @@ class AdminApiTestCase(ApiTestCase):
# Inject the TestContext middleware
self.app = middleware.TestContextMiddleware(
self.app, self.admin_context.tenant,
self.admin_context.tenant)
self.app, self.admin_context.project_id,
self.admin_context.project_id)
# Obtain a test client
self.client = TestApp(self.app)

View File

@ -31,9 +31,9 @@ class AdminApiQuotasTest(AdminApiTestCase):
self.policy({'get_quotas': '@'})
context = self.get_admin_context()
response = self.client.get('/quotas/%s' % context.tenant,
response = self.client.get('/quotas/%s' % context.project_id,
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
@ -52,11 +52,11 @@ class AdminApiQuotasTest(AdminApiTestCase):
def test_patch_quotas(self):
self.policy({'set_quotas': '@'})
context = self.get_context(tenant='a', is_admin=True)
context = self.get_context(project_id='a', is_admin=True)
response = self.client.get('/quotas/%s' % 'a',
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
@ -69,12 +69,12 @@ class AdminApiQuotasTest(AdminApiTestCase):
response = self.client.patch_json('/quotas/%s' % 'a', body,
status=200,
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
self.assertEqual(200, response.status_int)
response = self.client.get('/quotas/%s' % 'a',
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
new_count = response.json['quota']['zones']
@ -82,32 +82,36 @@ class AdminApiQuotasTest(AdminApiTestCase):
def test_patch_quotas_validation(self):
self.policy({'set_quotas': '@'})
context = self.get_context(tenant='a', is_admin=True)
context = self.get_context(project_id='a', is_admin=True)
url = '/quotas/%s' % 'a'
# Test a negative number for zones
body = {'quota': {"zones": -1337}}
# Ensure it fails with a 400
self._assert_exception('invalid_object', 400, self.client.patch_json,
url, body,
headers={'X-Test-Tenant-Id': context.tenant})
self._assert_exception(
'invalid_object', 400, self.client.patch_json,
url, body,
headers={'X-Test-Tenant-Id': context.project_id}
)
# Test a number > maximum (2147483647) for zones
body = {'quota': {"zones": 2147483648}}
# Ensure it fails with a 400
self._assert_exception('invalid_object', 400, self.client.patch_json,
url, body,
headers={'X-Test-Tenant-Id': context.tenant})
self._assert_exception(
'invalid_object', 400, self.client.patch_json,
url, body,
headers={'X-Test-Tenant-Id': context.project_id}
)
def test_reset_quotas(self):
self.policy({'reset_quotas': '@'})
context = self.get_context(tenant='a', is_admin=True)
context = self.get_context(project_id='a', is_admin=True)
response = self.client.get('/quotas/%s' % 'a',
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
@ -120,12 +124,12 @@ class AdminApiQuotasTest(AdminApiTestCase):
response = self.client.patch_json('/quotas/%s' % 'a', body,
status=200,
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
self.assertEqual(200, response.status_int)
response = self.client.get('/quotas/%s' % 'a',
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
new_count = response.json['quota']['zones']
@ -133,10 +137,10 @@ class AdminApiQuotasTest(AdminApiTestCase):
response = self.client.delete('/quotas/%s' % 'a',
headers={'X-Test-Tenant-Id':
context.tenant}, status=204)
context.project_id}, status=204)
response = self.client.get('/quotas/%s' % 'a',
headers={'X-Test-Tenant-Id':
context.tenant})
context.project_id})
newest_count = response.json['quota']['zones']
self.assertNotEqual(new_count, newest_count)

View File

@ -154,9 +154,9 @@ class AdminApiReportsTest(AdminApiTestCase):
def test_get_tenant(self):
self.policy({'find_tenants': '@'})
zone = self.create_zone()
tenant = zone.tenant_id
project_id = zone.tenant_id
response = self.client.get('/reports/tenants/%s' % tenant)
response = self.client.get('/reports/tenants/%s' % project_id)
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)

View File

@ -64,8 +64,8 @@ class KeystoneContextMiddlewareTest(ApiTestCase):
self.assertFalse(context.is_admin)
self.assertEqual('AuthToken', context.auth_token)
self.assertEqual('UserID', context.user)
self.assertEqual('TenantID', context.tenant)
self.assertEqual('UserID', context.user_id)
self.assertEqual('TenantID', context.project_id)
self.assertEqual(['admin', 'Member'], context.roles)
def test_process_request_invalid_keystone_token(self):
@ -118,8 +118,8 @@ class NoAuthContextMiddlewareTest(ApiTestCase):
ctxt = request.environ['context']
self.assertIsNone(ctxt.auth_token)
self.assertEqual('noauth-user', ctxt.user)
self.assertEqual('noauth-project', ctxt.tenant)
self.assertEqual('noauth-user', ctxt.user_id)
self.assertEqual('noauth-project', ctxt.project_id)
self.assertEqual(['admin'], ctxt.roles)

View File

@ -54,8 +54,8 @@ class ApiV2TestCase(ApiTestCase):
# Inject the TestContext middleware
self.app = middleware.TestContextMiddleware(
self.app, self.admin_context.tenant,
self.admin_context.tenant)
self.app, self.admin_context.project_id,
self.admin_context.project_id)
# Obtain a test client
self.client = TestApp(self.app)

View File

@ -23,13 +23,13 @@ NOTE: Record invalidation is tested in Central tests
class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
def test_get_floatingip_no_record(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
response = self.client.get(
'/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']]),
headers={'X-Test-Tenant-Id': context.tenant})
headers={'X-Test-Tenant-Id': context.project_id})
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
@ -47,17 +47,17 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
def test_get_floatingip_with_record(self):
fixture = self.get_ptr_fixture()
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(
context.tenant)
context.project_id)
self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)
response = self.client.get(
'/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']]),
headers={'X-Test-Tenant-Id': context.tenant})
headers={'X-Test-Tenant-Id': context.project_id})
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
@ -90,13 +90,13 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
self.assertEqual(0, len(response.json['floatingips']))
def test_list_floatingip_no_record(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
response = self.client.get(
'/reverse/floatingips',
headers={'X-Test-Tenant-Id': context.tenant})
headers={'X-Test-Tenant-Id': context.project_id})
self.assertIn('floatingips', response.json)
self.assertIn('links', response.json)
@ -114,16 +114,16 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
def test_list_floatingip_with_record(self):
fixture = self.get_ptr_fixture()
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)
response = self.client.get(
'/reverse/floatingips',
headers={'X-Test-Tenant-Id': context.tenant})
headers={'X-Test-Tenant-Id': context.project_id})
self.assertIn('floatingips', response.json)
self.assertIn('links', response.json)
@ -187,11 +187,11 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
def test_unset_floatingip(self):
fixture = self.get_ptr_fixture()
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
elevated_context = context.elevated()
elevated_context.all_tenants = True
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
# Unsetting via "None"
self.central_service.update_floatingip(
@ -199,7 +199,7 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
criterion = {
'managed_resource_id': fip['id'],
'managed_tenant_id': context.tenant
'managed_tenant_id': context.project_id
}
zone_id = self.central_service.find_record(
elevated_context, criterion=criterion).zone_id
@ -214,7 +214,7 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
response = self.client.patch_json(
'/reverse/floatingips/%s' % ":".join([fip['region'], fip['id']]),
{'ptrdname': None},
headers={'X-Test-Tenant-Id': context.tenant})
headers={'X-Test-Tenant-Id': context.project_id})
self.assertIsNone(response.json)
self.assertEqual(202, response.status_int)
@ -230,9 +230,9 @@ class ApiV2ReverseFloatingIPTest(ApiV2TestCase):
def test_unset_floatingip_not_allocated(self):
fixture = self.get_ptr_fixture()
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)

View File

@ -41,8 +41,8 @@ class APIV2ZoneImportExportTest(ApiV2TestCase):
adminapp = middleware.FaultWrapperMiddleware(adminapp)
# Inject the TestContext middleware
adminapp = middleware.TestContextMiddleware(
adminapp, self.admin_context.tenant,
self.admin_context.tenant)
adminapp, self.admin_context.project_id,
self.admin_context.project_id)
# Obtain a test client
self.adminclient = TestApp(adminapp)

View File

@ -22,8 +22,8 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
super(ApiV2ZoneTransfersTest, self).setUp()
self.zone = self.create_zone()
self.tenant_1_context = self.get_context(tenant=1)
self.tenant_2_context = self.get_context(tenant=2)
self.tenant_1_context = self.get_context(project_id=1)
self.tenant_2_context = self.get_context(project_id=2)
self.policy({'admin': '@'})
def test_create_zone_transfer_request(self):
@ -54,7 +54,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_create_zone_transfer_request_scoped(self):
response = self.client.post_json(
'/zones/%s/tasks/transfer_requests' % (self.zone.id),
{'target_project_id': str(self.tenant_1_context.tenant)})
{'target_project_id': str(self.tenant_1_context.project_id)})
# Check the headers are what we expect
self.assertEqual(201, response.status_int)
@ -69,7 +69,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
self.assertIn('created_at', response.json)
self.assertEqual('ACTIVE', response.json['status'])
self.assertEqual(
str(self.tenant_1_context.tenant),
str(self.tenant_1_context.project_id),
response.json['target_project_id'])
self.assertEqual(
self.zone.id,

View File

@ -417,8 +417,8 @@ class CentralServiceTest(CentralTestCase):
admin_context = self.get_admin_context()
admin_context.all_tenants = True
tenant_one_context = self.get_context(tenant=1)
tenant_two_context = self.get_context(tenant=2)
tenant_one_context = self.get_context(project_id=1)
tenant_two_context = self.get_context(project_id=2)
# in the beginning, there should be nothing
tenants = self.central_service.count_tenants(admin_context)
@ -588,7 +588,7 @@ class CentralServiceTest(CentralTestCase):
context = self.get_admin_context()
# Explicitly set a tenant_id
context.tenant = '1'
context.project_id = '1'
# Create the Parent Zone using fixture 0
parent_zone = self.create_zone(fixture=0, context=context)
@ -596,7 +596,7 @@ class CentralServiceTest(CentralTestCase):
context = self.get_admin_context()
# Explicitly use a different tenant_id
context.tenant = '2'
context.project_id = '2'
# Prepare values for the subzone using fixture 1 as a base
values = self.get_zone_fixture(fixture=1)
@ -613,7 +613,7 @@ class CentralServiceTest(CentralTestCase):
context = self.get_admin_context()
# Explicitly set a tenant_id
context.tenant = '1'
context.project_id = '1'
# Set up zone and subzone values
zone_values = self.get_zone_fixture(fixture=1)
@ -629,7 +629,7 @@ class CentralServiceTest(CentralTestCase):
context = self.get_admin_context()
# Explicitly use a different tenant_id
context.tenant = '2'
context.project_id = '2'
# Attempt to create the zone
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
@ -792,8 +792,8 @@ class CentralServiceTest(CentralTestCase):
admin_context = self.get_admin_context()
admin_context.all_tenants = True
tenant_one_context = self.get_context(tenant=1)
tenant_two_context = self.get_context(tenant=2)
tenant_one_context = self.get_context(project_id=1)
tenant_two_context = self.get_context(project_id=2)
# Ensure we have no zones to start with.
zones = self.central_service.find_zones(admin_context)
@ -807,12 +807,12 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(1, len(zones))
self.assertEqual(zone['name'], zones[0]['name'])
# Ensure tenant=1 can retrieve the newly created zone
# Ensure project_id=1 can retrieve the newly created zone
zones = self.central_service.find_zones(tenant_one_context)
self.assertEqual(1, len(zones))
self.assertEqual(zone['name'], zones[0]['name'])
# Ensure tenant=2 can NOT retrieve the newly created zone
# Ensure project_id=2 can NOT retrieve the newly created zone
zones = self.central_service.find_zones(tenant_two_context)
self.assertEqual(0, len(zones))
@ -2383,9 +2383,9 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(exceptions.Forbidden, exc.exc_info[0])
def test_get_floatingip_no_record(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
fip_ptr = self.central_service.get_floatingip(
context, fip['region'], fip['id'])
@ -2396,10 +2396,10 @@ class CentralServiceTest(CentralTestCase):
self.assertIsNone(fip_ptr['ptrdname'])
def test_get_floatingip_dual_no_record(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.tenant)
self.network_api.fake.allocate_floatingip(context.project_id)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
fip_ptr = self.central_service.get_floatingip(
context, fip['region'], fip['id'])
@ -2410,11 +2410,11 @@ class CentralServiceTest(CentralTestCase):
self.assertIsNone(fip_ptr['ptrdname'])
def test_get_floatingip_with_record(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fixture = self.get_ptr_fixture()
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
expected = self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)
@ -2426,9 +2426,9 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(expected, actual)
def test_get_floatingip_not_allocated(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
self.network_api.fake.deallocate_floatingip(fip['id'])
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
@ -2438,23 +2438,23 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(exceptions.NotFound, exc.exc_info[0])
def test_get_floatingip_deallocated_and_invalidate(self):
context_a = self.get_context(tenant='a')
context_a = self.get_context(project_id='a')
elevated_a = context_a.elevated()
elevated_a.all_tenants = True
context_b = self.get_context(tenant='b')
context_b = self.get_context(project_id='b')
fixture = self.get_ptr_fixture()
# First allocate and create a FIP as tenant a
fip = self.network_api.fake.allocate_floatingip(context_a.tenant)
fip = self.network_api.fake.allocate_floatingip(context_a.project_id)
self.central_service.update_floatingip(
context_a, fip['region'], fip['id'], fixture)
criterion = {
'managed_resource_id': fip['id'],
'managed_tenant_id': context_a.tenant}
'managed_tenant_id': context_a.project_id}
zone_id = self.central_service.find_record(
elevated_a, criterion).zone_id
@ -2477,7 +2477,7 @@ class CentralServiceTest(CentralTestCase):
# Now give the fip id to tenant 'b' and see that it get's deleted
self.network_api.fake.allocate_floatingip(
context_b.tenant, fip['id'])
context_b.project_id, fip['id'])
# There should be a fip returned with ptrdname of None
fip_ptr = self.central_service.get_floatingip(
@ -2499,16 +2499,16 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
def test_list_floatingips_no_allocations(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fips = self.central_service.list_floatingips(context)
self.assertEqual(0, len(fips))
def test_list_floatingips_no_record(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
fips = self.central_service.list_floatingips(context)
@ -2520,11 +2520,11 @@ class CentralServiceTest(CentralTestCase):
self.assertIsNone(fips[0]['description'])
def test_list_floatingips_with_record(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fixture = self.get_ptr_fixture()
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
fip_ptr = self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)
@ -2539,23 +2539,23 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(fip_ptr['description'], fips[0]['description'])
def test_list_floatingips_deallocated_and_invalidate(self):
context_a = self.get_context(tenant='a')
context_a = self.get_context(project_id='a')
elevated_a = context_a.elevated()
elevated_a.all_tenants = True
context_b = self.get_context(tenant='b')
context_b = self.get_context(project_id='b')
fixture = self.get_ptr_fixture()
# First allocate and create a FIP as tenant a
fip = self.network_api.fake.allocate_floatingip(context_a.tenant)
fip = self.network_api.fake.allocate_floatingip(context_a.project_id)
self.central_service.update_floatingip(
context_a, fip['region'], fip['id'], fixture)
criterion = {
'managed_resource_id': fip['id'],
'managed_tenant_id': context_a.tenant}
'managed_tenant_id': context_a.project_id}
zone_id = self.central_service.find_record(
elevated_a, criterion).zone_id
@ -2575,7 +2575,7 @@ class CentralServiceTest(CentralTestCase):
# Now give the fip id to tenant 'b' and see that it get's deleted
self.network_api.fake.allocate_floatingip(
context_b.tenant, fip['id'])
context_b.project_id, fip['id'])
# There should be a fip returned with ptrdname of None
fips = self.central_service.list_floatingips(context_b)
@ -2597,11 +2597,11 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
def test_set_floatingip(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fixture = self.get_ptr_fixture()
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
fip_ptr = self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)
@ -2612,11 +2612,11 @@ class CentralServiceTest(CentralTestCase):
self.assertIsNotNone(fip_ptr['ttl'])
def test_set_floatingip_no_managed_resource_tenant_id(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fixture = self.get_ptr_fixture()
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)
@ -2633,24 +2633,24 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(tenant_id, zone.tenant_id)
def test_set_floatingip_removes_old_record(self):
context_a = self.get_context(tenant='a')
context_a = self.get_context(project_id='a')
elevated_a = context_a.elevated()
elevated_a.all_tenants = True
context_b = self.get_context(tenant='b')
context_b = self.get_context(project_id='b')
fixture = self.get_ptr_fixture()
# Test that re-setting as tenant 'a' an already set floatingip leaves
# only 1 record
fip = self.network_api.fake.allocate_floatingip(context_a.tenant)
fip = self.network_api.fake.allocate_floatingip(context_a.project_id)
self.central_service.update_floatingip(
context_a, fip['region'], fip['id'], fixture)
criterion = {
'managed_resource_id': fip['id'],
'managed_tenant_id': context_a.tenant}
'managed_tenant_id': context_a.project_id}
zone_id = self.central_service.find_record(
elevated_a, criterion).zone_id
@ -2674,7 +2674,7 @@ class CentralServiceTest(CentralTestCase):
# Now test that tenant b allocating the same fip and setting a ptr
# deletes any records
fip = self.network_api.fake.allocate_floatingip(
context_b.tenant, fip['id'])
context_b.project_id, fip['id'])
self.central_service.update_floatingip(
context_b, fip['region'], fip['id'], fixture)
@ -2691,10 +2691,10 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(1, count)
def test_set_floatingip_not_allocated(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fixture = self.get_ptr_fixture()
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
self.network_api.fake.deallocate_floatingip(fip['id'])
# If one attempts to assign a de-allocated FIP or not-owned it should
@ -2706,11 +2706,11 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(exceptions.NotFound, exc.exc_info[0])
def test_unset_floatingip(self):
context = self.get_context(tenant='a')
context = self.get_context(project_id='a')
fixture = self.get_ptr_fixture()
fip = self.network_api.fake.allocate_floatingip(context.tenant)
fip = self.network_api.fake.allocate_floatingip(context.project_id)
fip_ptr = self.central_service.update_floatingip(
context, fip['region'], fip['id'], fixture)
@ -3322,9 +3322,9 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(zt_request.key, retrived_zt.key)
def test_get_zone_transfer_request_scoped(self):
tenant_1_context = self.get_context(tenant=1)
tenant_2_context = self.get_context(tenant=2)
tenant_3_context = self.get_context(tenant=3)
tenant_1_context = self.get_context(project_id=1)
tenant_2_context = self.get_context(project_id=2)
tenant_3_context = self.get_context(project_id=3)
zone = self.create_zone(context=tenant_1_context)
zt_request = self.create_zone_transfer_request(
zone,
@ -3373,8 +3373,8 @@ class CentralServiceTest(CentralTestCase):
exc.exc_info[0])
def test_create_zone_transfer_accept(self):
tenant_1_context = self.get_context(tenant=1)
tenant_2_context = self.get_context(tenant=2)
tenant_1_context = self.get_context(project_id=1)
tenant_2_context = self.get_context(project_id=2)
admin_context = self.get_admin_context()
admin_context.all_tenants = True
@ -3413,19 +3413,19 @@ class CentralServiceTest(CentralTestCase):
admin_context, zone_transfer_request.id)
self.assertEqual(
str(tenant_2_context.tenant), result['zone'].tenant_id)
str(tenant_2_context.project_id), result['zone'].tenant_id)
self.assertEqual(
str(tenant_2_context.tenant), result['recordset'].tenant_id)
str(tenant_2_context.project_id), result['recordset'].tenant_id)
self.assertEqual(
str(tenant_2_context.tenant), result['record'].tenant_id)
str(tenant_2_context.project_id), result['record'].tenant_id)
self.assertEqual(
'COMPLETE', result['zt_accept'].status)
self.assertEqual(
'COMPLETE', result['zt_request'].status)
def test_create_zone_transfer_accept_scoped(self):
tenant_1_context = self.get_context(tenant=1)
tenant_2_context = self.get_context(tenant=2)
tenant_1_context = self.get_context(project_id=1)
tenant_2_context = self.get_context(project_id=2)
admin_context = self.get_admin_context()
admin_context.all_tenants = True
@ -3466,19 +3466,19 @@ class CentralServiceTest(CentralTestCase):
admin_context, zone_transfer_request.id)
self.assertEqual(
str(tenant_2_context.tenant), result['zone'].tenant_id)
str(tenant_2_context.project_id), result['zone'].tenant_id)
self.assertEqual(
str(tenant_2_context.tenant), result['recordset'].tenant_id)
str(tenant_2_context.project_id), result['recordset'].tenant_id)
self.assertEqual(
str(tenant_2_context.tenant), result['record'].tenant_id)
str(tenant_2_context.project_id), result['record'].tenant_id)
self.assertEqual(
'COMPLETE', result['zt_accept'].status)
self.assertEqual(
'COMPLETE', result['zt_request'].status)
def test_create_zone_transfer_accept_failed_key(self):
tenant_1_context = self.get_context(tenant=1)
tenant_2_context = self.get_context(tenant=2)
tenant_1_context = self.get_context(project_id=1)
tenant_2_context = self.get_context(project_id=2)
admin_context = self.get_admin_context()
admin_context.all_tenants = True
@ -3504,8 +3504,8 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(exceptions.IncorrectZoneTransferKey, exc.exc_info[0])
def test_create_zone_tarnsfer_accept_out_of_tenant_scope(self):
tenant_1_context = self.get_context(tenant=1)
tenant_3_context = self.get_context(tenant=3)
tenant_1_context = self.get_context(project_id=1)
tenant_3_context = self.get_context(project_id=3)
admin_context = self.get_admin_context()
admin_context.all_tenants = True

View File

@ -25,13 +25,13 @@ LOG = logging.getLogger(__name__)
class TestDesignateContext(TestCase):
def test_deepcopy(self):
orig = context.DesignateContext(user='12345', tenant='54321')
orig = context.DesignateContext(user_id='12345', project_id='54321')
copy = orig.deepcopy()
self.assertEqual(orig.to_dict(), copy.to_dict())
def test_elevated(self):
ctxt = context.DesignateContext(user='12345', tenant='54321')
ctxt = context.DesignateContext(user_id='12345', project_id='54321')
admin_ctxt = ctxt.elevated()
self.assertFalse(ctxt.is_admin)
@ -39,7 +39,7 @@ class TestDesignateContext(TestCase):
self.assertEqual(0, len(ctxt.roles))
def test_all_tenants(self):
ctxt = context.DesignateContext(user='12345', tenant='54321')
ctxt = context.DesignateContext(user_id='12345', project_id='54321')
admin_ctxt = ctxt.elevated()
admin_ctxt.all_tenants = True
@ -48,12 +48,12 @@ class TestDesignateContext(TestCase):
self.assertTrue(admin_ctxt.all_tenants)
def test_all_tenants_policy_failure(self):
ctxt = context.DesignateContext(user='12345', tenant='54321')
ctxt = context.DesignateContext(user_id='12345', project_id='54321')
with testtools.ExpectedException(exceptions.Forbidden):
ctxt.all_tenants = True
def test_edit_managed_records(self):
ctxt = context.DesignateContext(user='12345', tenant='54321')
ctxt = context.DesignateContext(user_id='12345', project_id='54321')
admin_ctxt = ctxt.elevated()
admin_ctxt.edit_managed_records = True
@ -63,6 +63,6 @@ class TestDesignateContext(TestCase):
self.assertTrue(admin_ctxt.edit_managed_records)
def test_edit_managed_records_failure(self):
ctxt = context.DesignateContext(user='12345', tenant='54321')
ctxt = context.DesignateContext(user_id='12345', project_id='54321')
with testtools.ExpectedException(exceptions.Forbidden):
ctxt.edit_managed_records = True

View File

@ -37,7 +37,7 @@ class NeutronAPITest(TestCase):
@patch.object(clientv20.Client, 'list_floatingips',
side_effect=neutron_exceptions.Unauthorized)
def test_unauthorized_returns_empty(self, _):
context = self.get_context(tenant='a', auth_token='test')
context = self.get_context(project_id='a', auth_token='test')
fips = self.api.list_floatingips(context)
self.assertEqual(0, len(fips))
@ -45,7 +45,7 @@ class NeutronAPITest(TestCase):
@patch.object(clientv20.Client, 'list_floatingips',
side_effect=neutron_exceptions.NeutronException)
def test_communication_failure(self, _):
context = self.get_context(tenant='a', auth_token='test')
context = self.get_context(project_id='a', auth_token='test')
with testtools.ExpectedException(
exceptions.NeutronCommunicationFailure):

View File

@ -62,7 +62,7 @@ class StorageTestCase(object):
values = self.get_quota_fixture(fixture=fixture, values=kwargs)
if 'tenant_id' not in values:
values['tenant_id'] = context.tenant
values['tenant_id'] = context.project_id
return self.storage.create_quota(context, values)
@ -184,7 +184,7 @@ class StorageTestCase(object):
# Quota Tests
def test_create_quota(self):
values = self.get_quota_fixture()
values['tenant_id'] = self.admin_context.tenant
values['tenant_id'] = self.admin_context.project_id
result = self.storage.create_quota(self.admin_context, values)
@ -192,7 +192,7 @@ class StorageTestCase(object):
self.assertIsNotNone(result['created_at'])
self.assertIsNone(result['updated_at'])
self.assertEqual(self.admin_context.tenant, result['tenant_id'])
self.assertEqual(self.admin_context.project_id, result['tenant_id'])
self.assertEqual(values['resource'], result['resource'])
self.assertEqual(values['hard_limit'], result['hard_limit'])
@ -495,9 +495,9 @@ class StorageTestCase(object):
def test_find_tenants(self):
context = self.get_admin_context()
one_context = context
one_context.tenant = 'One'
one_context.project_id = 'One'
two_context = context
two_context.tenant = 'Two'
two_context.project_id = 'Two'
context.all_tenants = True
# create 3 zones in 2 tenants
@ -526,7 +526,7 @@ class StorageTestCase(object):
def test_get_tenant(self):
context = self.get_admin_context()
one_context = context
one_context.tenant = 1
one_context.project_id = 1
context.all_tenants = True
# create 2 zones in a tenant
@ -547,9 +547,9 @@ class StorageTestCase(object):
def test_count_tenants(self):
context = self.get_admin_context()
one_context = context
one_context.tenant = 1
one_context.project_id = 1
two_context = context
two_context.tenant = 2
two_context.project_id = 2
context.all_tenants = True
# in the beginning, there should be nothing
@ -580,7 +580,7 @@ class StorageTestCase(object):
def test_create_zone(self):
pool_id = cfg.CONF['service:central'].default_pool_id
values = {
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'name': 'example.net.',
'email': 'example@example.net',
'pool_id': pool_id
@ -593,7 +593,7 @@ class StorageTestCase(object):
self.assertIsNotNone(result['created_at'])
self.assertIsNone(result['updated_at'])
self.assertEqual(self.admin_context.tenant, result['tenant_id'])
self.assertEqual(self.admin_context.project_id, result['tenant_id'])
self.assertEqual(values['name'], result['name'])
self.assertEqual(values['email'], result['email'])
self.assertEqual(pool_id, result['pool_id'])
@ -662,9 +662,9 @@ class StorageTestCase(object):
def test_find_zones_all_tenants(self):
# Create two contexts with different tenant_id's
one_context = self.get_admin_context()
one_context.tenant = 1
one_context.project_id = 1
two_context = self.get_admin_context()
two_context.tenant = 2
two_context.project_id = 2
# Create normal and all_tenants context objects
nm_context = self.get_admin_context()
@ -1305,7 +1305,7 @@ class StorageTestCase(object):
self.assertIsNotNone(result['hash'])
self.assertIsNone(result['updated_at'])
self.assertEqual(self.admin_context.tenant, result['tenant_id'])
self.assertEqual(self.admin_context.project_id, result['tenant_id'])
self.assertEqual(values['data'], result['data'])
self.assertIn('status', result)
@ -1411,9 +1411,9 @@ class StorageTestCase(object):
def test_find_records_all_tenants(self):
# Create two contexts with different tenant_id's
one_context = self.get_admin_context()
one_context.tenant = 1
one_context.project_id = 1
two_context = self.get_admin_context()
two_context.tenant = 2
two_context.project_id = 2
# Create normal and all_tenants context objects
nm_context = self.get_admin_context()
@ -1904,7 +1904,7 @@ class StorageTestCase(object):
def test_create_pool(self):
values = {
'name': 'test1',
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'provisioner': 'UNMANAGED'
}
@ -2915,7 +2915,7 @@ class StorageTestCase(object):
zone = self.create_zone()
values = {
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'zone_id': zone.id,
'key': 'qwertyuiop'
}
@ -2923,19 +2923,19 @@ class StorageTestCase(object):
result = self.storage.create_zone_transfer_request(
self.admin_context, objects.ZoneTransferRequest.from_dict(values))
self.assertEqual(self.admin_context.tenant, result['tenant_id'])
self.assertEqual(self.admin_context.project_id, result['tenant_id'])
self.assertIn('status', result)
def test_create_zone_transfer_request_scoped(self):
zone = self.create_zone()
tenant_2_context = self.get_context(tenant='2')
tenant_3_context = self.get_context(tenant='3')
tenant_2_context = self.get_context(project_id='2')
tenant_3_context = self.get_context(project_id='3')
values = {
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'zone_id': zone.id,
'key': 'qwertyuiop',
'target_tenant_id': tenant_2_context.tenant,
'target_tenant_id': tenant_2_context.project_id,
}
result = self.storage.create_zone_transfer_request(
@ -2945,14 +2945,18 @@ class StorageTestCase(object):
self.assertIsNotNone(result['created_at'])
self.assertIsNone(result['updated_at'])
self.assertEqual(self.admin_context.tenant, result['tenant_id'])
self.assertEqual(tenant_2_context.tenant, result['target_tenant_id'])
self.assertEqual(self.admin_context.project_id, result['tenant_id'])
self.assertEqual(
tenant_2_context.project_id, result['target_tenant_id']
)
self.assertIn('status', result)
stored_ztr = self.storage.get_zone_transfer_request(
tenant_2_context, result.id)
self.assertEqual(self.admin_context.tenant, stored_ztr['tenant_id'])
self.assertEqual(
self.admin_context.project_id, stored_ztr['tenant_id']
)
self.assertEqual(stored_ztr['id'], result['id'])
with testtools.ExpectedException(
@ -2964,7 +2968,7 @@ class StorageTestCase(object):
zone = self.create_zone()
values = {
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'zone_id': zone.id,
'key': 'qwertyuiop'
}
@ -2973,7 +2977,7 @@ class StorageTestCase(object):
self.admin_context, objects.ZoneTransferRequest.from_dict(values))
requests = self.storage.find_zone_transfer_requests(
self.admin_context, {"tenant_id": self.admin_context.tenant})
self.admin_context, {"tenant_id": self.admin_context.project_id})
self.assertEqual(1, len(requests))
def test_delete_zone_transfer_request(self):
@ -3011,7 +3015,7 @@ class StorageTestCase(object):
zone = self.create_zone()
zt_request = self.create_zone_transfer_request(zone)
values = {
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'zone_transfer_request_id': zt_request.id,
'zone_id': zone.id,
'key': zt_request.key
@ -3024,14 +3028,14 @@ class StorageTestCase(object):
self.assertIsNotNone(result['created_at'])
self.assertIsNone(result['updated_at'])
self.assertEqual(self.admin_context.tenant, result['tenant_id'])
self.assertEqual(self.admin_context.project_id, result['tenant_id'])
self.assertIn('status', result)
def test_find_zone_transfer_accepts(self):
zone = self.create_zone()
zt_request = self.create_zone_transfer_request(zone)
values = {
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'zone_transfer_request_id': zt_request.id,
'zone_id': zone.id,
'key': zt_request.key
@ -3041,14 +3045,14 @@ class StorageTestCase(object):
self.admin_context, objects.ZoneTransferAccept.from_dict(values))
accepts = self.storage.find_zone_transfer_accepts(
self.admin_context, {"tenant_id": self.admin_context.tenant})
self.admin_context, {"tenant_id": self.admin_context.project_id})
self.assertEqual(1, len(accepts))
def test_find_zone_transfer_accept(self):
zone = self.create_zone()
zt_request = self.create_zone_transfer_request(zone)
values = {
'tenant_id': self.admin_context.tenant,
'tenant_id': self.admin_context.project_id,
'zone_transfer_request_id': zt_request.id,
'zone_id': zone.id,
'key': zt_request.key
@ -3062,8 +3066,8 @@ class StorageTestCase(object):
self.assertEqual(result.id, accept.id)
def test_transfer_zone_ownership(self):
tenant_1_context = self.get_context(tenant='1')
tenant_2_context = self.get_context(tenant='2')
tenant_1_context = self.get_context(project_id='1')
tenant_2_context = self.get_context(project_id='2')
admin_context = self.get_admin_context()
admin_context.all_tenants = True
@ -3074,7 +3078,7 @@ class StorageTestCase(object):
updated_zone = zone
updated_zone.tenant_id = tenant_2_context.tenant
updated_zone.tenant_id = tenant_2_context.project_id
self.storage.update_zone(
admin_context, updated_zone)
@ -3086,9 +3090,11 @@ class StorageTestCase(object):
saved_record = self.storage.get_record(
admin_context, record.id)
self.assertEqual(tenant_2_context.tenant, saved_zone.tenant_id)
self.assertEqual(tenant_2_context.tenant, saved_recordset.tenant_id)
self.assertEqual(tenant_2_context.tenant, saved_record.tenant_id)
self.assertEqual(tenant_2_context.project_id, saved_zone.tenant_id)
self.assertEqual(
tenant_2_context.project_id, saved_recordset.tenant_id
)
self.assertEqual(tenant_2_context.project_id, saved_record.tenant_id)
def test_delete_zone_transfer_accept(self):
zone = self.create_zone()

View File

@ -237,7 +237,6 @@ class NotMockedError(NotImplementedError):
@patch('designate.central.service.storage',
mock.NonCallableMock(side_effect=NotMockedError))
class CentralBasic(TestCase):
def setUp(self):
super(CentralBasic, self).setUp()
self.CONF = self.useFixture(cfg_fixture.Config(cfg.CONF)).conf
@ -963,7 +962,7 @@ class CentralZoneTestCase(CentralBasic):
self.assertEqual(CentralZoneTestCase.pool__id, pool_id)
def test_find_zones(self):
self.context = RoObject(tenant='t')
self.context = RoObject(project_id='t')
self.service.storage.find_zones = Mock()
self.service.find_zones(self.context)
self.assertTrue(self.service.storage.find_zones.called)
@ -972,7 +971,7 @@ class CentralZoneTestCase(CentralBasic):
self.assertEqual('find_zones', pcheck)
def test_find_zone(self):
self.context = RoObject(tenant='t')
self.context = RoObject(project_id='t')
self.service.storage.find_zone = Mock()
self.service.find_zone(self.context)
self.assertTrue(self.service.storage.find_zone.called)
@ -1223,7 +1222,7 @@ class CentralZoneTestCase(CentralBasic):
def test_find_recordsets(self):
self.context = Mock()
self.context.tenant = 't'
self.context.project_id = 't'
self.service.find_recordsets(self.context)
self.assertTrue(self.service.storage.find_recordsets.called)
n, ctx, target = designate.central.service.policy.check.call_args[0]
@ -1232,7 +1231,7 @@ class CentralZoneTestCase(CentralBasic):
def test_find_recordset(self):
self.context = Mock()
self.context.tenant = 't'
self.context.project_id = 't'
self.service.find_recordset(self.context)
self.assertTrue(self.service.storage.find_recordset.called)
n, ctx, target = designate.central.service.policy.check.call_args[0]
@ -2124,7 +2123,7 @@ class CentralZoneTestCase(CentralBasic):
def test_determine_floatingips(self):
self.context = Mock()
self.context.tenant = 'tnt'
self.context.project_id = 'tnt'
self.service.find_records = Mock(return_value=[
RoObject(managed_extra='')
])
@ -2137,7 +2136,7 @@ class CentralZoneTestCase(CentralBasic):
def test_determine_floatingips_with_data(self):
self.context = Mock()
self.context.tenant = 2
self.context.project_id = 2
self.service.find_records = Mock(return_value=[
RoObject(managed_extra=1, managed_tenant_id=1),
RoObject(managed_extra=2, managed_tenant_id=2),
@ -2209,7 +2208,7 @@ class CentralZoneExportTests(CentralBasic):
def test_create_zone_export(self):
self.context = Mock()
self.context.tenant = 't'
self.context.project_id = 't'
self.service.storage.get_zone.return_value = RoObject(
name='example.com.',
@ -2242,7 +2241,7 @@ class CentralZoneExportTests(CentralBasic):
def test_get_zone_export(self):
self.context = Mock()
self.context.tenant = 't'
self.context.project_id = 't'
self.service.storage.get_zone_export.return_value = RoObject(
zone_id=CentralZoneTestCase.zone__id,
@ -2270,7 +2269,7 @@ class CentralZoneExportTests(CentralBasic):
def test_find_zone_exports(self):
self.context = Mock()
self.context.tenant = 't'
self.context.project_id = 't'
self.service.storage.find_zone_exports = Mock()
self.service.find_zone_exports(self.context)
@ -2282,7 +2281,7 @@ class CentralZoneExportTests(CentralBasic):
def test_delete_zone_export(self):
self.context = Mock()
self.context.tenant = 't'
self.context.project_id = 't'
self.service.storage.delete_zone_export = Mock(
return_value=RoObject(

View File

@ -614,7 +614,7 @@ class ExportZone(base.Task):
if synchronous:
try:
self.quota.limit_check(
context, context.tenant, api_export_size=size)
context, context.project_id, api_export_size=size)
except exceptions.OverQuota:
LOG.debug('Zone Export too large to perform synchronously')
export.status = 'ERROR'