mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Rework supports_warn_or_except to msg and fallback
This commit is contained in:
@@ -52,10 +52,11 @@ class BaseProvider(BaseSource):
|
||||
for record in desired.records:
|
||||
if record._type == 'PTR' and len(record.values) > 1:
|
||||
# replace with a single-value copy
|
||||
self.supports_warn_or_except('does not support multi-value '
|
||||
'PTR records; will use only {} '
|
||||
'for {}'.format(record.value,
|
||||
record.fqdn))
|
||||
msg = 'multi-value PTR records not supported for {}' \
|
||||
.format(record.fqdn)
|
||||
fallback = 'falling back to single value, {}' \
|
||||
.format(record.value)
|
||||
self.supports_warn_or_except(msg, fallback)
|
||||
record = record.copy()
|
||||
record.values = [record.value]
|
||||
|
||||
@@ -78,10 +79,10 @@ class BaseProvider(BaseSource):
|
||||
'''
|
||||
return []
|
||||
|
||||
def supports_warn_or_except(self, msg):
|
||||
def supports_warn_or_except(self, msg, fallback):
|
||||
if self.strict_supports:
|
||||
raise ProviderException('{}: {}'.format(self.id, msg))
|
||||
self.log.warning(msg)
|
||||
self.log.warning('{}; {}'.format(msg, fallback))
|
||||
|
||||
def plan(self, desired, processors=[]):
|
||||
self.log.info('plan: desired=%s', desired.name)
|
||||
|
@@ -942,14 +942,18 @@ class Route53Provider(BaseProvider):
|
||||
if not g.startswith('NA-CA-')]
|
||||
if not filtered_geos:
|
||||
# We've removed all geos, we'll have to skip this rule
|
||||
msg = 'NA-CA-* not supported resulting in ' \
|
||||
'empty geo target, skipping rule {}'.format(i)
|
||||
self.supports_warn_or_except(msg)
|
||||
msg = 'NA-CA-* not supported for {}' \
|
||||
.format(record.fqdn)
|
||||
fallback = 'skipping rule {}'.format(i)
|
||||
self.supports_warn_or_except(msg, fallback)
|
||||
continue
|
||||
elif geos != filtered_geos:
|
||||
msg = 'NA-CA-* not supported resulting in ' \
|
||||
'empty geo target, skipping rule {}'.format(i)
|
||||
self.supports_warn_or_except(msg)
|
||||
msg = 'NA-CA-* not supported for {}' \
|
||||
.format(record.fqdn)
|
||||
fallback = 'filtering rule {} from ({}) to ({})' \
|
||||
.format(i, ', '.join(geos),
|
||||
', '.join(filtered_geos))
|
||||
self.supports_warn_or_except(msg, fallback)
|
||||
rule.data['geos'] = filtered_geos
|
||||
rules.append(rule)
|
||||
|
||||
|
@@ -457,15 +457,15 @@ class TestBaseProvider(TestCase):
|
||||
|
||||
normal = MinimalProvider(strict_supports=False)
|
||||
# Should log and not expect
|
||||
normal.supports_warn_or_except('Hello World!')
|
||||
normal.supports_warn_or_except('Hello World!', 'Goodbye')
|
||||
normal.log.warning.assert_called_once()
|
||||
normal.log.warning.assert_has_calls([
|
||||
call('Hello World!')
|
||||
call('Hello World!; Goodbye')
|
||||
])
|
||||
|
||||
strict = MinimalProvider(strict_supports=True)
|
||||
# Should log and not expect
|
||||
with self.assertRaises(ProviderException) as ctx:
|
||||
strict.supports_warn_or_except('Hello World!')
|
||||
strict.supports_warn_or_except('Hello World!', 'Will not see')
|
||||
self.assertEquals('minimal: Hello World!', text_type(ctx.exception))
|
||||
strict.log.warning.assert_not_called()
|
||||
|
Reference in New Issue
Block a user