Fix pool update with duplicate masters
If any zones exist that belong to a pool that has any duplicate masters
among all targets, currently updating the pool will fail.
This change fixes the issue by ensuring the pool target master list does
not contain duplicates.
Change-Id: I72bae79b4f8e0bab739875d6f783abdb4868950b
Closes-Bug: #1897936
(cherry picked from commit 4e86bc2a58
)
This commit is contained in:
parent
f101fab295
commit
58e441e4b0
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue