summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-03-10 01:25:33 +0000
committerGerrit Code Review <review@openstack.org>2022-03-10 01:25:33 +0000
commit13ca3954a089e9ad2673c5a4d3339eca5513b108 (patch)
tree6ef41a2db5da9e8754863b17a800026cdca3eaa0
parent93ebb1af53d216982210cff21a1bde87489ed0f1 (diff)
parent66cc876eadd9a4ded3afa35aed675c15c60f149d (diff)
downloaddesignate-13ca3954a089e9ad2673c5a4d3339eca5513b108.tar.gz
Merge "Fix zone update when adding new Bind9 target to pool."14.0.0.0rc114.0.0
-rw-r--r--designate/backend/impl_bind9.py31
-rw-r--r--designate/tests/unit/backend/test_bind9.py9
-rw-r--r--releasenotes/notes/Fix-update-zone-create-zone-ada1fd81de479492.yaml4
3 files changed, 43 insertions, 1 deletions
diff --git a/designate/backend/impl_bind9.py b/designate/backend/impl_bind9.py
index b112cd97..f0943e20 100644
--- a/designate/backend/impl_bind9.py
+++ b/designate/backend/impl_bind9.py
@@ -108,6 +108,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.
@@ -135,14 +157,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']
diff --git a/designate/tests/unit/backend/test_bind9.py b/designate/tests/unit/backend/test_bind9.py
index f29394ca..1f68a625 100644
--- a/designate/tests/unit/backend/test_bind9.py
+++ b/designate/tests/unit/backend/test_bind9.py
@@ -80,6 +80,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(
{'key': 'view', 'value': 'guest'},
diff --git a/releasenotes/notes/Fix-update-zone-create-zone-ada1fd81de479492.yaml b/releasenotes/notes/Fix-update-zone-create-zone-ada1fd81de479492.yaml
new file mode 100644
index 00000000..600ec937
--- /dev/null
+++ b/releasenotes/notes/Fix-update-zone-create-zone-ada1fd81de479492.yaml
@@ -0,0 +1,4 @@
+---
+fixes:
+ - |
+ Fixed an issue where new BIND9 pool instances may fail on zone update.