pvl.hosts: test location domains
authorTero Marttila <tero.marttila@aalto.fi>
Wed, 25 Feb 2015 15:24:49 +0200
changeset 471 e4b4458d8061
parent 470 ac334a55eebc
child 472 814cc88c531b
pvl.hosts: test location domains
pvl/hosts/tests.py
pvl/hosts/zone.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):
--- 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: