diff options
author | Zuul <zuul@review.opendev.org> | 2021-05-17 16:48:33 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2021-05-17 16:48:33 +0000 |
commit | 7cbbd3a18ffedc9dbeaddaab189643b59a224878 (patch) | |
tree | 02d9feeff26fc78ad37d6b128da0b25e8ddbe40c | |
parent | d08dd621c988fe13b9844c5c44e143907aa74d0c (diff) | |
parent | 9e159d93d99bf1ed0c487bfe99450f59db509249 (diff) | |
download | designate-7cbbd3a18ffedc9dbeaddaab189643b59a224878.tar.gz |
Merge "Fix pool update with duplicate masters" into stable/victoria
-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 a3653dca..35bc1fa4 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) |