# HG changeset patch # User Tero Marttila # Date 1424870689 -7200 # Node ID e4b4458d8061bb5f0c61a2a0ff4d6fc0cf7a0225 # Parent ac334a55eebcf20fbd72c66f611d92b1d206bc42 pvl.hosts: test location domains diff -r ac334a55eebc -r e4b4458d8061 pvl/hosts/tests.py --- a/pvl/hosts/tests.py Wed Feb 25 15:12:55 2015 +0200 +++ b/pvl/hosts/tests.py Wed Feb 25 15:24:49 2015 +0200 @@ -224,6 +224,37 @@ ('host', 'A'): ['192.0.2.1'], ('test', 'CNAME'): ['host'], }) + + def testHostLocationDomain(self): + h = host.Host.build('host', 'foo.domain', + ip = '192.0.2.1', + location = 'test@bar.domain', + ) + + self.assertEquals(h.location, ('test', 'bar.domain')) + + self.assertZoneEquals(zone.host_forward(h, 'domain'), { + ('host.foo', 'A'): ['192.0.2.1'], + ('test.bar', 'CNAME'): ['host.foo'], + }) + + def testHostLocationDomainOutOfOrigin(self): + h = host.Host.build('host', 'foo.domain', + ip = '192.0.2.1', + location = 'test@bar.domain', + ) + + self.assertEquals(h.location, ('test', 'bar.domain')) + + with self.assertRaises(zone.HostZoneError): + self.assertZoneEquals(zone.host_forward(h, 'foo.domain'), { + ('host', 'A'): ['192.0.2.1'], + }) + + # TODO + #self.assertZoneEquals(zone.host_forward(h, 'bar.domain'), { + # ('test', 'CNAME'): ['host.foo'], + #}) class TestReverseZone(TestZoneMixin, unittest.TestCase): def setUp(self): diff -r ac334a55eebc -r e4b4458d8061 pvl/hosts/zone.py --- a/pvl/hosts/zone.py Wed Feb 25 15:12:55 2015 +0200 +++ b/pvl/hosts/zone.py Wed Feb 25 15:24:49 2015 +0200 @@ -37,6 +37,7 @@ else: raise HostZoneError("{name}: fqdn {fqdn} out of zone {origin}".format(name=name, fqdn=fqdn, origin=origin)) +# TODO: generate location alias CNAMEs even if host itself is outside origin? def host_forward (host, origin) : """ Yield ZoneRecords for hosts within the given zone origin @@ -73,7 +74,7 @@ if host.location: location_alias, location_domain = host.location - + yield pvl.dns.ZoneRecord.CNAME(resolve(origin, location_domain, location_alias), label) for alias in host.alias: