diff options
-rw-r--r-- | designate/manage/pool.py | 9 | ||||
-rw-r--r-- | designate/tests/test_manage/test_update_pool.py | 41 |
2 files changed, 45 insertions, 5 deletions
diff --git a/designate/manage/pool.py b/designate/manage/pool.py index 063fa1e8..5d845659 100644 --- a/designate/manage/pool.py +++ b/designate/manage/pool.py @@ -51,8 +51,13 @@ class PoolCommands(base.Commands): masters = [] for target in pool.targets: for master in target.get("masters", []): - masters.append({'host': master['host'], - 'port': master['port']}) + master = {'host': master['host'], 'port': master['port']} + found = False + for existing_master in masters: + if master == existing_master: + found = True + if not found: + masters.append(master) return masters policy.init() diff --git a/designate/tests/test_manage/test_update_pool.py b/designate/tests/test_manage/test_update_pool.py index d5b21fbc..1e9320be 100644 --- a/designate/tests/test_manage/test_update_pool.py +++ b/designate/tests/test_manage/test_update_pool.py @@ -26,11 +26,11 @@ class UpdatePoolTestCase(DesignateManageTestCase): self.stdlog = fixtures.StandardLogging() self.useFixture(self.stdlog) - def hydrate_pool_targets(self, targets): + def hydrate_pool_targets(self, target_masters): pool_targets = objects.PoolTargetList() masters = objects.PoolTargetMasterList() - for target in targets: - masters.append(target) + for target_master in target_masters: + masters.append(target_master) target = objects.PoolTarget(masters=masters) target.masters = masters pool_targets.append(target) @@ -63,3 +63,38 @@ class UpdatePoolTestCase(DesignateManageTestCase): "update_zone") as mock_update_zone: command._update_zones(pool) mock_update_zone.assert_called_once() + + def test_update_pools_zones_multiple_masters(self): + values = dict( + name='example.com.', + email='info@example.com', + type='PRIMARY' + ) + + zone = self.central_service.create_zone( + self.admin_context, zone=objects.Zone.from_dict(values)) + + # Ensure the correct NS Records are in place + pool = self.central_service.get_pool( + self.admin_context, zone.pool_id) + + targets1 = self.hydrate_pool_targets([ + objects.PoolTargetMaster( + pool_target_id=pool.id, + host="127.0.0.1", + port="53") + ]) + targets2 = self.hydrate_pool_targets([ + objects.PoolTargetMaster( + pool_target_id=pool.id, + host="127.0.0.1", + port="53") + ]) + pool.targets = objects.PoolTargetList() + pool.targets.extend(targets1.objects + targets2.objects) + + command = PoolCommands() + command.context = self.admin_context + command.central_api = self.central_service + + command._update_zones(pool) |