pick first PTR value instead of erroring out

This commit is contained in:
Viranch Mehta
2021-08-16 16:39:23 -07:00
parent 73ad7000ca
commit 6e9ce3ac3c
6 changed files with 29 additions and 16 deletions
+24 -2
View File
@@ -294,8 +294,30 @@ class Manager(object):
for processor in processors:
plan = processor.process_plan(plan, sources=sources,
target=target)
if plan:
plans.append((target, plan))
if not plan:
continue
# Multi value PTR check
for change in plan.changes:
record = change.new
if not record:
# Delete - doesn't need to be checked
continue
if record._type == 'PTR' and len(record.values) > 1 and not \
target.SUPPORTS_MUTLIVALUE_PTR:
self.log.warn('target=%s does not support multi-value PTR '
'record %s; using %s as its only answer',
target, record.fqdn, record.value)
# Make a new copy of the record so as to not change a
# potentially shared object
change.new = Record.new(record.zone, record.name, {
'type': record._type,
'ttl': record.ttl,
'value': record.value,
}, source=record.source, lenient=lenient)
plans.append((target, plan))
# Return the zone as it's the desired state
return plans, zone
+1
View File
@@ -456,6 +456,7 @@ class AzureProvider(BaseProvider):
'''
SUPPORTS_GEO = False
SUPPORTS_DYNAMIC = True
SUPPORTS_MUTLIVALUE_PTR = True
SUPPORTS = set(('A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NS', 'PTR', 'SRV',
'TXT'))
+1
View File
@@ -261,6 +261,7 @@ class Ns1Provider(BaseProvider):
'''
SUPPORTS_GEO = True
SUPPORTS_DYNAMIC = True
SUPPORTS_MUTLIVALUE_PTR = True
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'MX', 'NAPTR',
'NS', 'PTR', 'SPF', 'SRV', 'TXT', 'URLFWD'))
+1 -4
View File
@@ -1285,10 +1285,7 @@ class PtrRecord(_ValuesMixin, Record):
# multi-value PTR records.
@property
def value(self):
if len(self.values) == 1:
return self.data['value']
raise AttributeError("Multi-value PTR record has no attribute 'value'")
return self.values[0]
class SshfpValue(EqualityTupleMixin):
+2
View File
@@ -8,6 +8,8 @@ from __future__ import absolute_import, division, print_function, \
class BaseSource(object):
SUPPORTS_MUTLIVALUE_PTR = False
def __init__(self, id):
self.id = id
if not getattr(self, 'log', False):
-10
View File
@@ -2755,16 +2755,6 @@ class TestRecordValidation(TestCase):
self.assertEquals(['PTR value "foo.bar" missing trailing .'],
ctx.exception.reasons)
# multi-value requesting single-value
with self.assertRaises(AttributeError) as ctx:
Record.new(self.zone, '', {
'type': 'PTR',
'ttl': 600,
'values': ['foo.com.', 'bar.net.'],
}).value
self.assertEquals("Multi-value PTR record has no attribute 'value'",
text_type(ctx.exception))
def test_SSHFP(self):
# doesn't blow up
Record.new(self.zone, '', {