pvl/hosts/tests.py
author Tero Marttila <tero.marttila@aalto.fi>
Wed, 25 Feb 2015 15:12:55 +0200
changeset 470 ac334a55eebc
parent 469 cd1f1b51f3a0
child 471 e4b4458d8061
permissions -rw-r--r--
pvl.hosts: fix location= and test forward records
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     1
import ipaddr
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     2
import unittest
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     3
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
     4
from pvl.hosts import config, host, zone
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     5
from StringIO import StringIO
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     6
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     7
class Options(object):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     8
    hosts_charset   = 'utf-8'
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     9
    hosts_domain    = None
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    10
    hosts_include   = None
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    11
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    12
class ConfFile(StringIO):
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    13
    def __init__(self, name, buffer):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    14
        StringIO.__init__(self, buffer)
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    15
        self.name = name
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    16
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    17
class TestConfig(unittest.TestCase):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    18
    def setUp(self):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    19
        self.options = Options()
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    20
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    21
    def assertHostEqual(self, host, host_str, attrs):
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    22
        self.assertEquals(str(host), host_str)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    23
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    24
        for attr, value in attrs.iteritems():
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    25
            self.assertEquals(getattr(host, attr), value)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    26
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    27
    def assertHostsEqual(self, hosts, expected):
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    28
        for host, expect in zip(hosts, expected):
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    29
            host_str, attrs = expect
441
f058fff1f272 pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents: 440
diff changeset
    30
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    31
            self.assertHostEqual(host, host_str, attrs)
441
f058fff1f272 pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents: 440
diff changeset
    32
 
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    33
    def testApplyHostsFileError(self):
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    34
        with self.assertRaises(config.HostConfigError):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    35
            list(config.apply_hosts(self.options, ['nonexistant']))
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    36
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    37
    def testApplyHosts(self):
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    38
        conf_file = ConfFile('test', """
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    39
[foo]
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    40
    ip = 127.0.0.1
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    41
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    42
[bar]
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    43
    ip = 127.0.0.2
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    44
        """)
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    45
        expected = [
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    46
                ('foo@test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    47
                ('bar@test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    48
        ]
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    49
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    50
        self.assertHostsEqual(config.apply_hosts_file(self.options, conf_file), expected)
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    51
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    52
    def testApply(self):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    53
        self.assertHostsEqual(config.apply(self.options, ['etc/hosts/test']), [
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    54
                ('foo@test', dict(
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    55
                    ip          = ipaddr.IPAddress('127.0.0.1'),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    56
                    ethernet    = {None: '00:11:22:33:44:55'},
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    57
                )),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    58
                ('bar@test', dict(
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    59
                    ip          = ipaddr.IPAddress('127.0.0.2'),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    60
                    ethernet    = {None: '01:23:45:67:89:ab'},
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    61
                )),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    62
        ])
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    63
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    64
    def testApplyHostsExpand(self):
449
a19438b781d5 pvl.hosts.config: cleanup apply_host_config
Tero Marttila <tero.marttila@aalto.fi>
parents: 447
diff changeset
    65
        self.assertHostsEqual(config.apply_host_config(self.options, 'asdf', 'asdf{1-3}', ip='10.100.100.$'), [
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    66
                ('asdf1@asdf', dict(ip=ipaddr.IPAddress('10.100.100.1'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    67
                ('asdf2@asdf', dict(ip=ipaddr.IPAddress('10.100.100.2'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    68
                ('asdf3@asdf', dict(ip=ipaddr.IPAddress('10.100.100.3'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    69
        ])
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    70
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    71
    def testApplyHostConfigDict(self):
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    72
        host = config.apply_host(self.options, 'foo', 'test', {
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    73
            'ethernet.eth0': '00:11:22:33:44:55',
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    74
        })
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    75
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    76
        self.assertHostEqual(host, 'foo@test', dict(
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    77
                ethernet    = { 'eth0': '00:11:22:33:44:55' }
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    78
        ))
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    79
   
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    80
    def testApplyHostsConfigError(self):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    81
        with self.assertRaises(config.HostConfigError):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    82
            config.apply_host(self.options, 'foo', 'test', {
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    83
                'ethernet': 'foo',
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    84
                'ethernet.eth0': 'bar',
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    85
            })
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    86
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
    87
class TestZoneMixin(object):
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    88
    def assertZoneEquals(self, rrs, expected):
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    89
        gather = { }
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    90
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    91
        for rr in rrs:
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    92
            key = (rr.name.lower(), rr.type.upper())
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    93
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    94
            self.assertNotIn(key, gather)
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    95
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    96
            gather[key] = rr.data
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    97
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    98
        self.assertDictEqual(gather, expected)
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    99
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   100
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   101
class TestForwardZone(TestZoneMixin, unittest.TestCase):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   102
    def setUp(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   103
        self.options = Options()
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   104
        self.options.add_origin = False
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   105
462
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   106
    def testResolve(self):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   107
        self.assertEquals(zone.resolve(None, None, 'host'), 'host.')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   108
        self.assertEquals(zone.resolve(None, 'domain', 'host'), 'host.domain.')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   109
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   110
        with self.assertRaises(zone.HostZoneError):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   111
            zone.resolve('origin', 'domain', 'host')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   112
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   113
        self.assertEquals(zone.resolve('domain', 'domain', 'host'), 'host')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   114
        self.assertEquals(zone.resolve('origin', 'domain.origin', 'host'), 'host.domain')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   115
        
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   116
        with self.assertRaises(zone.HostZoneError):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   117
            zone.resolve('origin', 'domainorigin', 'host')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   118
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   119
        with self.assertRaises(zone.HostZoneError):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   120
            zone.resolve('origin', None, 'host.domain')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   121
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   122
    def testHostOutOfOrigin(self):
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   123
        h = host.Host('host', 'domain', ip=ipaddr.IPAddress('10.0.0.1'))
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   124
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   125
        self.assertZoneEquals(zone.host_forward(h, 'test'), { })
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   126
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   127
    def testHostIP(self):
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   128
        h = host.Host.build('host', 'domain',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   129
                ip  = '192.0.2.1',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   130
                ip6 = '2001:db8::192.0.2.1',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   131
        )
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   132
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   133
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   134
            ('host', 'A'): ['192.0.2.1'],
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   135
            ('host', 'AAAA'): ['2001:db8::c000:201'],
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   136
        })
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   137
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   138
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   139
            ('1', 'PTR'): ['host.domain.'],
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   140
        })
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   141
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   142
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   143
            ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'],
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   144
        })
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   145
    
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   146
    def testHostAlias(self):
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   147
        h = host.Host.build('host', 'domain',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   148
                ip      = '192.0.2.1',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   149
                alias   = 'test *.test',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   150
        )
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   151
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   152
        self.assertEquals(h.alias, ['test', '*.test'])
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   153
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   154
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   155
            ('host', 'A'): ['192.0.2.1'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   156
            ('test', 'CNAME'): ['host'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   157
            ('*.test', 'CNAME'): ['host'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   158
        })
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   159
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   160
    def testHostAlias46(self):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   161
        h = host.Host.build('host', 'domain',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   162
                ip      = '192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   163
                ip6     = '2001:db8::192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   164
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   165
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   166
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   167
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   168
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   169
            ('host', 'A'): ['192.0.2.1'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   170
            ('host', 'AAAA'): ['2001:db8::c000:201'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   171
            ('test4', 'A'): ['192.0.2.1'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   172
            ('test6', 'AAAA'): ['2001:db8::c000:201'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   173
        })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   174
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   175
    def testHostAlias4Missing(self):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   176
        h = host.Host.build('host', 'domain',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   177
                ip6     = '2001:db8::192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   178
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   179
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   180
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   181
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   182
        with self.assertRaises(zone.HostZoneError):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   183
            self.assertZoneEquals(zone.host_forward(h, 'domain'), { })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   184
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   185
    def testHostAlias6Missing(self):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   186
        h = host.Host.build('host', 'domain',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   187
                ip      = '192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   188
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   189
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   190
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   191
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   192
        with self.assertRaises(zone.HostZoneError):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   193
            self.assertZoneEquals(zone.host_forward(h, 'domain'), { })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   194
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   195
    def testHostDelegate(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   196
        h = host.Host.build('host', 'example.com',
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   197
                forward = 'host.example.net',
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   198
        )
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   199
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   200
        self.assertZoneEquals(zone.host_forward(h, 'example.com'), {
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   201
            ('host', 'CNAME'): ['host.example.net.'],
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   202
        })
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   203
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   204
    def testHostForwardAlias(self):
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   205
        h = host.Host.build('host', 'domain',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   206
                forward = 'host.example.net',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   207
                alias   = 'test',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   208
        )
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   209
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   210
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   211
            ('host', 'CNAME'): ['host.example.net.'],
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   212
            ('test', 'CNAME'): ['host'],
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   213
        })
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   214
470
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   215
    def testHostLocation(self):
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   216
        h = host.Host.build('host', 'domain',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   217
                ip          = '192.0.2.1',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   218
                location    = 'test',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   219
        )
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   220
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   221
        self.assertEquals(h.location, ('test', 'domain'))
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   222
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   223
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   224
            ('host', 'A'): ['192.0.2.1'],
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   225
            ('test', 'CNAME'): ['host'],
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   226
        })
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   227
 
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   228
class TestReverseZone(TestZoneMixin, unittest.TestCase):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   229
    def setUp(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   230
        self.options = Options()
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   231
        self.options.unknown_host = False
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   232
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   233
    def testHostDelegate(self):
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   234
        h = host.Host.build('host', 'example.com',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   235
                ip      = '192.0.2.1',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   236
                ip6     = '2001:db8::192.0.2.1',
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   237
                forward = '',
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   238
                reverse = '1.0/28.2.0.192.in-addr.arpa',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   239
        )
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   240
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   241
        self.assertZoneEquals(zone.host_forward(h, 'example.com'), {
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   242
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   243
        })
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   244
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   245
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   246
            ('1', 'CNAME'): ['1.0/28.2.0.192.in-addr.arpa.'],
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   247
        })
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   248
        
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   249
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   250
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   251
        })
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   252
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   253
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   254
if __name__ == '__main__':
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   255
    unittest.main()