diff --git a/octodns/manager.py b/octodns/manager.py index f19885f..07be01b 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -221,13 +221,14 @@ class Manager(object): self.log.debug('configured_sub_zones: subs=%s', sub_zone_names) return set(sub_zone_names) - def _populate_and_plan(self, zone_name, sources, targets): + def _populate_and_plan(self, zone_name, sources, targets, lenient=False): - self.log.debug('sync: populating, zone=%s', zone_name) + self.log.debug('sync: populating, zone=%s, lenient=%s', + zone_name, lenient) zone = Zone(zone_name, sub_zones=self.configured_sub_zones(zone_name)) for source in sources: - source.populate(zone) + source.populate(zone, lenient=lenient) self.log.debug('sync: planning, zone=%s', zone_name) plans = [] @@ -259,6 +260,7 @@ class Manager(object): futures = [] for zone_name, config in zones: self.log.info('sync: zone=%s', zone_name) + lenient = config.get('lenient', False) try: sources = config['sources'] except KeyError: @@ -308,7 +310,8 @@ class Manager(object): .format(zone_name, target)) futures.append(self._executor.submit(self._populate_and_plan, - zone_name, sources, targets)) + zone_name, sources, + targets, lenient=lenient)) # Wait on all results and unpack/flatten them in to a list of target & # plan pairs. diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index 39bae2a..04eb2da 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -1215,7 +1215,7 @@ class SrvRecord(_ValuesMixin, Record): def validate(cls, name, fqdn, data): reasons = [] if not cls._name_re.match(name): - reasons.append('invalid name') + reasons.append('invalid name for SRV record') reasons.extend(super(SrvRecord, cls).validate(name, fqdn, data)) return reasons diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index b6dc4e9..e2917b3 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -2167,7 +2167,8 @@ class TestRecordValidation(TestCase): 'target': 'foo.bar.baz.' } }) - self.assertEquals(['invalid name'], ctx.exception.reasons) + self.assertEquals(['invalid name for SRV record'], + ctx.exception.reasons) # missing priority with self.assertRaises(ValidationError) as ctx: diff --git a/tests/test_octodns_source_axfr.py b/tests/test_octodns_source_axfr.py index 62e1a65..bd25062 100644 --- a/tests/test_octodns_source_axfr.py +++ b/tests/test_octodns_source_axfr.py @@ -15,6 +15,7 @@ from unittest import TestCase from octodns.source.axfr import AxfrSource, AxfrSourceZoneTransferFailed, \ ZoneFileSource, ZoneFileSourceLoadFailure from octodns.zone import Zone +from octodns.record import ValidationError class TestAxfrSource(TestCase): @@ -70,3 +71,16 @@ class TestZoneFileSource(TestCase): self.source.populate(zone) self.assertEquals('The DNS zone has no NS RRset at its origin.', text_type(ctx.exception)) + + # Records are not to RFC (lenient=False) + with self.assertRaises(ValidationError) as ctx: + zone = Zone('invalid.records.', []) + self.source.populate(zone) + self.assertEquals('Invalid record _invalid.invalid.records.\n' + ' - invalid name for SRV record', + text_type(ctx.exception)) + + # Records are not to RFC, but load anyhow (lenient=True) + invalid = Zone('invalid.records.', []) + self.source.populate(invalid, lenient=True) + self.assertEquals(12, len(invalid.records)) diff --git a/tests/zones/invalid.records. b/tests/zones/invalid.records. new file mode 100644 index 0000000..e7865a4 --- /dev/null +++ b/tests/zones/invalid.records. @@ -0,0 +1,43 @@ +$ORIGIN invalid.records. +@ 3600 IN SOA ns1.invalid.records. root.invalid.records. ( + 2018071501 ; Serial + 3600 ; Refresh (1 hour) + 600 ; Retry (10 minutes) + 604800 ; Expire (1 week) + 3600 ; NXDOMAIN ttl (1 hour) + ) + +; NS Records +@ 3600 IN NS ns1.invalid.records. +@ 3600 IN NS ns2.invalid.records. +under 3600 IN NS ns1.invalid.records. +under 3600 IN NS ns2.invalid.records. + +; SRV Records +_srv._tcp 600 IN SRV 10 20 30 foo-1.invalid.records. +_srv._tcp 600 IN SRV 10 20 30 foo-2.invalid.records. +_invalid 600 IN SRV 10 20 30 foo-3.invalid.records. + +; TXT Records +txt 600 IN TXT "Bah bah black sheep" +txt 600 IN TXT "have you any wool." +txt 600 IN TXT "v=DKIM1;k=rsa;s=email;h=sha256;p=A/kinda+of/long/string+with+numb3rs" + +; MX Records +mx 300 IN MX 10 smtp-4.invalid.records. +mx 300 IN MX 20 smtp-2.invalid.records. +mx 300 IN MX 30 smtp-3.invalid.records. +mx 300 IN MX 40 smtp-1.invalid.records. + +; A Records +@ 300 IN A 1.2.3.4 +@ 300 IN A 1.2.3.5 +www 300 IN A 2.2.3.6 +wwww.sub 300 IN A 2.2.3.6 + +; AAAA Records +aaaa 600 IN AAAA 2601:644:500:e210:62f8:1dff:feb8:947a + +; CNAME Records +cname 300 IN CNAME invalid.records. +included 300 IN CNAME invalid.records.