Smarter Create/Delete in BIND9/Agent

* In BIND9, an rndc addzone fails if the zone already exists,
  similarly, a delzone fails if the zone doesn't exist. This
  patch catches that in the output from the RNDC call, and allows
  the Pool Manager to realize success in the above situation.

* In the Agent, we must take action (write a zone file, for example)
  before we execute the addzone/delzone. So we check with an SOA query
  before the backend is called.

Partial-Bug: 1430976
Change-Id: I0430c3a402ae30d5705bbfef1a4394772cbc12f9
This commit is contained in:
Tim Simmons 2015-03-12 15:52:56 +00:00
parent 9bf9406287
commit b597b2c280
2 changed files with 26 additions and 4 deletions

View File

@ -115,9 +115,10 @@ class RequestHandler(object):
serial = self.backend.find_domain_serial(domain_name)
if serial is not None:
LOG.warn(_LW("Refusing CREATE for %(name)s, zone already exists") %
LOG.warn(_LW("Not creating %(name)s, zone already exists") %
{'name': domain_name})
response.set_rcode(dns.rcode.from_text("REFUSED"))
# Provide an authoritative answer
response.flags |= dns.flags.AA
return response
LOG.debug("Received %(verb)s for %(name)s from %(host)s" %
@ -206,6 +207,15 @@ class RequestHandler(object):
response.set_rcode(dns.rcode.from_text("REFUSED"))
return response
serial = self.backend.find_domain_serial(domain_name)
if serial is None:
LOG.warn(_LW("Not deleting %(name)s, zone doesn't exist") %
{'name': domain_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})

View File

@ -85,7 +85,13 @@ class Bind9Backend(base.PoolBackend):
(domain['name'].rstrip('.'), '; '.join(masters), domain['name'],
domain['id']),
]
self._execute_rndc(rndc_op)
try:
self._execute_rndc(rndc_op)
except exceptions.Backend as e:
# If create fails because the domain exists, don't reraise
if "already exists" not in str(e.message):
raise
def delete_domain(self, context, domain):
LOG.debug('Delete Domain')
@ -93,7 +99,13 @@ class Bind9Backend(base.PoolBackend):
'delzone',
'%s' % domain['name'].rstrip('.'),
]
self._execute_rndc(rndc_op)
try:
self._execute_rndc(rndc_op)
except exceptions.Backend as e:
# If domain is already deleted, don't reraise
if "not found" not in str(e.message):
raise
def _rndc_base(self):
rndc_call = [