diff --git a/octodns/cmds/dump.py b/octodns/cmds/dump.py index 38eaeb9..1c788fd 100755 --- a/octodns/cmds/dump.py +++ b/octodns/cmds/dump.py @@ -39,7 +39,10 @@ def main(): default=False, help='Split the dumped zone into a YAML file per record', ) - parser.add_argument('zone', help='Zone to dump') + parser.add_argument( + 'zone', + help="Zone to dump, '*' (single quoted to avoid expansion) for all configured zones", + ) parser.add_argument('source', nargs='+', help='Source(s) to pull data from') args = parser.parse_args() diff --git a/octodns/manager.py b/octodns/manager.py index 37530de..d3c22df 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -851,14 +851,25 @@ class Manager(object): clz = SplitYamlProvider target = clz('dump', output_dir) - zone = self.get_zone(zone) - for source in sources: - source.populate(zone, lenient=lenient) - - plan = target.plan(zone) - if plan is None: - plan = Plan(zone, zone, [], False) - target.apply(plan) + zones = self.config['zones'] + zones = self._preprocess_zones(zones, [s.id for s in sources]) + + if '*' in zone: + # we want to do everything, just need the names though + zones = zones.keys() + else: + # we want to do a specific zone + zones = [zone] + + for zone in zones: + zone = self.get_zone(zone) + for source in sources: + source.populate(zone, lenient=lenient) + + plan = target.plan(zone) + if plan is None: + plan = Plan(zone, zone, [], False) + target.apply(plan) def validate_configs(self): # TODO: this code can probably be shared with stuff in sync diff --git a/tests/test_octodns_manager.py b/tests/test_octodns_manager.py index e597f49..464472f 100644 --- a/tests/test_octodns_manager.py +++ b/tests/test_octodns_manager.py @@ -2,7 +2,7 @@ # # -from os import environ +from os import environ, listdir from os.path import dirname, isfile, join from unittest import TestCase from unittest.mock import MagicMock, patch @@ -371,12 +371,28 @@ class TestManager(TestCase): ) self.assertEqual('Unknown source: nope', str(ctx.exception)) + # specific zone manager.dump( zone='unit.tests.', output_dir=tmpdir.dirname, split=True, sources=['in'], ) + self.assertEqual(['unit.tests.'], listdir(tmpdir.dirname)) + + # all configured zones + manager.dump( + zone='*', output_dir=tmpdir.dirname, split=True, sources=['in'] + ) + self.assertEqual( + [ + 'empty.', + 'sub.txt.unit.tests.', + 'subzone.unit.tests.', + 'unit.tests.', + ], + sorted(listdir(tmpdir.dirname)), + ) # make sure this fails with an ManagerException and not a KeyError # when trying to find sub zones