# HG changeset patch # User Tero Marttila # Date 1424867380 -7200 # Node ID 6d699c76d75d82f1c339e21f83c0be1002e5f430 # Parent e3bddc5eeff50f6afb9023982571ff0e9b898bf9 pvl.hosts.zone: test resolve() and handle FQDN's strictly diff -r e3bddc5eeff5 -r 6d699c76d75d pvl/hosts/tests.py --- a/pvl/hosts/tests.py Wed Feb 25 14:23:04 2015 +0200 +++ b/pvl/hosts/tests.py Wed Feb 25 14:29:40 2015 +0200 @@ -1,7 +1,7 @@ import ipaddr import unittest -from pvl.hosts import config +from pvl.hosts import config, zone from StringIO import StringIO class Options(object): @@ -84,5 +84,26 @@ 'ethernet.eth0': 'bar', }) +class TestForwardZone(unittest.TestCase): + def setUp(self): + self.options = Options() + self.options.add_origin = False + + def testResolve(self): + self.assertEquals(zone.resolve(None, None, 'host'), 'host.') + self.assertEquals(zone.resolve(None, 'domain', 'host'), 'host.domain.') + + with self.assertRaises(zone.HostZoneError): + zone.resolve('origin', 'domain', 'host') + + self.assertEquals(zone.resolve('domain', 'domain', 'host'), 'host') + self.assertEquals(zone.resolve('origin', 'domain.origin', 'host'), 'host.domain') + + with self.assertRaises(zone.HostZoneError): + zone.resolve('origin', 'domainorigin', 'host') + + with self.assertRaises(zone.HostZoneError): + zone.resolve('origin', None, 'host.domain') + if __name__ == '__main__': unittest.main() diff -r e3bddc5eeff5 -r 6d699c76d75d pvl/hosts/zone.py --- a/pvl/hosts/zone.py Wed Feb 25 14:23:04 2015 +0200 +++ b/pvl/hosts/zone.py Wed Feb 25 14:29:40 2015 +0200 @@ -14,7 +14,13 @@ Resolve relative CNAME for label@origin -> alias@domain """ - fqdn = pvl.dns.join(name, domain) + if origin: + origin = pvl.dns.fqdn(origin) + + if domain: + fqdn = pvl.dns.fqdn(name, domain) + else: + fqdn = pvl.dns.fqdn(name) if not origin: return fqdn