Fix zone update when adding new Bind9 target to pool.

When a new Bind9 is added to the pool, Designate will trigger 'modzone'
rndc command that will fail, unless zone is already present on the backend.

This change will first verify that the zone is present on the backend,
before an update attempt. If zone is not present - zone creation will be
triggered.

Closes-Bug: 1958409

Co-authored-by: Kiran Pawar <kinpaa@gmail.com>
Change-Id: I782bf38a68f24a2e7133ff2afad7c96e2ae6b7f0
(cherry picked from commit 66cc876ead)
This commit is contained in:
Dmitry Galkin 2022-02-10 10:40:35 +01:00 committed by Sven Kieske
parent 8a84e936b2
commit 5e569a3c76
3 changed files with 43 additions and 1 deletions

View File

@ -104,6 +104,28 @@ class Bind9Backend(base.Backend):
context, zone, self._host, self._port, self.timeout,
self.retry_interval, self.max_retries, self.delay)
def get_zone(self, context, zone):
"""Returns True if zone exists and False if not"""
LOG.debug('Get Zone')
view = 'in %s' % self._view if self._view else ''
rndc_op = [
'showzone',
'%s %s' % (zone['name'].rstrip('.'), view),
]
try:
self._execute_rndc(rndc_op)
except exceptions.Backend as e:
if "not found" in str(e):
LOG.debug('Zone %s not found on the backend', zone['name'])
return False
else:
LOG.warning('RNDC call failure: %s', e)
raise e
return True
def delete_zone(self, context, zone):
"""Delete a new Zone by executin rndc
Do not raise exceptions if the zone does not exist.
@ -131,14 +153,21 @@ class Bind9Backend(base.Backend):
"""
Update a DNS zone.
This will execute a rndc modzone as the zone
This will execute a rndc modzone if the zone
already exists but masters might need to be refreshed.
Or, will create the zone if it does not exist.
:param context: Security context information.
:param zone: the DNS zone.
"""
LOG.debug('Update Zone')
if not self.get_zone(context, zone):
# If zone does not exist yet, create it
self.create_zone(context, zone)
# Newly created zone won't require an update
return
masters = []
for master in self.masters:
host = master['host']

View File

@ -77,6 +77,15 @@ class Bind9BackendTestCase(designate.tests.TestCase):
]
)
@mock.patch.object(impl_bind9.Bind9Backend, '_execute_rndc')
def test_get_zone(self, mock_execute):
with fixtures.random_seed(0):
self.backend.get_zone(self.admin_context, self.zone)
mock_execute.assert_called_with(
['showzone', 'example.com ']
)
@mock.patch.object(impl_bind9.Bind9Backend, '_execute_rndc')
def test_create_zone_with_view(self, mock_execute):
self.target['options'].append(

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fixed an issue where new BIND9 pool instances may fail on zone update.