Replace RCPDispatcher with decorator
Overriding the RCPDispatcher has been deprecated for a long time and generates a warning when starting the service. Ideally we would use the inbuilt oslo.messaging decorator instead of our own decorator, but due to complexities with the current Central implementation this at least gets us functional rpc unit-tests, that will make future refactors easier. The decorator introduced in this commit will only catch exceptions from the first call. Any additional calls happening as a result of the first call will not be caught and converted until they have bubbled back up to the original call. This is to prevent internal calls that expect the original exception from failing. * Added expected_exceptions decorator. * Renamed Base -> DesignateException. * Removed RPCDispatcher override. Change-Id: Id6a83b286bc20a1dc078ca77af0e9c97686fd74d
This commit is contained in:
@@ -233,7 +233,7 @@ class FaultWrapperMiddleware(base.Middleware):
|
||||
def __call__(self, request):
|
||||
try:
|
||||
return request.get_response(self.application)
|
||||
except exceptions.Base as e:
|
||||
except exceptions.DesignateException as e:
|
||||
# Handle Designate Exceptions
|
||||
status = e.error_code if hasattr(e, 'error_code') else 500
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ class Denominator(object):
|
||||
return stdout
|
||||
except utils.processutils.ProcessExecutionError as e:
|
||||
LOG.debug('Denominator call failure: %s' % e)
|
||||
raise exceptions.Base(e)
|
||||
raise exceptions.DesignateException(e)
|
||||
|
||||
|
||||
class DenominatorBackend(base.AgentBackend):
|
||||
|
||||
@@ -43,10 +43,11 @@ from designate import notifications
|
||||
from designate import objects
|
||||
from designate import policy
|
||||
from designate import quota
|
||||
from designate import rpc
|
||||
from designate import service
|
||||
from designate import scheduler
|
||||
from designate import utils
|
||||
from designate import storage
|
||||
from designate import utils
|
||||
from designate.mdns import rpcapi as mdns_rpcapi
|
||||
from designate.pool_manager import rpcapi as pool_manager_rpcapi
|
||||
from designate.storage import transaction
|
||||
@@ -654,11 +655,13 @@ class Service(service.RPCService, service.Service):
|
||||
recordset_records=recordset_records)
|
||||
|
||||
# Misc Methods
|
||||
@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)
|
||||
|
||||
# Quota Methods
|
||||
@rpc.expected_exceptions()
|
||||
def get_quotas(self, context, tenant_id):
|
||||
target = {'tenant_id': tenant_id}
|
||||
policy.check('get_quotas', context, target)
|
||||
@@ -668,12 +671,14 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return self.quota.get_quotas(context, tenant_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_quota(self, context, tenant_id, resource):
|
||||
target = {'tenant_id': tenant_id, 'resource': resource}
|
||||
policy.check('get_quota', context, target)
|
||||
|
||||
return self.quota.get_quota(context, tenant_id, resource)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@transaction
|
||||
def set_quota(self, context, tenant_id, resource, hard_limit):
|
||||
target = {
|
||||
@@ -696,6 +701,7 @@ class Service(service.RPCService, service.Service):
|
||||
self.quota.reset_quotas(context, tenant_id)
|
||||
|
||||
# TLD Methods
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.tld.create')
|
||||
@transaction
|
||||
def create_tld(self, context, tld):
|
||||
@@ -706,6 +712,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return created_tld
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_tlds(self, context, criterion=None, marker=None, limit=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
policy.check('find_tlds', context)
|
||||
@@ -713,11 +720,13 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_tlds(context, criterion, marker, limit,
|
||||
sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_tld(self, context, tld_id):
|
||||
policy.check('get_tld', context, {'tld_id': tld_id})
|
||||
|
||||
return self.storage.get_tld(context, tld_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.tld.update')
|
||||
@transaction
|
||||
def update_tld(self, context, tld):
|
||||
@@ -730,6 +739,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return tld
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.tld.delete')
|
||||
@transaction
|
||||
def delete_tld(self, context, tld_id):
|
||||
@@ -740,6 +750,7 @@ class Service(service.RPCService, service.Service):
|
||||
return tld
|
||||
|
||||
# TSIG Key Methods
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.tsigkey.create')
|
||||
@transaction
|
||||
def create_tsigkey(self, context, tsigkey):
|
||||
@@ -751,6 +762,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return created_tsigkey
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_tsigkeys(self, context, criterion=None, marker=None, limit=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
policy.check('find_tsigkeys', context)
|
||||
@@ -758,11 +770,13 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_tsigkeys(context, criterion, marker,
|
||||
limit, sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_tsigkey(self, context, tsigkey_id):
|
||||
policy.check('get_tsigkey', context, {'tsigkey_id': tsigkey_id})
|
||||
|
||||
return self.storage.get_tsigkey(context, tsigkey_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.tsigkey.update')
|
||||
@transaction
|
||||
def update_tsigkey(self, context, tsigkey):
|
||||
@@ -777,6 +791,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return tsigkey
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.tsigkey.delete')
|
||||
@transaction
|
||||
def delete_tsigkey(self, context, tsigkey_id):
|
||||
@@ -789,10 +804,12 @@ class Service(service.RPCService, service.Service):
|
||||
return tsigkey
|
||||
|
||||
# Tenant Methods
|
||||
@rpc.expected_exceptions()
|
||||
def find_tenants(self, context):
|
||||
policy.check('find_tenants', context)
|
||||
return self.storage.find_tenants(context)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_tenant(self, context, tenant_id):
|
||||
target = {
|
||||
'tenant_id': tenant_id
|
||||
@@ -802,6 +819,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return self.storage.get_tenant(context, tenant_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def count_tenants(self, context):
|
||||
policy.check('count_tenants', context)
|
||||
return self.storage.count_tenants(context)
|
||||
@@ -831,6 +849,7 @@ class Service(service.RPCService, service.Service):
|
||||
pool = self.storage.get_pool(elevated_context, pool_id)
|
||||
return pool.ns_records
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.domain.create')
|
||||
@notification('dns.zone.create')
|
||||
@synchronized_zone(new_zone=True)
|
||||
@@ -949,6 +968,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return zone
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_zone(self, context, zone_id):
|
||||
"""Get a zone, even if flagged for deletion
|
||||
"""
|
||||
@@ -963,6 +983,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return zone
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_zone_ns_records(self, context, zone_id=None, criterion=None):
|
||||
|
||||
if zone_id is None:
|
||||
@@ -987,6 +1008,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return pool.ns_records
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_zones(self, context, criterion=None, marker=None, limit=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
"""List existing zones including the ones flagged for deletion.
|
||||
@@ -997,12 +1019,14 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_zones(context, criterion, marker, limit,
|
||||
sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_zone(self, context, criterion=None):
|
||||
target = {'tenant_id': context.tenant}
|
||||
policy.check('find_zone', context, target)
|
||||
|
||||
return self.storage.find_zone(context, criterion)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.domain.update')
|
||||
@notification('dns.zone.update')
|
||||
@synchronized_zone()
|
||||
@@ -1068,6 +1092,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return zone
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.domain.delete')
|
||||
@notification('dns.zone.delete')
|
||||
@synchronized_zone()
|
||||
@@ -1122,6 +1147,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return zone
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def purge_zones(self, context, criterion, limit=None):
|
||||
"""Purge deleted zones.
|
||||
:returns: number of purged zones
|
||||
@@ -1134,6 +1160,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return self.storage.purge_zones(context, criterion, limit)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def xfr_zone(self, context, zone_id):
|
||||
zone = self.storage.get_zone(context, zone_id)
|
||||
|
||||
@@ -1162,6 +1189,7 @@ class Service(service.RPCService, service.Service):
|
||||
{"srv_serial": serial, "serial": zone.serial})
|
||||
self.mdns_api.perform_zone_xfr(context, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def count_zones(self, context, criterion=None):
|
||||
if criterion is None:
|
||||
criterion = {}
|
||||
@@ -1175,6 +1203,7 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.count_zones(context, criterion)
|
||||
|
||||
# Report combining all the count reports based on criterion
|
||||
@rpc.expected_exceptions()
|
||||
def count_report(self, context, criterion=None):
|
||||
reports = []
|
||||
|
||||
@@ -1203,6 +1232,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return reports
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone.touch')
|
||||
@synchronized_zone()
|
||||
def touch_zone(self, context, zone_id):
|
||||
@@ -1230,6 +1260,7 @@ class Service(service.RPCService, service.Service):
|
||||
return zone
|
||||
|
||||
# RecordSet Methods
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.recordset.create')
|
||||
@synchronized_zone()
|
||||
def create_recordset(self, context, zone_id, recordset,
|
||||
@@ -1319,6 +1350,7 @@ class Service(service.RPCService, service.Service):
|
||||
# Return the zone too in case it was updated
|
||||
return (recordset, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_recordset(self, context, zone_id, recordset_id):
|
||||
recordset = self.storage.get_recordset(context, recordset_id)
|
||||
|
||||
@@ -1345,6 +1377,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return recordset
|
||||
|
||||
@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}
|
||||
@@ -1356,6 +1389,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return recordsets
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_recordset(self, context, criterion=None):
|
||||
target = {'tenant_id': context.tenant}
|
||||
policy.check('find_recordset', context, target)
|
||||
@@ -1364,6 +1398,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return recordset
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def export_zone(self, context, zone_id):
|
||||
zone = self.get_zone(context, zone_id)
|
||||
|
||||
@@ -1374,6 +1409,7 @@ class Service(service.RPCService, service.Service):
|
||||
zone=zone,
|
||||
recordsets=recordsets)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.recordset.update')
|
||||
@synchronized_zone()
|
||||
def update_recordset(self, context, recordset, increment_serial=True):
|
||||
@@ -1447,6 +1483,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return (recordset, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.recordset.delete')
|
||||
@synchronized_zone()
|
||||
def delete_recordset(self, context, zone_id, recordset_id,
|
||||
@@ -1506,6 +1543,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return (recordset, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def count_recordsets(self, context, criterion=None):
|
||||
if criterion is None:
|
||||
criterion = {}
|
||||
@@ -1519,6 +1557,7 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.count_recordsets(context, criterion)
|
||||
|
||||
# Record Methods
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.record.create')
|
||||
@synchronized_zone()
|
||||
def create_record(self, context, zone_id, recordset_id, record,
|
||||
@@ -1571,6 +1610,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return (record, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_record(self, context, zone_id, recordset_id, record_id):
|
||||
zone = self.storage.get_zone(context, zone_id)
|
||||
recordset = self.storage.get_recordset(context, recordset_id)
|
||||
@@ -1597,6 +1637,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return record
|
||||
|
||||
@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}
|
||||
@@ -1605,12 +1646,14 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_records(context, criterion, marker, limit,
|
||||
sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_record(self, context, criterion=None):
|
||||
target = {'tenant_id': context.tenant}
|
||||
policy.check('find_record', context, target)
|
||||
|
||||
return self.storage.find_record(context, criterion)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.record.update')
|
||||
@synchronized_zone()
|
||||
def update_record(self, context, record, increment_serial=True):
|
||||
@@ -1679,6 +1722,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return (record, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.record.delete')
|
||||
@synchronized_zone()
|
||||
def delete_record(self, context, zone_id, recordset_id, record_id,
|
||||
@@ -1739,6 +1783,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return (record, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def count_records(self, context, criterion=None):
|
||||
if criterion is None:
|
||||
criterion = {}
|
||||
@@ -1754,6 +1799,7 @@ class Service(service.RPCService, service.Service):
|
||||
def _sync_zone(self, context, zone):
|
||||
return self.pool_manager_api.update_zone(context, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@transaction
|
||||
def sync_zones(self, context):
|
||||
policy.check('diagnostics_sync_zones', context)
|
||||
@@ -1766,6 +1812,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return results
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@transaction
|
||||
def sync_zone(self, context, zone_id):
|
||||
zone = self.storage.get_zone(context, zone_id)
|
||||
@@ -1780,6 +1827,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return self._sync_zone(context, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@transaction
|
||||
def sync_record(self, context, zone_id, recordset_id, record_id):
|
||||
zone = self.storage.get_zone(context, zone_id)
|
||||
@@ -1798,6 +1846,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
self.zone_api.update_zone(context, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def ping(self, context):
|
||||
policy.check('diagnostics_ping', context)
|
||||
|
||||
@@ -1956,6 +2005,7 @@ class Service(service.RPCService, service.Service):
|
||||
return fips[region, floatingip_id]
|
||||
|
||||
# PTR ops
|
||||
@rpc.expected_exceptions()
|
||||
def list_floatingips(self, context):
|
||||
"""
|
||||
List Floating IPs PTR
|
||||
@@ -1976,6 +2026,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return self._format_floatingips(context, valid)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_floatingip(self, context, region, floatingip_id):
|
||||
"""
|
||||
Get Floating IP PTR
|
||||
@@ -2123,6 +2174,7 @@ class Service(service.RPCService, service.Service):
|
||||
recordset_id=record['recordset_id'],
|
||||
record_id=record['id'])
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@transaction
|
||||
def update_floatingip(self, context, region, floatingip_id, values):
|
||||
"""
|
||||
@@ -2137,6 +2189,7 @@ class Service(service.RPCService, service.Service):
|
||||
context, region, floatingip_id, values)
|
||||
|
||||
# Blacklisted zones
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.blacklist.create')
|
||||
@transaction
|
||||
def create_blacklist(self, context, blacklist):
|
||||
@@ -2146,6 +2199,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return created_blacklist
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_blacklist(self, context, blacklist_id):
|
||||
policy.check('get_blacklist', context)
|
||||
|
||||
@@ -2153,6 +2207,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return blacklist
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_blacklists(self, context, criterion=None, marker=None,
|
||||
limit=None, sort_key=None, sort_dir=None):
|
||||
policy.check('find_blacklists', context)
|
||||
@@ -2163,6 +2218,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return blacklists
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_blacklist(self, context, criterion):
|
||||
policy.check('find_blacklist', context)
|
||||
|
||||
@@ -2170,6 +2226,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return blacklist
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.blacklist.update')
|
||||
@transaction
|
||||
def update_blacklist(self, context, blacklist):
|
||||
@@ -2182,6 +2239,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return blacklist
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.blacklist.delete')
|
||||
@transaction
|
||||
def delete_blacklist(self, context, blacklist_id):
|
||||
@@ -2192,6 +2250,7 @@ class Service(service.RPCService, service.Service):
|
||||
return blacklist
|
||||
|
||||
# Server Pools
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.pool.create')
|
||||
@transaction
|
||||
def create_pool(self, context, pool):
|
||||
@@ -2205,6 +2264,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return created_pool
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_pools(self, context, criterion=None, marker=None, limit=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
|
||||
@@ -2213,18 +2273,21 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_pools(context, criterion, marker, limit,
|
||||
sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_pool(self, context, criterion=None):
|
||||
|
||||
policy.check('find_pool', context)
|
||||
|
||||
return self.storage.find_pool(context, criterion)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_pool(self, context, pool_id):
|
||||
|
||||
policy.check('get_pool', context)
|
||||
|
||||
return self.storage.get_pool(context, pool_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.pool.update')
|
||||
@transaction
|
||||
def update_pool(self, context, pool):
|
||||
@@ -2281,6 +2344,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return updated_pool
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.pool.delete')
|
||||
@transaction
|
||||
def delete_pool(self, context, pool_id):
|
||||
@@ -2303,6 +2367,7 @@ class Service(service.RPCService, service.Service):
|
||||
return pool
|
||||
|
||||
# Pool Manager Integration
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.domain.update')
|
||||
@notification('dns.zone.update')
|
||||
@transaction
|
||||
@@ -2434,6 +2499,7 @@ class Service(service.RPCService, service.Service):
|
||||
sysrand = SystemRandom()
|
||||
return ''.join(sysrand.choice(chars) for _ in range(size))
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_transfer_request.create')
|
||||
@transaction
|
||||
def create_zone_transfer_request(self, context, zone_transfer_request):
|
||||
@@ -2461,6 +2527,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return created_zone_transfer_request
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_zone_transfer_request(self, context, zone_transfer_request_id):
|
||||
|
||||
elevated_context = context.elevated(all_tenants=True)
|
||||
@@ -2478,6 +2545,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return zone_transfer_request
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_zone_transfer_requests(self, context, criterion=None, marker=None,
|
||||
limit=None, sort_key=None, sort_dir=None):
|
||||
|
||||
@@ -2490,6 +2558,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return requests
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_zone_transfer_request(self, context, criterion):
|
||||
target = {
|
||||
'tenant_id': context.tenant,
|
||||
@@ -2497,6 +2566,7 @@ class Service(service.RPCService, service.Service):
|
||||
policy.check('find_zone_transfer_request', context, target)
|
||||
return self.storage.find_zone_transfer_requests(context, criterion)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_transfer_request.update')
|
||||
@transaction
|
||||
def update_zone_transfer_request(self, context, zone_transfer_request):
|
||||
@@ -2513,6 +2583,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return request
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_transfer_request.delete')
|
||||
@transaction
|
||||
def delete_zone_transfer_request(self, context, zone_transfer_request_id):
|
||||
@@ -2527,6 +2598,7 @@ class Service(service.RPCService, service.Service):
|
||||
context,
|
||||
zone_transfer_request_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_transfer_accept.create')
|
||||
@transaction
|
||||
def create_zone_transfer_accept(self, context, zone_transfer_accept):
|
||||
@@ -2590,6 +2662,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return created_zone_transfer_accept
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_zone_transfer_accept(self, context, zone_transfer_accept_id):
|
||||
# Get zone transfer accept
|
||||
|
||||
@@ -2603,6 +2676,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return zone_transfer_accept
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_zone_transfer_accepts(self, context, criterion=None, marker=None,
|
||||
limit=None, sort_key=None, sort_dir=None):
|
||||
policy.check('find_zone_transfer_accepts', context)
|
||||
@@ -2610,10 +2684,12 @@ class Service(service.RPCService, service.Service):
|
||||
marker, limit,
|
||||
sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_zone_transfer_accept(self, context, criterion):
|
||||
policy.check('find_zone_transfer_accept', context)
|
||||
return self.storage.find_zone_transfer_accept(context, criterion)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_transfer_accept.update')
|
||||
@transaction
|
||||
def update_zone_transfer_accept(self, context, zone_transfer_accept):
|
||||
@@ -2626,6 +2702,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return accept
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_transfer_accept.delete')
|
||||
@transaction
|
||||
def delete_zone_transfer_accept(self, context, zone_transfer_accept_id):
|
||||
@@ -2642,6 +2719,7 @@ class Service(service.RPCService, service.Service):
|
||||
zone_transfer_accept_id)
|
||||
|
||||
# Zone Import Methods
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_import.create')
|
||||
def create_zone_import(self, context, request_body):
|
||||
target = {'tenant_id': context.tenant}
|
||||
@@ -2737,6 +2815,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
self.update_zone_import(context, zone_import)
|
||||
|
||||
@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}
|
||||
@@ -2748,11 +2827,13 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_zone_imports(context, criterion, marker,
|
||||
limit, sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_zone_import(self, context, zone_import_id):
|
||||
target = {'tenant_id': context.tenant}
|
||||
policy.check('get_zone_import', context, target)
|
||||
return self.storage.get_zone_import(context, zone_import_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_import.update')
|
||||
def update_zone_import(self, context, zone_import):
|
||||
target = {
|
||||
@@ -2762,6 +2843,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return self.storage.update_zone_import(context, zone_import)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_import.delete')
|
||||
@transaction
|
||||
def delete_zone_import(self, context, zone_import_id):
|
||||
@@ -2776,6 +2858,7 @@ class Service(service.RPCService, service.Service):
|
||||
return zone_import
|
||||
|
||||
# Zone Export Methods
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_export.create')
|
||||
def create_zone_export(self, context, zone_id):
|
||||
# Try getting the zone to ensure it exists
|
||||
@@ -2832,6 +2915,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return created_zone_export
|
||||
|
||||
@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}
|
||||
@@ -2843,12 +2927,14 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_zone_exports(context, criterion, marker,
|
||||
limit, sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def get_zone_export(self, context, zone_export_id):
|
||||
target = {'tenant_id': context.tenant}
|
||||
policy.check('get_zone_export', context, target)
|
||||
|
||||
return self.storage.get_zone_export(context, zone_export_id)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_export.update')
|
||||
def update_zone_export(self, context, zone_export):
|
||||
target = {
|
||||
@@ -2858,6 +2944,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return self.storage.update_zone_export(context, zone_export)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
@notification('dns.zone_export.delete')
|
||||
@transaction
|
||||
def delete_zone_export(self, context, zone_export_id):
|
||||
@@ -2871,6 +2958,7 @@ class Service(service.RPCService, service.Service):
|
||||
|
||||
return zone_export
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_service_statuses(self, context, criterion=None, marker=None,
|
||||
limit=None, sort_key=None, sort_dir=None):
|
||||
"""List service statuses.
|
||||
@@ -2880,11 +2968,13 @@ class Service(service.RPCService, service.Service):
|
||||
return self.storage.find_service_statuses(
|
||||
context, criterion, marker, limit, sort_key, sort_dir)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def find_service_status(self, context, criterion=None):
|
||||
policy.check('find_service_status', context)
|
||||
|
||||
return self.storage.find_service_status(context, criterion)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def update_service_status(self, context, service_status):
|
||||
policy.check('update_service_status', context)
|
||||
|
||||
|
||||
+25
-25
@@ -16,7 +16,7 @@
|
||||
import six
|
||||
|
||||
|
||||
class Base(Exception):
|
||||
class DesignateException(Exception):
|
||||
error_code = 500
|
||||
error_type = None
|
||||
error_message = None
|
||||
@@ -27,9 +27,9 @@ class Base(Exception):
|
||||
self.errors = kwargs.pop('errors', None)
|
||||
self.object = kwargs.pop('object', None)
|
||||
|
||||
super(Base, self).__init__(*args, **kwargs)
|
||||
super(DesignateException, self).__init__(*args, **kwargs)
|
||||
|
||||
if len(args) > 0 and isinstance(args[0], six.string_types):
|
||||
if args and isinstance(args[0], six.string_types):
|
||||
self.error_message = args[0]
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class Backend(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class RelationNotLoaded(Base):
|
||||
class RelationNotLoaded(DesignateException):
|
||||
error_code = 500
|
||||
error_type = 'relation_not_loaded'
|
||||
|
||||
@@ -54,7 +54,7 @@ class RelationNotLoaded(Base):
|
||||
return self.error_message
|
||||
|
||||
|
||||
class AdapterNotFound(Base):
|
||||
class AdapterNotFound(DesignateException):
|
||||
error_code = 500
|
||||
error_type = 'adapter_not_found'
|
||||
|
||||
@@ -63,24 +63,24 @@ class NSD4SlaveBackendError(Backend):
|
||||
pass
|
||||
|
||||
|
||||
class NotImplemented(Base, NotImplementedError):
|
||||
class NotImplemented(DesignateException, NotImplementedError):
|
||||
pass
|
||||
|
||||
|
||||
class XFRFailure(Base):
|
||||
class XFRFailure(DesignateException):
|
||||
pass
|
||||
|
||||
|
||||
class ConfigurationError(Base):
|
||||
class ConfigurationError(DesignateException):
|
||||
error_type = 'configuration_error'
|
||||
|
||||
|
||||
class UnknownFailure(Base):
|
||||
class UnknownFailure(DesignateException):
|
||||
error_code = 500
|
||||
error_type = 'unknown_failure'
|
||||
|
||||
|
||||
class CommunicationFailure(Base):
|
||||
class CommunicationFailure(DesignateException):
|
||||
error_code = 504
|
||||
error_type = 'communication_failure'
|
||||
|
||||
@@ -119,27 +119,27 @@ class NoPoolTargetsConfigured(ConfigurationError):
|
||||
error_type = 'no_pool_targets_configured'
|
||||
|
||||
|
||||
class OverQuota(Base):
|
||||
class OverQuota(DesignateException):
|
||||
error_code = 413
|
||||
error_type = 'over_quota'
|
||||
expected = True
|
||||
|
||||
|
||||
class QuotaResourceUnknown(Base):
|
||||
class QuotaResourceUnknown(DesignateException):
|
||||
error_type = 'quota_resource_unknown'
|
||||
|
||||
|
||||
class InvalidObject(Base):
|
||||
class InvalidObject(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'invalid_object'
|
||||
expected = True
|
||||
|
||||
|
||||
class BadAction(Base):
|
||||
class BadAction(DesignateException):
|
||||
error_type = 'bad_action'
|
||||
|
||||
|
||||
class BadRequest(Base):
|
||||
class BadRequest(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'bad_request'
|
||||
expected = True
|
||||
@@ -206,40 +206,40 @@ class UnsupportedContentType(BadRequest):
|
||||
error_type = 'unsupported_content_type'
|
||||
|
||||
|
||||
class InvalidZoneName(Base):
|
||||
class InvalidZoneName(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'invalid_zone_name'
|
||||
expected = True
|
||||
|
||||
|
||||
class InvalidRecordSetName(Base):
|
||||
class InvalidRecordSetName(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'invalid_recordset_name'
|
||||
expected = True
|
||||
|
||||
|
||||
class InvalidRecordSetLocation(Base):
|
||||
class InvalidRecordSetLocation(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'invalid_recordset_location'
|
||||
expected = True
|
||||
|
||||
|
||||
class InvaildZoneTransfer(Base):
|
||||
class InvaildZoneTransfer(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'invalid_zone_transfer_request'
|
||||
|
||||
|
||||
class InvalidTTL(Base):
|
||||
class InvalidTTL(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'invalid_ttl'
|
||||
|
||||
|
||||
class ZoneHasSubZone(Base):
|
||||
class ZoneHasSubZone(DesignateException):
|
||||
error_code = 400
|
||||
error_type = 'zone_has_sub_zone'
|
||||
|
||||
|
||||
class Forbidden(Base):
|
||||
class Forbidden(DesignateException):
|
||||
error_code = 403
|
||||
error_type = 'forbidden'
|
||||
expected = True
|
||||
@@ -257,7 +257,7 @@ class IncorrectZoneTransferKey(Forbidden):
|
||||
error_type = 'invalid_key'
|
||||
|
||||
|
||||
class Duplicate(Base):
|
||||
class Duplicate(DesignateException):
|
||||
expected = True
|
||||
error_code = 409
|
||||
error_type = 'duplicate'
|
||||
@@ -343,7 +343,7 @@ class DuplicateZoneExport(Duplicate):
|
||||
error_type = 'duplicate_zone_export'
|
||||
|
||||
|
||||
class MethodNotAllowed(Base):
|
||||
class MethodNotAllowed(DesignateException):
|
||||
expected = True
|
||||
error_code = 405
|
||||
error_type = 'method_not_allowed'
|
||||
@@ -365,7 +365,7 @@ class DuplicateZoneMaster(Duplicate):
|
||||
error_type = 'duplicate_zone_attribute'
|
||||
|
||||
|
||||
class NotFound(Base):
|
||||
class NotFound(DesignateException):
|
||||
expected = True
|
||||
error_code = 404
|
||||
error_type = 'not_found'
|
||||
|
||||
+33
-16
@@ -25,20 +25,22 @@ __all__ = [
|
||||
'get_notifier',
|
||||
]
|
||||
|
||||
import functools
|
||||
from oslo_config import cfg
|
||||
import oslo_messaging as messaging
|
||||
from oslo_messaging.rpc import dispatcher as rpc_dispatcher
|
||||
from oslo_messaging.rpc import server as rpc_server
|
||||
from oslo_serialization import jsonutils
|
||||
import threading
|
||||
|
||||
import designate.context
|
||||
import designate.exceptions
|
||||
from designate import objects
|
||||
|
||||
CONF = cfg.CONF
|
||||
TRANSPORT = None
|
||||
NOTIFIER = None
|
||||
EXPECTED_EXCEPTION = threading.local()
|
||||
NOTIFICATION_TRANSPORT = None
|
||||
NOTIFIER = None
|
||||
TRANSPORT = None
|
||||
|
||||
# NOTE: Additional entries to designate.exceptions goes here.
|
||||
CONF.register_opts([
|
||||
@@ -162,16 +164,6 @@ class RequestContextSerializer(messaging.Serializer):
|
||||
return designate.context.DesignateContext.from_dict(context)
|
||||
|
||||
|
||||
class RPCDispatcher(rpc_dispatcher.RPCDispatcher):
|
||||
def dispatch(self, *args, **kwds):
|
||||
try:
|
||||
return super(RPCDispatcher, self).dispatch(*args, **kwds)
|
||||
except designate.exceptions.Base as e:
|
||||
if e.expected:
|
||||
raise rpc_dispatcher.ExpectedException()
|
||||
raise
|
||||
|
||||
|
||||
def get_transport_url(url_str=None):
|
||||
return messaging.TransportURL.parse(CONF, url_str)
|
||||
|
||||
@@ -197,12 +189,13 @@ def get_server(target, endpoints, serializer=None):
|
||||
serializer = DesignateObjectSerializer()
|
||||
serializer = RequestContextSerializer(serializer)
|
||||
access_policy = rpc_dispatcher.DefaultRPCAccessPolicy
|
||||
dispatcher = RPCDispatcher(endpoints, serializer, access_policy)
|
||||
return rpc_server.RPCServer(
|
||||
return messaging.get_rpc_server(
|
||||
TRANSPORT,
|
||||
target,
|
||||
dispatcher=dispatcher,
|
||||
endpoints,
|
||||
executor='eventlet',
|
||||
serializer=serializer,
|
||||
access_policy=access_policy
|
||||
)
|
||||
|
||||
|
||||
@@ -234,3 +227,27 @@ def create_transport(url):
|
||||
return messaging.get_rpc_transport(CONF,
|
||||
url=url,
|
||||
allowed_remote_exmods=exmods)
|
||||
|
||||
|
||||
def expected_exceptions():
|
||||
def outer(f):
|
||||
@functools.wraps(f)
|
||||
def exception_wrapper(self, *args, **kwargs):
|
||||
if not hasattr(EXPECTED_EXCEPTION, 'depth'):
|
||||
EXPECTED_EXCEPTION.depth = 0
|
||||
EXPECTED_EXCEPTION.depth += 1
|
||||
|
||||
# We only want to wrap the first function wrapped.
|
||||
if EXPECTED_EXCEPTION.depth > 1:
|
||||
return f(self, *args, **kwargs)
|
||||
|
||||
try:
|
||||
return f(self, *args, **kwargs)
|
||||
except designate.exceptions.DesignateException as e:
|
||||
if e.expected:
|
||||
raise rpc_dispatcher.ExpectedException()
|
||||
raise
|
||||
finally:
|
||||
EXPECTED_EXCEPTION.depth = 0
|
||||
return exception_wrapper
|
||||
return outer
|
||||
|
||||
@@ -28,6 +28,7 @@ from oslo_log import log as logging
|
||||
from oslo_db import exception as db_exception
|
||||
from oslo_versionedobjects import exception as ovo_exc
|
||||
from oslo_messaging.notify import notifier
|
||||
from oslo_messaging.rpc import dispatcher as rpc_dispatcher
|
||||
|
||||
from designate import exceptions
|
||||
from designate import objects
|
||||
@@ -325,10 +326,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.central_service.delete_tld(self.admin_context, tld['id'])
|
||||
|
||||
# Fetch the tld again, ensuring an exception is raised
|
||||
self.assertRaises(
|
||||
exceptions.TldNotFound,
|
||||
self.central_service.get_tld,
|
||||
self.admin_context, tld['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_tld,
|
||||
self.admin_context, tld['id'])
|
||||
|
||||
self.assertEqual(exceptions.TldNotFound, exc.exc_info[0])
|
||||
|
||||
# TsigKey Tests
|
||||
def test_create_tsigkey(self):
|
||||
@@ -404,8 +406,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.central_service.delete_tsigkey(self.admin_context, tsigkey['id'])
|
||||
|
||||
# Fetch the tsigkey again, ensuring an exception is raised
|
||||
with testtools.ExpectedException(exceptions.TsigKeyNotFound):
|
||||
self.central_service.get_tsigkey(self.admin_context, tsigkey['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_tsigkey,
|
||||
self.admin_context, tsigkey['id'])
|
||||
|
||||
self.assertEqual(exceptions.TsigKeyNotFound, exc.exc_info[0])
|
||||
|
||||
# Tenant Tests
|
||||
def test_count_tenants(self):
|
||||
@@ -430,8 +435,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
# Set the policy to reject the authz
|
||||
self.policy({'count_tenants': '!'})
|
||||
|
||||
with testtools.ExpectedException(exceptions.Forbidden):
|
||||
self.central_service.count_tenants(self.get_context())
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.count_tenants,
|
||||
self.get_context())
|
||||
|
||||
self.assertEqual(exceptions.Forbidden, exc.exc_info[0])
|
||||
|
||||
# Zone Tests
|
||||
@mock.patch.object(notifier.Notifier, "info")
|
||||
@@ -510,8 +518,10 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
self.create_zone()
|
||||
|
||||
with testtools.ExpectedException(exceptions.OverQuota):
|
||||
self.create_zone()
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_zone)
|
||||
|
||||
self.assertEqual(exceptions.OverQuota, exc.exc_info[0])
|
||||
|
||||
def test_create_subzone(self):
|
||||
# Create the Parent Zone using fixture 0
|
||||
@@ -593,9 +603,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
values['name'] = 'www.%s' % parent_zone['name']
|
||||
|
||||
# Attempt to create the subzone
|
||||
with testtools.ExpectedException(exceptions.IllegalChildZone):
|
||||
self.central_service.create_zone(
|
||||
context, objects.Zone.from_dict(values))
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_zone,
|
||||
context, objects.Zone.from_dict(values))
|
||||
|
||||
self.assertEqual(exceptions.IllegalChildZone, exc.exc_info[0])
|
||||
|
||||
def test_create_superzone_failure(self):
|
||||
context = self.get_admin_context()
|
||||
@@ -620,9 +632,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
context.tenant = '2'
|
||||
|
||||
# Attempt to create the zone
|
||||
with testtools.ExpectedException(exceptions.IllegalParentZone):
|
||||
self.central_service.create_zone(
|
||||
context, objects.Zone.from_dict(zone_values))
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_zone,
|
||||
context, objects.Zone.from_dict(zone_values))
|
||||
|
||||
self.assertEqual(exceptions.IllegalParentZone, exc.exc_info[0])
|
||||
|
||||
def test_create_blacklisted_zone_success(self):
|
||||
# Create blacklisted zone using default values
|
||||
@@ -656,10 +670,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
email='info@blacklisted.com'
|
||||
)
|
||||
|
||||
with testtools.ExpectedException(exceptions.InvalidZoneName):
|
||||
# Create a zone
|
||||
self.central_service.create_zone(
|
||||
self.admin_context, objects.Zone.from_dict(values))
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_zone,
|
||||
self.admin_context,
|
||||
objects.Zone.from_dict(values))
|
||||
|
||||
self.assertEqual(exceptions.InvalidZoneName, exc.exc_info[0])
|
||||
|
||||
def _test_create_zone_fail(self, values, exception):
|
||||
|
||||
@@ -687,10 +703,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
)
|
||||
|
||||
# There is no TLD for net so it should fail
|
||||
with testtools.ExpectedException(exceptions.InvalidZoneName):
|
||||
# Create an invalid zone
|
||||
self.central_service.create_zone(
|
||||
self.admin_context, objects.Zone.from_dict(values))
|
||||
# Create an invalid zone
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_zone,
|
||||
self.admin_context,
|
||||
objects.Zone.from_dict(values))
|
||||
|
||||
self.assertEqual(exceptions.InvalidZoneName, exc.exc_info[0])
|
||||
|
||||
def test_create_zone_invalid_ttl_fail(self):
|
||||
self.policy({'use_low_ttl': '!'})
|
||||
@@ -905,8 +924,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
zone.name = 'example.net.'
|
||||
|
||||
# Perform the update
|
||||
with testtools.ExpectedException(exceptions.BadRequest):
|
||||
self.central_service.update_zone(self.admin_context, zone)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.update_zone,
|
||||
self.admin_context, zone)
|
||||
|
||||
self.assertEqual(exceptions.BadRequest, exc.exc_info[0])
|
||||
|
||||
def test_update_zone_deadlock_retry(self):
|
||||
# Create a zone
|
||||
@@ -1005,8 +1027,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
# Set the policy to reject the authz
|
||||
self.policy({'count_zones': '!'})
|
||||
|
||||
with testtools.ExpectedException(exceptions.Forbidden):
|
||||
self.central_service.count_zones(self.get_context())
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.count_zones,
|
||||
self.get_context())
|
||||
|
||||
self.assertEqual(exceptions.Forbidden, exc.exc_info[0])
|
||||
|
||||
def _fetch_all_zones(self):
|
||||
"""Fetch all zones including deleted ones
|
||||
@@ -1356,8 +1381,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
def test_xfr_zone_invalid_type(self):
|
||||
zone = self.create_zone()
|
||||
|
||||
with testtools.ExpectedException(exceptions.BadRequest):
|
||||
self.central_service.xfr_zone(self.admin_context, zone.id)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.xfr_zone,
|
||||
self.admin_context, zone.id)
|
||||
|
||||
self.assertEqual(exceptions.BadRequest, exc.exc_info[0])
|
||||
|
||||
# RecordSet Tests
|
||||
def test_create_recordset(self):
|
||||
@@ -1424,8 +1452,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
self.create_recordset(zone)
|
||||
|
||||
with testtools.ExpectedException(exceptions.OverQuota):
|
||||
self.create_recordset(zone)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_recordset,
|
||||
zone)
|
||||
|
||||
self.assertEqual(exceptions.OverQuota, exc.exc_info[0])
|
||||
|
||||
def test_create_invalid_recordset_location_cname_at_apex(self):
|
||||
zone = self.create_zone()
|
||||
@@ -1436,11 +1467,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
)
|
||||
|
||||
# Attempt to create a CNAME record at the apex
|
||||
with testtools.ExpectedException(exceptions.InvalidRecordSetLocation):
|
||||
self.central_service.create_recordset(
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_recordset,
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
|
||||
self.assertEqual(exceptions.InvalidRecordSetLocation, exc.exc_info[0])
|
||||
|
||||
def test_create_invalid_recordset_location_cname_sharing(self):
|
||||
zone = self.create_zone()
|
||||
@@ -1452,11 +1485,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
)
|
||||
|
||||
# Attempt to create a CNAME record alongside another record
|
||||
with testtools.ExpectedException(exceptions.InvalidRecordSetLocation):
|
||||
self.central_service.create_recordset(
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_recordset,
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
|
||||
self.assertEqual(exceptions.InvalidRecordSetLocation, exc.exc_info[0])
|
||||
|
||||
def test_create_invalid_recordset_location_wrong_zone(self):
|
||||
zone = self.create_zone()
|
||||
@@ -1468,11 +1503,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
)
|
||||
|
||||
# Attempt to create a record in the incorrect zone
|
||||
with testtools.ExpectedException(exceptions.InvalidRecordSetLocation):
|
||||
self.central_service.create_recordset(
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_recordset,
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
|
||||
self.assertEqual(exceptions.InvalidRecordSetLocation, exc.exc_info[0])
|
||||
|
||||
def test_create_invalid_recordset_ttl(self):
|
||||
self.policy({'use_low_ttl': '!'})
|
||||
@@ -1487,11 +1524,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
)
|
||||
|
||||
# Attempt to create a A record under the TTL
|
||||
with testtools.ExpectedException(exceptions.InvalidTTL):
|
||||
self.central_service.create_recordset(
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
self.assertRaises(exceptions.InvalidTTL,
|
||||
self.central_service.create_recordset,
|
||||
self.admin_context,
|
||||
zone['id'],
|
||||
recordset=objects.RecordSet.from_dict(values))
|
||||
|
||||
def test_create_recordset_no_min_ttl(self):
|
||||
self.policy({'use_low_ttl': '!'})
|
||||
@@ -1549,9 +1586,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
expected = self.create_recordset(zone)
|
||||
|
||||
# Ensure we get a 404 if we use the incorrect zone_id
|
||||
with testtools.ExpectedException(exceptions.RecordSetNotFound):
|
||||
self.central_service.get_recordset(
|
||||
self.admin_context, other_zone['id'], expected['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_recordset,
|
||||
self.admin_context, other_zone['id'],
|
||||
expected['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0])
|
||||
|
||||
def test_find_recordsets(self):
|
||||
zone = self.create_zone()
|
||||
@@ -1843,9 +1883,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.admin_context, zone['id'], recordset['id'])
|
||||
|
||||
# Fetch the recordset again, ensuring an exception is raised
|
||||
with testtools.ExpectedException(exceptions.RecordSetNotFound):
|
||||
self.central_service.get_recordset(
|
||||
self.admin_context, zone['id'], recordset['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_recordset,
|
||||
self.admin_context, zone['id'],
|
||||
recordset['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0])
|
||||
|
||||
# Fetch the zone again to verify serial number increased
|
||||
updated_zone = self.central_service.get_zone(self.admin_context,
|
||||
@@ -1869,9 +1912,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
increment_serial=False)
|
||||
|
||||
# Fetch the record again, ensuring an exception is raised
|
||||
with testtools.ExpectedException(exceptions.RecordSetNotFound):
|
||||
self.central_service.get_recordset(
|
||||
self.admin_context, zone['id'], recordset['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_recordset,
|
||||
self.admin_context, zone['id'],
|
||||
recordset['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0])
|
||||
|
||||
# Ensure the zones serial number was not updated
|
||||
zone_after = self.central_service.get_zone(
|
||||
@@ -1887,9 +1933,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
recordset = self.create_recordset(zone)
|
||||
|
||||
# Ensure we get a 404 if we use the incorrect zone_id
|
||||
with testtools.ExpectedException(exceptions.RecordSetNotFound):
|
||||
self.central_service.delete_recordset(
|
||||
self.admin_context, other_zone['id'], recordset['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.delete_recordset,
|
||||
self.admin_context, other_zone['id'],
|
||||
recordset['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0])
|
||||
|
||||
def test_count_recordsets(self):
|
||||
# in the beginning, there should be nothing
|
||||
@@ -1910,8 +1959,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
# Set the policy to reject the authz
|
||||
self.policy({'count_recordsets': '!'})
|
||||
|
||||
with testtools.ExpectedException(exceptions.Forbidden):
|
||||
self.central_service.count_recordsets(self.get_context())
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.count_recordsets,
|
||||
self.get_context())
|
||||
|
||||
self.assertEqual(exceptions.Forbidden, exc.exc_info[0])
|
||||
|
||||
# Record Tests
|
||||
def test_create_record(self):
|
||||
@@ -1942,8 +1994,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
self.create_record(zone, recordset)
|
||||
|
||||
with testtools.ExpectedException(exceptions.OverQuota):
|
||||
self.create_record(zone, recordset)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_record,
|
||||
zone, recordset)
|
||||
|
||||
self.assertEqual(exceptions.OverQuota, exc.exc_info[0])
|
||||
|
||||
def test_create_record_over_zone_quota(self):
|
||||
self.config(quota_zone_records=1)
|
||||
@@ -1960,10 +2015,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
])
|
||||
)
|
||||
|
||||
with testtools.ExpectedException(exceptions.OverQuota):
|
||||
# Persist the Object
|
||||
recordset = self.central_service.create_recordset(
|
||||
self.admin_context, zone.id, recordset=recordset)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_recordset,
|
||||
self.admin_context, zone.id,
|
||||
recordset=recordset)
|
||||
|
||||
self.assertEqual(exceptions.OverQuota, exc.exc_info[0])
|
||||
|
||||
def test_create_record_over_recordset_quota(self):
|
||||
self.config(quota_recordset_records=1)
|
||||
@@ -1974,8 +2031,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
self.create_record(zone, recordset)
|
||||
|
||||
with testtools.ExpectedException(exceptions.OverQuota):
|
||||
self.create_record(zone, recordset)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_record,
|
||||
zone, recordset)
|
||||
|
||||
self.assertEqual(exceptions.OverQuota, exc.exc_info[0])
|
||||
|
||||
def test_create_record_without_incrementing_serial(self):
|
||||
zone = self.create_zone()
|
||||
@@ -2020,11 +2080,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
# Create a record
|
||||
expected = self.create_record(zone, recordset)
|
||||
|
||||
# Ensure we get a 404 if we use the incorrect zone_id
|
||||
with testtools.ExpectedException(exceptions.RecordNotFound):
|
||||
self.central_service.get_record(
|
||||
self.admin_context, other_zone['id'], recordset['id'],
|
||||
expected['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_record,
|
||||
self.admin_context, other_zone['id'],
|
||||
recordset['id'],
|
||||
expected['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
|
||||
|
||||
def test_get_record_incorrect_recordset_id(self):
|
||||
zone = self.create_zone()
|
||||
@@ -2034,11 +2096,14 @@ class CentralServiceTest(CentralTestCase):
|
||||
# Create a record
|
||||
expected = self.create_record(zone, recordset)
|
||||
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_record,
|
||||
self.admin_context, zone['id'],
|
||||
other_recordset['id'],
|
||||
expected['id'])
|
||||
|
||||
# Ensure we get a 404 if we use the incorrect recordset_id
|
||||
with testtools.ExpectedException(exceptions.RecordNotFound):
|
||||
self.central_service.get_record(
|
||||
self.admin_context, zone['id'], other_recordset['id'],
|
||||
expected['id'])
|
||||
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
|
||||
|
||||
def test_find_records(self):
|
||||
zone = self.create_zone()
|
||||
@@ -2162,8 +2227,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
record.zone_id = other_zone.id
|
||||
|
||||
# Ensure we get a BadRequest if we change the zone_id
|
||||
with testtools.ExpectedException(exceptions.BadRequest):
|
||||
self.central_service.update_record(self.admin_context, record)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.update_record,
|
||||
self.admin_context, record)
|
||||
|
||||
self.assertEqual(exceptions.BadRequest, exc.exc_info[0])
|
||||
|
||||
def test_update_record_immutable_recordset_id(self):
|
||||
zone = self.create_zone()
|
||||
@@ -2177,8 +2245,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
record.recordset_id = other_recordset.id
|
||||
|
||||
# Ensure we get a BadRequest if we change the recordset_id
|
||||
with testtools.ExpectedException(exceptions.BadRequest):
|
||||
self.central_service.update_record(self.admin_context, record)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.update_record,
|
||||
self.admin_context, record)
|
||||
|
||||
self.assertEqual(exceptions.BadRequest, exc.exc_info[0])
|
||||
|
||||
def test_delete_record(self):
|
||||
zone = self.create_zone()
|
||||
@@ -2260,10 +2331,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
record = self.create_record(zone, recordset)
|
||||
|
||||
# Ensure we get a 404 if we use the incorrect zone_id
|
||||
with testtools.ExpectedException(exceptions.RecordNotFound):
|
||||
self.central_service.delete_record(
|
||||
self.admin_context, other_zone['id'], recordset['id'],
|
||||
record['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.delete_record,
|
||||
self.admin_context, other_zone['id'],
|
||||
recordset['id'],
|
||||
record['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
|
||||
|
||||
def test_delete_record_incorrect_recordset_id(self):
|
||||
zone = self.create_zone()
|
||||
@@ -2274,10 +2348,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
record = self.create_record(zone, recordset)
|
||||
|
||||
# Ensure we get a 404 if we use the incorrect recordset_id
|
||||
with testtools.ExpectedException(exceptions.RecordNotFound):
|
||||
self.central_service.delete_record(
|
||||
self.admin_context, zone['id'], other_recordset['id'],
|
||||
record['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.delete_record,
|
||||
self.admin_context, zone['id'],
|
||||
other_recordset['id'],
|
||||
record['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
|
||||
|
||||
def test_count_records(self):
|
||||
# in the beginning, there should be nothing
|
||||
@@ -2299,8 +2376,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
# Set the policy to reject the authz
|
||||
self.policy({'count_records': '!'})
|
||||
|
||||
with testtools.ExpectedException(exceptions.Forbidden):
|
||||
self.central_service.count_records(self.get_context())
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.count_records,
|
||||
self.get_context())
|
||||
|
||||
self.assertEqual(exceptions.Forbidden, exc.exc_info[0])
|
||||
|
||||
def test_get_floatingip_no_record(self):
|
||||
context = self.get_context(tenant='a')
|
||||
@@ -2351,9 +2431,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
fip = self.network_api.fake.allocate_floatingip(context.tenant)
|
||||
self.network_api.fake.deallocate_floatingip(fip['id'])
|
||||
|
||||
with testtools.ExpectedException(exceptions.NotFound):
|
||||
self.central_service.get_floatingip(
|
||||
context, fip['region'], fip['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_floatingip,
|
||||
context, fip['region'], fip['id'])
|
||||
|
||||
self.assertEqual(exceptions.NotFound, exc.exc_info[0])
|
||||
|
||||
def test_get_floatingip_deallocated_and_invalidate(self):
|
||||
context_a = self.get_context(tenant='a')
|
||||
@@ -2384,9 +2466,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
self.network_api.fake.deallocate_floatingip(fip['id'])
|
||||
|
||||
with testtools.ExpectedException(exceptions.NotFound):
|
||||
self.central_service.get_floatingip(
|
||||
context_a, fip['region'], fip['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_floatingip,
|
||||
context_a, fip['region'], fip['id'])
|
||||
|
||||
self.assertEqual(exceptions.NotFound, exc.exc_info[0])
|
||||
|
||||
# Ensure that the record is still in DB (No invalidation)
|
||||
self.central_service.find_record(elevated_a, criterion)
|
||||
@@ -2408,8 +2492,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
# Ensure that the old record for tenant a for the fip now owned by
|
||||
# tenant b is gone
|
||||
with testtools.ExpectedException(exceptions.RecordNotFound):
|
||||
self.central_service.find_record(elevated_a, criterion)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.find_record,
|
||||
elevated_a, criterion)
|
||||
|
||||
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
|
||||
|
||||
def test_list_floatingips_no_allocations(self):
|
||||
context = self.get_context(tenant='a')
|
||||
@@ -2481,7 +2568,7 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.network_api.fake.deallocate_floatingip(fip['id'])
|
||||
|
||||
fips = self.central_service.list_floatingips(context_a)
|
||||
assert(len(fips) == 0)
|
||||
self.assertEqual(len(fips), 0)
|
||||
|
||||
# Ensure that the record is still in DB (No invalidation)
|
||||
self.central_service.find_record(elevated_a, criterion)
|
||||
@@ -2503,8 +2590,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
# Ensure that the old record for tenant a for the fip now owned by
|
||||
# tenant b is gone
|
||||
with testtools.ExpectedException(exceptions.RecordNotFound):
|
||||
self.central_service.find_record(elevated_a, criterion)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.find_record,
|
||||
elevated_a, criterion)
|
||||
|
||||
self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0])
|
||||
|
||||
def test_set_floatingip(self):
|
||||
context = self.get_context(tenant='a')
|
||||
@@ -2609,9 +2699,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
|
||||
# If one attempts to assign a de-allocated FIP or not-owned it should
|
||||
# fail with BadRequest
|
||||
with testtools.ExpectedException(exceptions.NotFound):
|
||||
fixture = self.central_service.update_floatingip(
|
||||
context, fip['region'], fip['id'], fixture)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.update_floatingip,
|
||||
context, fip['region'], fip['id'], fixture)
|
||||
|
||||
self.assertEqual(exceptions.NotFound, exc.exc_info[0])
|
||||
|
||||
def test_unset_floatingip(self):
|
||||
context = self.get_context(tenant='a')
|
||||
@@ -2726,9 +2818,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
blacklist['id'])
|
||||
|
||||
# Try to fetch the blacklist to verify an exception is raised
|
||||
with testtools.ExpectedException(exceptions.BlacklistNotFound):
|
||||
self.central_service.get_blacklist(self.admin_context,
|
||||
blacklist['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_blacklist,
|
||||
self.admin_context,
|
||||
blacklist['id']
|
||||
)
|
||||
|
||||
self.assertEqual(exceptions.BlacklistNotFound, exc.exc_info[0])
|
||||
|
||||
# SOA recordset tests
|
||||
def test_create_SOA(self):
|
||||
@@ -3005,8 +3101,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.central_service.delete_pool(self.admin_context, pool['id'])
|
||||
|
||||
# Verify that the pool has been deleted
|
||||
with testtools.ExpectedException(exceptions.PoolNotFound):
|
||||
self.central_service.get_pool(self.admin_context, pool['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_pool,
|
||||
self.admin_context, pool['id'])
|
||||
|
||||
self.assertEqual(exceptions.PoolNotFound, exc.exc_info[0])
|
||||
|
||||
def test_update_status_delete_zone(self):
|
||||
# Create a zone
|
||||
@@ -3029,8 +3128,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.admin_context, zone['id'], "SUCCESS", zone_serial)
|
||||
|
||||
# Fetch the zone again, ensuring an exception is raised
|
||||
with testtools.ExpectedException(exceptions.ZoneNotFound):
|
||||
self.central_service.get_zone(self.admin_context, zone['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_zone,
|
||||
self.admin_context, zone['id'])
|
||||
|
||||
self.assertEqual(exceptions.ZoneNotFound, exc.exc_info[0])
|
||||
|
||||
def test_update_status_delete_last_record(self):
|
||||
zone = self.create_zone()
|
||||
@@ -3050,10 +3152,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.admin_context, zone['id'], "SUCCESS", zone_serial)
|
||||
|
||||
# Fetch the record again, ensuring an exception is raised
|
||||
with testtools.ExpectedException(exceptions.RecordSetNotFound):
|
||||
self.central_service.get_record(
|
||||
self.admin_context, zone['id'], recordset['id'],
|
||||
record['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_record,
|
||||
self.admin_context, zone['id'],
|
||||
recordset['id'],
|
||||
record['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0])
|
||||
|
||||
@mock.patch.object(notifier.Notifier, "info")
|
||||
def test_update_status_send_notification(self, mock_notifier):
|
||||
@@ -3114,10 +3219,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.admin_context, zone['id'], "SUCCESS", zone_serial)
|
||||
|
||||
# Fetch the record again, ensuring an exception is raised
|
||||
with testtools.ExpectedException(exceptions.RecordSetNotFound):
|
||||
self.central_service.get_record(
|
||||
self.admin_context, zone['id'], recordset['id'],
|
||||
record['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_record,
|
||||
self.admin_context, zone['id'],
|
||||
recordset['id'], record['id'])
|
||||
|
||||
self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0])
|
||||
|
||||
# Ensure the zones serial number was not updated
|
||||
new_zone_serial = self.central_service.get_zone(
|
||||
@@ -3180,9 +3287,14 @@ class CentralServiceTest(CentralTestCase):
|
||||
def test_create_zone_transfer_request_duplicate(self):
|
||||
zone = self.create_zone()
|
||||
self.create_zone_transfer_request(zone)
|
||||
with testtools.ExpectedException(
|
||||
exceptions.DuplicateZoneTransferRequest):
|
||||
self.create_zone_transfer_request(zone)
|
||||
|
||||
exc = self.assertRaises(
|
||||
rpc_dispatcher.ExpectedException,
|
||||
self.create_zone_transfer_request,
|
||||
zone)
|
||||
|
||||
self.assertEqual(exceptions.DuplicateZoneTransferRequest,
|
||||
exc.exc_info[0])
|
||||
|
||||
def test_create_scoped_zone_transfer_request(self):
|
||||
zone = self.create_zone()
|
||||
@@ -3225,9 +3337,11 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.central_service.get_zone_transfer_request(
|
||||
tenant_1_context, zt_request.id)
|
||||
|
||||
with testtools.ExpectedException(exceptions.Forbidden):
|
||||
self.central_service.get_zone_transfer_request(
|
||||
tenant_3_context, zt_request.id)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_zone_transfer_request,
|
||||
tenant_3_context, zt_request.id)
|
||||
|
||||
self.assertEqual(exceptions.Forbidden, exc.exc_info[0])
|
||||
|
||||
def test_update_zone_transfer_request(self):
|
||||
zone = self.create_zone()
|
||||
@@ -3250,11 +3364,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.central_service.delete_zone_transfer_request(
|
||||
self.admin_context, zone_transfer_request.id)
|
||||
|
||||
with testtools.ExpectedException(
|
||||
exceptions.ZoneTransferRequestNotFound):
|
||||
self.central_service.get_zone_transfer_request(
|
||||
self.admin_context,
|
||||
zone_transfer_request.id)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_zone_transfer_request,
|
||||
self.admin_context,
|
||||
zone_transfer_request.id)
|
||||
|
||||
self.assertEqual(exceptions.ZoneTransferRequestNotFound,
|
||||
exc.exc_info[0])
|
||||
|
||||
def test_create_zone_transfer_accept(self):
|
||||
tenant_1_context = self.get_context(tenant=1)
|
||||
@@ -3380,10 +3496,12 @@ class CentralServiceTest(CentralTestCase):
|
||||
zone_transfer_accept.key = 'WRONG KEY'
|
||||
zone_transfer_accept.zone_id = zone.id
|
||||
|
||||
with testtools.ExpectedException(exceptions.IncorrectZoneTransferKey):
|
||||
zone_transfer_accept = \
|
||||
self.central_service.create_zone_transfer_accept(
|
||||
tenant_2_context, zone_transfer_accept)
|
||||
exc = self.assertRaises(
|
||||
rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_zone_transfer_accept,
|
||||
tenant_2_context, zone_transfer_accept)
|
||||
|
||||
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)
|
||||
@@ -3405,10 +3523,13 @@ class CentralServiceTest(CentralTestCase):
|
||||
zone_transfer_accept.key = zone_transfer_request.key
|
||||
zone_transfer_accept.zone_id = zone.id
|
||||
|
||||
with testtools.ExpectedException(exceptions.Forbidden):
|
||||
zone_transfer_accept = \
|
||||
self.central_service.create_zone_transfer_accept(
|
||||
tenant_3_context, zone_transfer_accept)
|
||||
exc = self.assertRaises(
|
||||
rpc_dispatcher.ExpectedException,
|
||||
self.central_service.create_zone_transfer_accept,
|
||||
tenant_3_context, zone_transfer_accept
|
||||
)
|
||||
|
||||
self.assertEqual(exceptions.Forbidden, exc.exc_info[0])
|
||||
|
||||
# Zone Import Tests
|
||||
def test_create_zone_import(self):
|
||||
@@ -3517,7 +3638,8 @@ class CentralServiceTest(CentralTestCase):
|
||||
zone_import['id'])
|
||||
|
||||
# Fetch the zone_import again, ensuring an exception is raised
|
||||
self.assertRaises(
|
||||
exceptions.ZoneImportNotFound,
|
||||
self.central_service.get_zone_import,
|
||||
context, zone_import['id'])
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.central_service.get_zone_import,
|
||||
context, zone_import['id'])
|
||||
|
||||
self.assertEqual(exceptions.ZoneImportNotFound, exc.exc_info[0])
|
||||
|
||||
@@ -19,6 +19,7 @@ import mock
|
||||
import testtools
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_messaging.rpc import dispatcher as rpc_dispatcher
|
||||
|
||||
from designate import exceptions
|
||||
from designate import objects
|
||||
@@ -375,8 +376,11 @@ class StorageTestCase(object):
|
||||
values = self.get_tsigkey_fixture(1)
|
||||
values['name'] = tsigkey_one['name']
|
||||
|
||||
with testtools.ExpectedException(exceptions.DuplicateTsigKey):
|
||||
self.create_tsigkey(**values)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_tsigkey,
|
||||
**values)
|
||||
|
||||
self.assertEqual(exceptions.DuplicateTsigKey, exc.exc_info[0])
|
||||
|
||||
def test_find_tsigkeys(self):
|
||||
actual = self.storage.find_tsigkeys(self.admin_context)
|
||||
@@ -599,8 +603,10 @@ class StorageTestCase(object):
|
||||
# Create the Initial Zone
|
||||
self.create_zone()
|
||||
|
||||
with testtools.ExpectedException(exceptions.DuplicateZone):
|
||||
self.create_zone()
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_zone)
|
||||
|
||||
self.assertEqual(exceptions.DuplicateZone, exc.exc_info[0])
|
||||
|
||||
def test_find_zones(self):
|
||||
self.config(quota_zones=20)
|
||||
@@ -880,9 +886,11 @@ class StorageTestCase(object):
|
||||
# Create the First RecordSet
|
||||
self.create_recordset(zone)
|
||||
|
||||
with testtools.ExpectedException(exceptions.DuplicateRecordSet):
|
||||
# Attempt to create the second/duplicate recordset
|
||||
self.create_recordset(zone)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_recordset,
|
||||
zone)
|
||||
|
||||
self.assertEqual(exceptions.DuplicateRecordSet, exc.exc_info[0])
|
||||
|
||||
def test_create_recordset_with_records(self):
|
||||
zone = self.create_zone()
|
||||
@@ -1308,9 +1316,11 @@ class StorageTestCase(object):
|
||||
# Create the First Record
|
||||
self.create_record(zone, recordset)
|
||||
|
||||
with testtools.ExpectedException(exceptions.DuplicateRecord):
|
||||
# Attempt to create the second/duplicate record
|
||||
self.create_record(zone, recordset)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_record,
|
||||
zone, recordset)
|
||||
|
||||
self.assertEqual(exceptions.DuplicateRecord, exc.exc_info[0])
|
||||
|
||||
def test_find_records(self):
|
||||
zone = self.create_zone()
|
||||
@@ -1603,9 +1613,11 @@ class StorageTestCase(object):
|
||||
# Create the First Tld
|
||||
self.create_tld(fixture=0)
|
||||
|
||||
with testtools.ExpectedException(exceptions.DuplicateTld):
|
||||
# Attempt to create the second/duplicate Tld
|
||||
self.create_tld(fixture=0)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_tld,
|
||||
fixture=0)
|
||||
|
||||
self.assertEqual(exceptions.DuplicateTld, exc.exc_info[0])
|
||||
|
||||
def test_find_tlds(self):
|
||||
|
||||
@@ -1759,8 +1771,11 @@ class StorageTestCase(object):
|
||||
# Create the initial Blacklist
|
||||
self.create_blacklist(fixture=0)
|
||||
|
||||
with testtools.ExpectedException(exceptions.DuplicateBlacklist):
|
||||
self.create_blacklist(fixture=0)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_blacklist,
|
||||
fixture=0)
|
||||
|
||||
self.assertEqual(exceptions.DuplicateBlacklist, exc.exc_info[0])
|
||||
|
||||
def test_find_blacklists(self):
|
||||
# Verify that there are no blacklists created
|
||||
@@ -1935,8 +1950,11 @@ class StorageTestCase(object):
|
||||
self.create_pool(fixture=0)
|
||||
|
||||
# Create the second pool and should get exception
|
||||
with testtools.ExpectedException(exceptions.DuplicatePool):
|
||||
self.create_pool(fixture=0)
|
||||
exc = self.assertRaises(rpc_dispatcher.ExpectedException,
|
||||
self.create_pool,
|
||||
fixture=0)
|
||||
|
||||
self.assertEqual(exceptions.DuplicatePool, exc.exc_info[0])
|
||||
|
||||
def test_find_pools(self):
|
||||
# Verify that there are no pools, except for default pool
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,7 @@ import oslo_messaging as messaging
|
||||
|
||||
from designate import backend
|
||||
from designate import exceptions
|
||||
from designate import rpc
|
||||
from designate import service
|
||||
from designate import storage
|
||||
from designate.central import rpcapi as central_api
|
||||
@@ -141,6 +142,7 @@ class Service(service.RPCService, service.Service):
|
||||
notify_target))
|
||||
return self.executor.run(all_tasks)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def create_zone(self, context, zone):
|
||||
"""
|
||||
:param context: Security context information.
|
||||
@@ -149,6 +151,7 @@ class Service(service.RPCService, service.Service):
|
||||
"""
|
||||
self._do_zone_action(context, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def update_zone(self, context, zone):
|
||||
"""
|
||||
:param context: Security context information.
|
||||
@@ -157,6 +160,7 @@ class Service(service.RPCService, service.Service):
|
||||
"""
|
||||
self._do_zone_action(context, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def delete_zone(self, context, zone):
|
||||
"""
|
||||
:param context: Security context information.
|
||||
@@ -165,6 +169,7 @@ class Service(service.RPCService, service.Service):
|
||||
"""
|
||||
self._do_zone_action(context, zone)
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def recover_shard(self, context, begin, end):
|
||||
"""
|
||||
:param begin: the beginning of the shards to recover
|
||||
@@ -175,6 +180,7 @@ class Service(service.RPCService, service.Service):
|
||||
self.executor, context, begin, end
|
||||
))
|
||||
|
||||
@rpc.expected_exceptions()
|
||||
def start_zone_export(self, context, zone, export):
|
||||
"""
|
||||
:param zone: Zone to be exported
|
||||
|
||||
Reference in New Issue
Block a user