Browse Source

Do away with zone_tree, not a tree and unnecessary now

pull/917/head
Ross McFarland 3 years ago
parent
commit
af010121ea
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 31 additions and 55 deletions
  1. +30
    -32
      octodns/manager.py
  2. +1
    -23
      tests/test_octodns_manager.py

+ 30
- 32
octodns/manager.py View File

@ -228,37 +228,7 @@ class Manager(object):
'Incorrect plan_output config for ' + plan_output_name 'Incorrect plan_output config for ' + plan_output_name
) )
self._zone_tree = None
@property
def zone_tree(self):
if self._zone_tree is None:
zone_tree = {}
# Get a list of all of our zone names. Sort them from shortest to
# longest so that parents will always come before their subzones
zones = sorted(
self.config['zones'].keys(), key=lambda z: len(z), reverse=True
)
zones = deque(zones)
# Until we're done processing zones
while zones:
# Grab the one we'lre going to work on now
zone = zones.pop()
trimmer = len(zone) + 1
subs = set()
# look at all the zone names that come after it
for candidate in zones:
# If they end with this zone's name them they're a sub
if candidate.endswith(zone):
# We want subs to exclude the zone portion
subs.add(candidate[:-trimmer])
zone_tree[zone] = subs
self._zone_tree = zone_tree
return self._zone_tree
self._configured_sub_zones = None
def _try_version(self, module_name, module=None, version=None): def _try_version(self, module_name, module=None, version=None):
try: try:
@ -330,7 +300,35 @@ class Manager(object):
return kwargs return kwargs
def configured_sub_zones(self, zone_name): def configured_sub_zones(self, zone_name):
return self.zone_tree.get(zone_name, set())
if self._configured_sub_zones is None:
# First time through we compute all the sub-zones
configured_sub_zones = {}
# Get a list of all of our zone names. Sort them from shortest to
# longest so that parents will always come before their subzones
zones = sorted(
self.config['zones'].keys(), key=lambda z: len(z), reverse=True
)
zones = deque(zones)
# Until we're done processing zones
while zones:
# Grab the one we'lre going to work on now
zone = zones.pop()
trimmer = len(zone) + 1
subs = set()
# look at all the zone names that come after it
for candidate in zones:
# If they end with this zone's name them they're a sub
if candidate.endswith(zone):
# We want subs to exclude the zone portion
subs.add(candidate[:-trimmer])
configured_sub_zones[zone] = subs
self._configured_sub_zones = configured_sub_zones
return self._configured_sub_zones.get(zone_name, set())
def _populate_and_plan( def _populate_and_plan(
self, self,


+ 1
- 23
tests/test_octodns_manager.py View File

@ -723,15 +723,6 @@ class TestManager(TestCase):
'skipped.alevel.unit.tests.': {}, 'skipped.alevel.unit.tests.': {},
} }
self.assertEqual(
{
'unit.tests.': {'sub', 'another.sub', 'skipped.alevel'},
'sub.unit.tests.': {'another'},
'another.sub.unit.tests.': set(),
'skipped.alevel.unit.tests.': set(),
},
manager.zone_tree,
)
self.assertEqual( self.assertEqual(
{'another.sub', 'sub', 'skipped.alevel'}, {'another.sub', 'sub', 'skipped.alevel'},
manager.configured_sub_zones('unit.tests.'), manager.configured_sub_zones('unit.tests.'),
@ -757,20 +748,7 @@ class TestManager(TestCase):
'skipped.alevel.unit.tests.': {}, 'skipped.alevel.unit.tests.': {},
'skipped.alevel.unit2.tests.': {}, 'skipped.alevel.unit2.tests.': {},
} }
manager._zone_tree = None
self.assertEqual(
{
'unit.tests.': {'sub', 'another.sub', 'skipped.alevel'},
'sub.unit.tests.': {'another'},
'another.sub.unit.tests.': set(),
'skipped.alevel.unit.tests.': set(),
'unit2.tests.': {'sub', 'another.sub', 'skipped.alevel'},
'sub.unit2.tests.': {'another'},
'another.sub.unit2.tests.': set(),
'skipped.alevel.unit2.tests.': set(),
},
manager.zone_tree,
)
manager._configured_sub_zones = None
self.assertEqual( self.assertEqual(
{'another.sub', 'sub', 'skipped.alevel'}, {'another.sub', 'sub', 'skipped.alevel'},
manager.configured_sub_zones('unit.tests.'), manager.configured_sub_zones('unit.tests.'),


Loading…
Cancel
Save