Browse Source

Rework _AggregateTarget to dynamically handle SUPPORTS

pull/875/head
Ross McFarland 4 years ago
parent
commit
e0a5f4d746
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
4 changed files with 32 additions and 13 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +14
    -13
      octodns/manager.py
  3. +2
    -0
      tests/helpers.py
  4. +14
    -0
      tests/test_octodns_manager.py

+ 2
- 0
CHANGELOG.md View File

@ -48,6 +48,8 @@
* Additional FQDN validation to ALIAS/CNAME value, MX exchange, SRV target and
tests of the functionality.
* _AggregateTarget has more complete handling of SUPPORTS* functionality,
mostly applicable for the compare operation.
## v0.9.14 - 2021-10-10 - A new supports system


+ 14
- 13
octodns/manager.py View File

@ -24,6 +24,9 @@ class _AggregateTarget(object):
def __init__(self, targets):
self.targets = targets
self.SUPPORTS = targets[0].SUPPORTS
for target in targets[1:]:
self.SUPPORTS = self.SUPPORTS & target.SUPPORTS
def supports(self, record):
for target in self.targets:
@ -31,19 +34,17 @@ class _AggregateTarget(object):
return False
return True
@property
def SUPPORTS_GEO(self):
for target in self.targets:
if not target.SUPPORTS_GEO:
return False
return True
@property
def SUPPORTS_DYNAMIC(self):
for target in self.targets:
if not target.SUPPORTS_DYNAMIC:
return False
return True
def __getattr__(self, name):
if name.startswith('SUPPORTS_'):
# special case to handle any current or future SUPPORTS_* by
# returning whether all providers support the requested
# functionality.
for target in self.targets:
if not getattr(target, name):
return False
return True
klass = self.__class__.__name__
raise AttributeError(f'{klass} object has no attribute {name}')
class MakeThreadFuture(object):


+ 2
- 0
tests/helpers.py View File

@ -41,6 +41,7 @@ class SimpleProvider(object):
class GeoProvider(object):
SUPPORTS_GEO = True
SUPPORTS_DYNAMIC = False
SUPPORTS = set(('A', 'AAAA', 'TXT'))
id = 'test'
def __init__(self, id='test'):
@ -59,6 +60,7 @@ class GeoProvider(object):
class DynamicProvider(object):
SUPPORTS_GEO = False
SUPPORTS_DYNAMIC = True
SUPPORTS = set(('A', 'AAAA', 'TXT'))
id = 'test'
def __init__(self, id='test'):


+ 14
- 0
tests/test_octodns_manager.py View File

@ -235,6 +235,20 @@ class TestManager(TestCase):
dynamic = DynamicProvider()
nosshfp = NoSshFpProvider()
targets = [simple, geo]
at = _AggregateTarget(targets)
# expected targets
self.assertEqual(targets, at.targets)
# union of their SUPPORTS
self.assertEqual(set(('A')), at.SUPPORTS)
# unknown property will go up into super and throw the normal
# exception
with self.assertRaises(AttributeError) as ctx:
at.FOO
self.assertEqual('_AggregateTarget object has no attribute FOO',
str(ctx.exception))
self.assertFalse(_AggregateTarget([simple, simple]).SUPPORTS_GEO)
self.assertFalse(_AggregateTarget([simple, geo]).SUPPORTS_GEO)
self.assertFalse(_AggregateTarget([geo, simple]).SUPPORTS_GEO)


Loading…
Cancel
Save