Commit c5949ccb authored by Graham Hayes's avatar Graham Hayes

Rename all references of Domain to Zone

This is a pretty invasive change :)

A non complete list of changes:

* Database Tables
* Database Columns
* Designate Objects and fields on Objects
* Designate Objects Adaptors stop doing some of the renames
* All RPCAPI versions are bumped - totally backward
  incompatable (function names have changed)

Change-Id: Ib99e918998a3909fa4aa92bf1ee0475f8a519196
parent 3e9ec422
......@@ -213,11 +213,11 @@ class IPABackend(base.Backend):
self.ntries = cfg.CONF[self.name].ipa_connect_retries
self.force = cfg.CONF[self.name].ipa_force_ns_use
def create_domain(self, context, domain):
LOG.debug('Create Domain %r' % domain)
def create_zone(self, context, zone):
LOG.debug('Create Zone %r' % zone)
ipareq = {'method': 'dnszone_add', 'id': 0}
params = [domain['name']]
servers = self.central_service.get_domain_servers(self.admin_context)
params = [zone['name']]
servers = self.central_service.get_zone_ns_records(self.admin_context)
# just use the first one for zone creation - add the others
# later, below - use force because designate assumes the NS
# already exists somewhere, is resolvable, and already has
......@@ -226,35 +226,35 @@ class IPABackend(base.Backend):
if self.force:
args['force'] = True
for dkey, ipakey in list(domain2ipa.items()):
if dkey in domain:
args[ipakey] = domain[dkey]
if dkey in zone:
args[ipakey] = zone[dkey]
ipareq['params'] = [params, args]
self._call_and_handle_error(ipareq)
# add NS records for all of the other servers
if len(servers) > 1:
ipareq = {'method': 'dnsrecord_add', 'id': 0}
params = [domain['name'], "@"]
params = [zone['name'], "@"]
args = {'nsrecord': servers[1:]}
if self.force:
args['force'] = True
ipareq['params'] = [params, args]
self._call_and_handle_error(ipareq)
def update_domain(self, context, domain):
LOG.debug('Update Domain %r' % domain)
def update_zone(self, context, zone):
LOG.debug('Update Zone %r' % zone)
ipareq = {'method': 'dnszone_mod', 'id': 0}
params = [domain['name']]
params = [zone['name']]
args = {}
for dkey, ipakey in list(domain2ipa.items()):
if dkey in domain:
args[ipakey] = domain[dkey]
if dkey in zone:
args[ipakey] = zone[dkey]
ipareq['params'] = [params, args]
self._call_and_handle_error(ipareq)
def delete_domain(self, context, domain):
LOG.debug('Delete Domain %r' % domain)
def delete_zone(self, context, zone):
LOG.debug('Delete Zone %r' % zone)
ipareq = {'method': 'dnszone_del', 'id': 0}
params = [domain['name']]
params = [zone['name']]
args = {}
ipareq['params'] = [params, args]
self._call_and_handle_error(ipareq)
......
......@@ -97,54 +97,54 @@ class MultiBackend(base.Backend):
with excutils.save_and_reraise_exception():
self.slave.create_tsigkey(context, tsigkey)
def create_domain(self, context, domain):
self.master.create_domain(context, domain)
def create_zone(self, context, zone):
self.master.create_zone(context, zone)
try:
self.slave.create_domain(context, domain)
self.slave.create_zone(context, zone)
except Exception:
with excutils.save_and_reraise_exception():
self.master.delete_domain(context, domain)
self.master.delete_zone(context, zone)
def update_domain(self, context, domain):
self.master.update_domain(context, domain)
def update_zone(self, context, zone):
self.master.update_zone(context, zone)
def delete_domain(self, context, domain):
# Fetch the full domain from Central first, as we may
def delete_zone(self, context, zone):
# Fetch the full zone from Central first, as we may
# have to recreate it on slave if delete on master fails
deleted_context = context.deepcopy()
deleted_context.show_deleted = True
full_domain = self.central.find_domain(
deleted_context, {'id': domain['id']})
full_domain = self.central.find_zone(
deleted_context, {'id': zone['id']})
self.slave.delete_domain(context, domain)
self.slave.delete_zone(context, zone)
try:
self.master.delete_domain(context, domain)
self.master.delete_zone(context, zone)
except Exception:
with excutils.save_and_reraise_exception():
self.slave.create_domain(context, domain)
self.slave.create_zone(context, zone)
[self.slave.create_record(context, domain, record)
[self.slave.create_record(context, zone, record)
for record in self.central.find_records(
context, {'domain_id': full_domain['id']})]
def create_recordset(self, context, domain, recordset):
self.master.create_recordset(context, domain, recordset)
def create_recordset(self, context, zone, recordset):
self.master.create_recordset(context, zone, recordset)
def update_recordset(self, context, domain, recordset):
self.master.update_recordset(context, domain, recordset)
def update_recordset(self, context, zone, recordset):
self.master.update_recordset(context, zone, recordset)
def delete_recordset(self, context, domain, recordset):
self.master.delete_recordset(context, domain, recordset)
def delete_recordset(self, context, zone, recordset):
self.master.delete_recordset(context, zone, recordset)
def create_record(self, context, domain, recordset, record):
self.master.create_record(context, domain, recordset, record)
def create_record(self, context, zone, recordset, record):
self.master.create_record(context, zone, recordset, record)
def update_record(self, context, domain, recordset, record):
self.master.update_record(context, domain, recordset, record)
def update_record(self, context, zone, recordset, record):
self.master.update_record(context, zone, recordset, record)
def delete_record(self, context, domain, recordset, record):
self.master.delete_record(context, domain, recordset, record)
def delete_record(self, context, zone, recordset, record):
self.master.delete_record(context, zone, recordset, record)
def ping(self, context):
return {
......
......@@ -242,7 +242,7 @@ def main():
# create a fake domain in IPA
# create a fake server in Designate
# try to create the same fake domain in Designate
# if we get a DuplicateDomain error from Designate, then
# if we get a DuplicateZone error from Designate, then
# raise the CannotUseIPABackend error, after deleting
# the fake server and fake domain
# find the first non-reverse zone
......
......@@ -305,7 +305,7 @@ ComputeAdminGroup = [
help="API key to use when authenticating as admin.",
secret=True),
cfg.StrOpt('domain_name',
help="Domain name for authentication as admin (Keystone V3)."
help="Zone name for authentication as admin (Keystone V3)."
"The same domain applies to user and project"),
]
......
......@@ -39,13 +39,13 @@ class DomainsClientJSON(rest_client.RestClient):
"""Get the details of a domain."""
resp, body = self.get("v1/domains/%s" % str(domain_id))
body = json.loads(body)
self.validate_response(schema.get_domain, resp, body)
self.validate_response(schema.get_zone, resp, body)
return resp, body
def delete_domain(self, domain_id):
"""Delete the given domain."""
resp, body = self.delete("v1/domains/%s" % str(domain_id))
self.validate_response(schema.delete_domain, resp, body)
self.validate_response(schema.delete_zone, resp, body)
return resp, body
def create_domain(self, name, email, **kwargs):
......@@ -61,7 +61,7 @@ class DomainsClientJSON(rest_client.RestClient):
post_body[post_param] = value
resp, body = self.post('v1/domains', json.dumps(post_body))
body = json.loads(body)
self.validate_response(schema.create_domain, resp, body)
self.validate_response(schema.create_zone, resp, body)
return resp, body
def update_domain(self, domain_id, **kwargs):
......@@ -75,5 +75,5 @@ class DomainsClientJSON(rest_client.RestClient):
resp, body = self.put('v1/domains/%s' % domain_id,
json.dumps(post_body))
body = json.loads(body)
self.validate_response(schema.update_domain, resp, body)
self.validate_response(schema.update_zone, resp, body)
return resp, body
......@@ -30,19 +30,19 @@ class DnsDomainsTest(base.BaseDnsTest):
for i in range(2):
name = data_utils.rand_name('domain') + '.com.'
email = data_utils.rand_name('dns') + '@testmail.com'
_, domain = cls.client.create_domain(name, email)
_, domain = cls.client.create_zone(name, email)
cls.setup_domains.append(domain)
@classmethod
def tearDownClass(cls):
for domain in cls.setup_domains:
cls.client.delete_domain(domain['id'])
cls.client.delete_zone(domain['id'])
super(DnsDomainsTest, cls).tearDownClass()
def _delete_domain(self, domain_id):
self.client.delete_domain(domain_id)
self.client.delete_zone(domain_id)
self.assertRaises(exceptions.NotFound,
self.client.get_domain, domain_id)
self.client.get_zone, domain_id)
@test.attr(type='gate')
def test_list_domains(self):
......@@ -54,20 +54,20 @@ class DnsDomainsTest(base.BaseDnsTest):
@test.attr(type='smoke')
def test_create_update_get_domain(self):
# Create Domain
# Create Zone
d_name = data_utils.rand_name('domain') + '.com.'
d_email = data_utils.rand_name('dns') + '@testmail.com'
_, domain = self.client.create_domain(name=d_name, email=d_email)
_, domain = self.client.create_zone(name=d_name, email=d_email)
self.addCleanup(self._delete_domain, domain['id'])
self.assertEqual(d_name, domain['name'])
self.assertEqual(d_email, domain['email'])
# Update Domain with ttl
# Update Zone with ttl
d_ttl = 3600
_, update_domain = self.client.update_domain(domain['id'],
ttl=d_ttl)
_, update_domain = self.client.update_zone(domain['id'],
ttl=d_ttl)
self.assertEqual(d_ttl, update_domain['ttl'])
# Get the details of Domain
_, get_domain = self.client.get_domain(domain['id'])
# Get the details of Zone
_, get_domain = self.client.get_zone(domain['id'])
self.assertEqual(update_domain['name'], get_domain['name'])
self.assertEqual(update_domain['email'], get_domain['email'])
self.assertEqual(update_domain['ttl'], get_domain['ttl'])
......@@ -30,7 +30,7 @@ class RecordsTest(base.BaseDnsTest):
cls.setup_records = list()
name = data_utils.rand_name('domain') + '.com.'
email = data_utils.rand_name('dns') + '@testmail.com'
_, cls.domain = cls.dns_domains_client.create_domain(name, email)
_, cls.domain = cls.dns_domains_client.create_zone(name, email)
# Creates a record with type as A
r_name = 'www.' + name
data1 = "192.0.2.3"
......@@ -49,7 +49,7 @@ class RecordsTest(base.BaseDnsTest):
def tearDownClass(cls):
for record in cls.setup_records:
cls.client.delete_record(cls.domain['id'], record['id'])
cls.dns_domains_client.delete_domain(cls.domain['id'])
cls.dns_domains_client.delete_zone(cls.domain['id'])
def _delete_record(self, domain_id, record_id):
self.client.delete_record(domain_id, record_id)
......@@ -66,11 +66,11 @@ class RecordsTest(base.BaseDnsTest):
@test.attr(type='smoke')
def test_create_update_get_delete_record(self):
# Create Domain
# Create Zone
name = data_utils.rand_name('domain') + '.com.'
email = data_utils.rand_name('dns') + '@testmail.com'
_, domain = self.dns_domains_client.create_domain(name, email)
self.addCleanup(self.dns_domains_client.delete_domain, domain['id'])
_, domain = self.dns_domains_client.create_zone(name, email)
self.addCleanup(self.dns_domains_client.delete_zone, domain['id'])
# Create Record
r_name = 'www.' + name
r_data = "192.0.2.4"
......
......@@ -108,28 +108,28 @@ class RequestHandler(object):
question = request.question[0]
requester = request.environ['addr'][0]
domain_name = question.name.to_text()
zone_name = question.name.to_text()
if not self._allowed(request, requester, "CREATE", domain_name):
if not self._allowed(request, requester, "CREATE", zone_name):
response.set_rcode(dns.rcode.from_text("REFUSED"))
return response
serial = self.backend.find_domain_serial(domain_name)
serial = self.backend.find_zone_serial(zone_name)
if serial is not None:
LOG.warn(_LW("Not creating %(name)s, zone already exists") %
{'name': domain_name})
{'name': zone_name})
# Provide an authoritative answer
response.flags |= dns.flags.AA
return response
LOG.debug("Received %(verb)s for %(name)s from %(host)s" %
{'verb': "CREATE", 'name': domain_name, 'host': requester})
{'verb': "CREATE", 'name': zone_name, 'host': requester})
try:
zone = dnsutils.do_axfr(domain_name, self.masters,
zone = dnsutils.do_axfr(zone_name, self.masters,
source=self.transfer_source)
self.backend.create_domain(zone)
self.backend.create_zone(zone)
except Exception:
response.set_rcode(dns.rcode.from_text("SERVFAIL"))
return response
......@@ -152,35 +152,35 @@ class RequestHandler(object):
question = request.question[0]
requester = request.environ['addr'][0]
domain_name = question.name.to_text()
zone_name = question.name.to_text()
if not self._allowed(request, requester, "NOTIFY", domain_name):
if not self._allowed(request, requester, "NOTIFY", zone_name):
response.set_rcode(dns.rcode.from_text("REFUSED"))
return response
serial = self.backend.find_domain_serial(domain_name)
serial = self.backend.find_zone_serial(zone_name)
if serial is None:
LOG.warn(_LW("Refusing NOTIFY for %(name)s, doesn't exist") %
{'name': domain_name})
{'name': zone_name})
response.set_rcode(dns.rcode.from_text("REFUSED"))
return response
LOG.debug("Received %(verb)s for %(name)s from %(host)s" %
{'verb': "NOTIFY", 'name': domain_name, 'host': requester})
{'verb': "NOTIFY", 'name': zone_name, 'host': requester})
# According to RFC we should query the server that sent the NOTIFY
# TODO(Tim): Reenable this when it makes more sense
# resolver = dns.resolver.Resolver()
# resolver.nameservers = [requester]
# This assumes that the Master is running on port 53
# soa_answer = resolver.query(domain_name, 'SOA')
# soa_answer = resolver.query(zone_name, 'SOA')
# Check that the serial is < serial above
try:
zone = dnsutils.do_axfr(domain_name, self.masters,
zone = dnsutils.do_axfr(zone_name, self.masters,
source=self.transfer_source)
self.backend.update_domain(zone)
self.backend.update_zone(zone)
except Exception:
response.set_rcode(dns.rcode.from_text("SERVFAIL"))
return response
......@@ -203,44 +203,44 @@ class RequestHandler(object):
question = request.question[0]
requester = request.environ['addr'][0]
domain_name = question.name.to_text()
zone_name = question.name.to_text()
if not self._allowed(request, requester, "DELETE", domain_name):
if not self._allowed(request, requester, "DELETE", zone_name):
response.set_rcode(dns.rcode.from_text("REFUSED"))
return response
serial = self.backend.find_domain_serial(domain_name)
serial = self.backend.find_zone_serial(zone_name)
if serial is None:
LOG.warn(_LW("Not deleting %(name)s, zone doesn't exist") %
{'name': domain_name})
{'name': zone_name})
# Provide an authoritative answer
response.flags |= dns.flags.AA
return response
LOG.debug("Received DELETE for %(name)s from %(host)s" %
{'name': domain_name, 'host': requester})
{'name': zone_name, 'host': requester})
# Provide an authoritative answer
response.flags |= dns.flags.AA
# Call into the backend to Delete
try:
self.backend.delete_domain(domain_name)
self.backend.delete_zone(zone_name)
except Exception:
response.set_rcode(dns.rcode.from_text("SERVFAIL"))
return response
return response
def _allowed(self, request, requester, op, domain_name):
def _allowed(self, request, requester, op, zone_name):
# If there are no explict notifiers specified, allow all
if not self.allow_notify:
return True
if requester not in self.allow_notify:
LOG.warn(_LW("%(verb)s for %(name)s from %(server)s refused") %
{'verb': op, 'name': domain_name, 'server': requester})
{'verb': op, 'name': zone_name, 'server': requester})
return False
return True
......@@ -33,7 +33,7 @@ class BaseView(object):
as part of the API call.
For example, in the V2 API, we did s/domain/zone/. Adapting a record
resources "domain_id" <-> "zone_id" is the responsibility of a View.
resources "tenant_id" <-> "project_id" is the responsibility of a View.
"""
_resource_name = None
_collection_name = None
......
......@@ -30,24 +30,15 @@ class QuotasView(base_view.BaseView):
def show_basic(self, context, request, quota):
"""Basic view of a quota"""
return {
"zones": quota['domains'],
"zone_records": quota['domain_records'],
"zone_recordsets": quota['domain_recordsets'],
"zones": quota['zones'],
"zone_records": quota['zone_records'],
"zone_recordsets": quota['zone_recordsets'],
"recordset_records": quota['recordset_records']
}
def load(self, context, request, body):
"""Extract a "central" compatible dict from an API call"""
valid_keys = ('domain_records', 'domain_recordsets', 'domains',
valid_keys = ('zone_records', 'zone_recordsets', 'zones',
'recordset_records')
mapping = {
'zones': 'domains',
'zone_records': 'domain_records',
'zone_recordsets': 'domain_recordsets',
'recordset_records': 'recordset_records'
}
body["quota"] = {mapping[k]: body["quota"][k] for k in body["quota"]}
return self._load(context, request, body, valid_keys)
......@@ -51,7 +51,7 @@ class TenantsView(base_view.BaseView):
"""Basic view of the Tenants Report"""
return {
"zone_count": tenants['domain_count'],
"zone_count": tenants['zone_count'],
"id": tenants['id'],
"links": self._get_resource_links(request, tenants)
}
......@@ -60,8 +60,8 @@ class TenantsView(base_view.BaseView):
"""Detail view of the Tenants Report"""
return {
"zones_count": tenant['domain_count'],
"zones": tenant['domains'],
"zones_count": tenant['zone_count'],
"zones": tenant['zones'],
"id": tenant['id'],
"links": self._get_resource_links(request, tenant)
}
......@@ -65,7 +65,7 @@ def create_domain():
# A V1 zone only supports being a primary (No notion of a type)
values['type'] = 'PRIMARY'
domain = central_api.create_domain(context, objects.Domain(**values))
domain = central_api.create_zone(context, objects.Zone(**values))
response = flask.jsonify(domain_schema.filter(domain))
response.status_int = 201
......@@ -80,7 +80,7 @@ def get_domains():
central_api = central_rpcapi.CentralAPI.get_instance()
domains = central_api.find_domains(context, criterion={"type": "PRIMARY"})
domains = central_api.find_zones(context, criterion={"type": "PRIMARY"})
return flask.jsonify(domains_schema.filter({'domains': domains}))
......@@ -92,7 +92,7 @@ def get_domain(domain_id):
central_api = central_rpcapi.CentralAPI.get_instance()
criterion = {"id": domain_id, "type": "PRIMARY"}
domain = central_api.find_domain(context, criterion=criterion)
domain = central_api.find_zone(context, criterion=criterion)
return flask.jsonify(domain_schema.filter(domain))
......@@ -106,7 +106,7 @@ def update_domain(domain_id):
# Fetch the existing resource
criterion = {"id": domain_id, "type": "PRIMARY"}
domain = central_api.find_domain(context, criterion=criterion)
domain = central_api.find_zone(context, criterion=criterion)
# Prepare a dict of fields for validation
domain_data = domain_schema.filter(domain)
......@@ -117,7 +117,7 @@ def update_domain(domain_id):
# Update and persist the resource
domain.update(values)
domain = central_api.update_domain(context, domain)
domain = central_api.update_zone(context, domain)
return flask.jsonify(domain_schema.filter(domain))
......@@ -130,9 +130,9 @@ def delete_domain(domain_id):
# TODO(ekarlso): Fix this to something better.
criterion = {"id": domain_id, "type": "PRIMARY"}
central_api.find_domain(context, criterion=criterion)
central_api.find_zone(context, criterion=criterion)
central_api.delete_domain(context, domain_id)
central_api.delete_zone(context, domain_id)
return flask.Response(status=200)
......@@ -145,9 +145,9 @@ def get_domain_servers(domain_id):
# TODO(ekarlso): Fix this to something better.
criterion = {"id": domain_id, "type": "PRIMARY"}
central_api.find_domain(context, criterion=criterion)
central_api.find_zone(context, criterion=criterion)
nameservers = central_api.get_domain_servers(context, domain_id)
nameservers = central_api.get_zone_ns_records(context, domain_id)
servers = objects.ServerList()
......
......@@ -47,7 +47,7 @@ def reports_counts():
context = flask.request.environ.get('context')
tenants = central_api.count_tenants(context)
domains = central_api.count_domains(context)
domains = central_api.count_zones(context)
records = central_api.count_records(context)
return flask.jsonify(tenants=tenants, domains=domains, records=records)
......@@ -66,7 +66,7 @@ def reports_counts_tenants():
def reports_counts_domains():
context = flask.request.environ.get('context')
count = central_api.count_domains(context)
count = central_api.count_zones(context)
return flask.jsonify(domains=count)
......
......@@ -28,7 +28,7 @@ blueprint = flask.Blueprint('sync', __name__)
def sync_domains():
context = flask.request.environ.get('context')
central_api.sync_domains(context)
central_api.sync_zones(context)
return flask.Response(status=200)
......@@ -37,7 +37,7 @@ def sync_domains():
def sync_domain(domain_id):
context = flask.request.environ.get('context')
central_api.sync_domain(context, domain_id)
central_api.sync_zone(context, domain_id)
return flask.Response(status=200)
......
......@@ -26,6 +26,6 @@ blueprint = flask.Blueprint('touch', __name__)
def touch_domain(domain_id):
context = flask.request.environ.get('context')
central_api.touch_domain(context, domain_id)
central_api.touch_zone(context, domain_id)
return flask.Response(status=200)
......@@ -41,8 +41,8 @@ def get_limits():
return flask.jsonify(limits_schema.filter({
"limits": {
"absolute": {
"maxDomains": absolute_limits['domains'],
"maxDomainRecords": absolute_limits['domain_records']
"maxDomains": absolute_limits['zones'],
"maxDomainRecords": absolute_limits['zone_records']
}
}
}))
......@@ -33,7 +33,7 @@ def _find_recordset(context, domain_id, name, type):
central_api = central_rpcapi.CentralAPI.get_instance()
return central_api.find_recordset(context, {
'domain_id': domain_id,
'zone_id': domain_id,
'name': name,
'type': type,
})
......@@ -43,7 +43,7 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl):
central_api = central_rpcapi.CentralAPI.get_instance()
criterion = {"id": domain_id, "type": "PRIMARY"}
central_api.find_domain(context, criterion=criterion)
central_api.find_zone(context, criterion=criterion)
try:
# Attempt to create an empty recordset
......@@ -83,6 +83,10 @@ def _format_record_v1(record, recordset):
record['priority'], record['data'] = utils.extract_priority_from_data(
recordset.type, record)
record['domain_id'] = record['zone_id']
del record['zone_id']
record.update({
'name': recordset['name'],
'type': recordset['type'],
......@@ -122,8 +126,8 @@ def create_record(domain_id):
central_api = central_rpcapi.CentralAPI.get_instance()
record = central_api.create_record(context, domain_id,
recordset['id'],
record)
recordset['id'],
record)