# HG changeset patch # User Tero Marttila # Date 1425295594 -7200 # Node ID f99f9e3d02cfbab2afac38004f287ca49dc5ca12 # Parent 6416c448a71301587c162c4c48352e1b3b52dd8e pvl.hosts.zone: make non-CNAME check_conflicts optional diff -r 6416c448a713 -r f99f9e3d02cf bin/pvl.hosts-forward --- a/bin/pvl.hosts-forward Mon Mar 02 13:12:35 2015 +0200 +++ b/bin/pvl.hosts-forward Mon Mar 02 13:26:34 2015 +0200 @@ -25,6 +25,9 @@ parser.add_option('--add-origin', action='store_true', help="Include $ORIGIN directive in zone") + parser.add_option('--check-conflicts', action='store_true', + help="Check for dupliate forward records, e.g. multiple A records for the same name") + # input options, args = pvl.args.parse(parser, argv) @@ -52,7 +55,8 @@ # process try: for rr in pvl.hosts.zone.apply_hosts_forward(hosts, origin, - add_origin = options.add_origin, + add_origin = options.add_origin, + check_conflicts = options.check_conflicts, ): print unicode(rr) except pvl.hosts.HostError as error: diff -r 6416c448a713 -r f99f9e3d02cf pvl/hosts/tests.py --- a/pvl/hosts/tests.py Mon Mar 02 13:12:35 2015 +0200 +++ b/pvl/hosts/tests.py Mon Mar 02 13:26:34 2015 +0200 @@ -368,7 +368,7 @@ ] with self.assertRaises(zone.HostZoneError): - self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain'), { }) + self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain', check_conflicts=True), { }) def testHostsAliasConflict(self): hosts = [ @@ -401,7 +401,7 @@ ] with self.assertRaises(zone.HostZoneError): - self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain'), { }) + self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain', check_conflicts=True), { }) class TestReverseZone(TestZoneMixin, unittest.TestCase): diff -r 6416c448a713 -r f99f9e3d02cf pvl/hosts/zone.py --- a/pvl/hosts/zone.py Mon Mar 02 13:12:35 2015 +0200 +++ b/pvl/hosts/zone.py Mon Mar 02 13:26:34 2015 +0200 @@ -117,7 +117,8 @@ log.info("%s %s[%s]: omit", host, prefix, ip) def apply_hosts_forward (hosts, origin, - add_origin = False, + add_origin = False, + check_conflicts = False, ) : """ Generate DNS ZoneRecords for for hosts within the given zone origin. @@ -127,6 +128,8 @@ hosts: [Host] - Host's to render origin: str - generate records relative to given zone origin add_origin: bool - generate an explicit $ORIGIN directive + check_conflits: bool- raise HostZoneError on dupliate records for the same name/type + overlapping CNAME records will always raise Yields ZoneRecords in Host-order """ @@ -143,7 +146,7 @@ raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name_type[rr.name, 'CNAME'])) elif rr.type == 'CNAME' and rr.name in by_name: raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name[rr.name])) - elif (rr.name, rr.type) in by_name_type: + elif check_conflicts and (rr.name, rr.type) in by_name_type: raise HostZoneError(host, u"{name} {type} conflict with {other}".format(type=rr.type, name=rr.name, other=by_name_type[rr.name, rr.type])) by_name[rr.name] = host