summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEndre Karlson <endre.karlson@hp.com>2015-09-29 19:50:32 +0200
committerEndre Karlson <endre.karlson@hp.com>2015-10-06 11:04:37 +0200
commitc034c930863dcb62923709af3f21ba9fd8ca755e (patch)
tree8152b8f884f61ecc39898fc1e6c05c2e149d156a
parent78a83cca4a58fb2e5589e3e6a682098cd7b5bd7e (diff)
downloaddesignate-c034c930863dcb62923709af3f21ba9fd8ca755e.tar.gz
Fix handling of Pool NS changes
Closes-Bug: #1500798 Change-Id: Ie697f35a523a63617ba386f0dcde63600ce5dac6
-rw-r--r--designate/central/service.py17
-rw-r--r--designate/tests/test_central/test_service.py48
2 files changed, 61 insertions, 4 deletions
diff --git a/designate/central/service.py b/designate/central/service.py
index 8071661e..b5a4a47e 100644
--- a/designate/central/service.py
+++ b/designate/central/service.py
@@ -558,13 +558,22 @@ class Service(service.RPCService, service.Service):
def _add_ns(self, context, zone, ns_record):
# Get NS recordset
# If the zone doesn't have an NS recordset yet, create one
- try:
- ns_recordset = self.find_recordset(
- context, criterion={'domain_id': zone['id'], 'type': "NS"})
+ recordsets = self.find_recordsets(
+ context, criterion={'domain_id': zone['id'], 'type': "NS"}
+ )
- except exceptions.RecordSetNotFound:
+ managed = []
+ for rs in recordsets:
+ if [r for r in rs.records if r.managed]:
+ managed.append(rs)
+
+ if len(managed) == 0:
self._create_ns(context, zone, [ns_record])
return
+ elif len(managed) != 1:
+ raise exceptions.RecordSetNotFound("No valid recordset found")
+
+ ns_recordset = managed[0]
# Add new record to recordset based on the new nameserver
ns_recordset.records.append(
diff --git a/designate/tests/test_central/test_service.py b/designate/tests/test_central/test_service.py
index 8693f4a4..f127c224 100644
--- a/designate/tests/test_central/test_service.py
+++ b/designate/tests/test_central/test_service.py
@@ -2571,6 +2571,54 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(set([n.hostname for n in pool.ns_records]),
set([n.data for n in ns_recordset.records]))
+ def test_update_pool_add_ns_record_with_existing_ns_in_zone(self):
+ # Create a server pool and domain
+ pool = self.create_pool(fixture=0)
+ domain = self.create_domain(pool_id=pool.id)
+
+ records = [
+ objects.Record(data="ns-1.example.com."),
+ objects.Record(data="ns-2.example.com.")
+ ]
+ recordset = objects.RecordSet(
+ name="nsx.%s" % domain.name,
+ type="NS",
+ records=records
+ )
+
+ self.central_service.create_recordset(
+ self.admin_context, domain.id, recordset)
+
+ ns_record_count = len(pool.ns_records)
+ new_ns_record = objects.PoolNsRecord(
+ priority=10,
+ hostname='ns-new.example.org.')
+
+ # Update and save the pool
+ pool.ns_records.append(new_ns_record)
+ self.central_service.update_pool(self.admin_context, pool)
+
+ # Fetch the pool
+ pool = self.central_service.get_pool(self.admin_context, pool.id)
+
+ # Verify that the pool was updated correctly
+ self.assertEqual(ns_record_count + 1, len(pool.ns_records))
+ self.assertIn(new_ns_record.hostname,
+ [n.hostname for n in pool.ns_records])
+
+ # Fetch the domains NS recordset
+ ns_recordsets = self.central_service.find_recordsets(
+ self.admin_context,
+ criterion={'domain_id': domain.id, 'type': "NS"})
+
+ # It should have 2
+ self.assertEqual(2, len(ns_recordsets))
+
+ # Verify that the doamins NS records ware updated correctly
+ managed = [i for i in ns_recordsets if i.managed][0]
+ self.assertEqual(set([n.hostname for n in pool.ns_records]),
+ set([n.data for n in managed.records]))
+
def test_update_pool_remove_ns_record(self):
# Create a server pool and domain
pool = self.create_pool(fixture=0)