pvl/hosts/tests.py
author Tero Marttila <tero.marttila@aalto.fi>
Thu, 26 Feb 2015 15:05:18 +0200
changeset 483 19d084bb4afd
parent 480 7e44854e85d4
child 487 920394061b6f
permissions -rw-r--r--
pvl.hosts.dhcp: test and document hosts on multiple networks
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
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
     2
import pvl.args
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
     3
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
     4
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
     5
from pvl.hosts import config, dhcp, zone
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
     6
from pvl.hosts.host import Host
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
     7
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
     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
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
    10
    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
    11
    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
    12
    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
    13
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    14
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
    15
    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
    16
        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
    17
        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
    18
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
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
    20
    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
    21
        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
    22
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    23
    def assertHostEqual(self, host, host_str, attrs):
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    24
        self.assertEquals(str(host), host_str)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    25
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    26
        for attr, value in attrs.iteritems():
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    27
            self.assertEquals(getattr(host, attr), value)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    28
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    29
    def assertHostsEqual(self, hosts, expected):
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    30
        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
    31
            host_str, attrs = expect
441
f058fff1f272 pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents: 440
diff changeset
    32
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    33
            self.assertHostEqual(host, host_str, attrs)
441
f058fff1f272 pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents: 440
diff changeset
    34
 
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    35
    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
    36
        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
    37
            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
    38
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
    def testApplyHosts(self):
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    40
        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
    41
[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
    42
    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
    43
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    44
[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
    45
    ip = 127.0.0.2
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    46
        """)
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    47
        expected = [
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    48
                ('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
    49
                ('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
    50
        ]
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
    51
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    52
        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
    53
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    54
    def testApply(self):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    55
        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
    56
                ('foo@test', dict(
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    57
                    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
    58
                    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
    59
                )),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    60
                ('bar@test', dict(
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    61
                    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
    62
                    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
    63
                )),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    64
        ])
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    65
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    66
    def testApplyHostsExpand(self):
449
a19438b781d5 pvl.hosts.config: cleanup apply_host_config
Tero Marttila <tero.marttila@aalto.fi>
parents: 447
diff changeset
    67
        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
    68
                ('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
    69
                ('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
    70
                ('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
    71
        ])
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    72
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    73
    def testApplyHostConfigDict(self):
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    74
        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
    75
            '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
    76
        })
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    77
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    78
        self.assertHostEqual(host, 'foo@test', dict(
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    79
                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
    80
        ))
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    81
   
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    82
    def testApplyHostsConfigError(self):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    83
        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
    84
            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
    85
                'ethernet': 'foo',
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    86
                'ethernet.eth0': 'bar',
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    87
            })
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    88
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
    89
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
    90
    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
    91
        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
    92
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
        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
    94
            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
    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
            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
    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
            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
    99
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
   100
        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
   101
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   102
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   103
class TestForwardZone(TestZoneMixin, unittest.TestCase):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   104
    def setUp(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   105
        self.options = Options()
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   106
        self.options.add_origin = False
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   107
462
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   108
    def testResolve(self):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   109
        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
   110
        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
   111
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   112
        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
   113
            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
   114
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   115
        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
   116
        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
   117
        
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   118
        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
   119
            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
   120
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   121
        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
   122
            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
   123
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   124
    def testHostOutOfOrigin(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   125
        h = Host('host', 'domain', ip=ipaddr.IPAddress('10.0.0.1'))
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
   126
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
   127
        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
   128
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   129
    def testHostIP(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   130
        h = Host.build('host', 'domain',
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
   131
                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
   132
                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
   133
        )
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
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
        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
   136
            ('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
   137
            ('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
   138
        })
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   139
    
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   140
    def testHostAlias(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   141
        h = Host.build('host', 'domain',
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   142
                ip      = '192.0.2.1',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   143
                alias   = 'test *.test',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   144
        )
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   145
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   146
        self.assertEquals(h.alias, ['test', '*.test'])
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   147
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   148
        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
   149
            ('host', 'A'): ['192.0.2.1'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   150
            ('test', 'CNAME'): ['host'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   151
            ('*.test', 'CNAME'): ['host'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   152
        })
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   153
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   154
    def testHostAlias46(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   155
        h = Host.build('host', 'domain',
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   156
                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
   157
                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
   158
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   159
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   160
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   161
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   162
        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
   163
            ('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
   164
            ('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
   165
            ('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
   166
            ('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
   167
        })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   168
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   169
    def testHostAlias4Missing(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   170
        h = Host.build('host', 'domain',
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   171
                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
   172
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   173
                alias6  = 'test6',
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
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   176
        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
   177
            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
   178
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   179
    def testHostAlias6Missing(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   180
        h = Host.build('host', 'domain',
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   181
                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
   182
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   183
                alias6  = 'test6',
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
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   186
        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
   187
            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
   188
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   189
    def testHostDelegate(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   190
        h = Host.build('host', 'example.com',
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   191
                forward = 'host.example.net',
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   192
        )
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   193
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   194
        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
   195
            ('host', 'CNAME'): ['host.example.net.'],
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   196
        })
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   197
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   198
    def testHostForwardAlias(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   199
        h = Host.build('host', 'domain',
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   200
                forward = 'host.example.net',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   201
                alias   = 'test',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   202
        )
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   203
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   204
        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
   205
            ('host', 'CNAME'): ['host.example.net.'],
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   206
            ('test', 'CNAME'): ['host'],
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   207
        })
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   208
470
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   209
    def testHostLocation(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   210
        h = Host.build('host', 'domain',
470
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   211
                ip          = '192.0.2.1',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   212
                location    = 'test',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   213
        )
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   214
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   215
        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
   216
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   217
        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
   218
            ('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
   219
            ('test', 'CNAME'): ['host'],
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   220
        })
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   221
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   222
    def testHostLocationDomain(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   223
        h = Host.build('host', 'foo.domain',
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   224
                ip          = '192.0.2.1',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   225
                location    = 'test@bar.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   226
        )
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   227
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   228
        self.assertEquals(h.location, ('test', 'bar.domain'))
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   229
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   230
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   231
            ('host.foo', 'A'): ['192.0.2.1'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   232
            ('test.bar', 'CNAME'): ['host.foo'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   233
        })
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   234
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   235
    def testHostLocationDomainOutOfOrigin(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   236
        h = Host.build('host', 'foo.domain',
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   237
                ip          = '192.0.2.1',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   238
                location    = 'test@bar.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   239
        )
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   240
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   241
        self.assertEquals(h.location, ('test', 'bar.domain'))
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   242
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   243
        with self.assertRaises(zone.HostZoneError):
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   244
            self.assertZoneEquals(zone.host_forward(h, 'foo.domain'), {
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   245
                ('host', 'A'): ['192.0.2.1'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   246
            })
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   247
        
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   248
        # TODO
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   249
        #self.assertZoneEquals(zone.host_forward(h, 'bar.domain'), {
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   250
        #    ('test', 'CNAME'): ['host.foo'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   251
        #})
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   252
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   253
    def testHostsForward(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   254
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   255
                Host.build('foo', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   256
                    ip      = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   257
                    ip6     = '2001:db8::192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   258
                    alias   = 'test',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   259
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   260
                Host.build('bar', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   261
                    ip      = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   262
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   263
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   264
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   265
        self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), {
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   266
            ('foo', 'A'): ['192.0.2.1'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   267
            ('foo', 'AAAA'): ['2001:db8::c000:201'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   268
            ('test', 'CNAME'): ['foo'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   269
            ('bar', 'A'): ['192.0.2.2'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   270
        })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   271
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   272
    def testHostsConflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   273
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   274
                Host.build('foo', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   275
                    ip      = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   276
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   277
                Host.build('foo', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   278
                    ip      = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   279
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   280
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   281
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   282
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   283
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   284
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   285
    def testHostsAliasConflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   286
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   287
                Host.build('foo', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   288
                    ip          = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   289
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   290
                Host.build('bar', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   291
                    ip          = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   292
                    alias       = 'foo',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   293
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   294
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   295
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   296
        # with A first
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   297
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   298
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   299
    
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   300
        # also with CNAME first
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   301
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   302
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, reversed(hosts), 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   303
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   304
    def testHostsAlias4Conflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   305
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   306
                Host.build('foo', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   307
                    ip          = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   308
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   309
                Host.build('bar', 'domain',
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   310
                    ip          = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   311
                    alias4      = 'foo',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   312
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   313
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   314
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   315
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   316
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   317
    
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   318
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   319
class TestReverseZone(TestZoneMixin, unittest.TestCase):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   320
    def setUp(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   321
        self.options = Options()
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   322
        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
   323
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   324
    def testHostIP(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   325
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   326
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   327
                ip6 = '2001:db8::192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   328
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   329
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   330
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   331
            ('1', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   332
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   333
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   334
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   335
            ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   336
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   337
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   338
    def testHostIP4(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   339
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   340
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   341
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   342
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   343
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   344
            ('1', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   345
        })
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   346
        
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   347
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/16'))), {
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   348
            ('1.2', 'PTR'): ['host.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   349
        })
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   350
        
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   351
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/12'))), {
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   352
            ('1.2.0', 'PTR'): ['host.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   353
        })
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   354
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   355
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   356
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   357
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   358
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   359
    def testHostIP6(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   360
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   361
                ip6 = '2001:db8::192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   362
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   363
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   364
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   365
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   366
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   367
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   368
            ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   369
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   370
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   371
    def testHostIPOutOfPrefix(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   372
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   373
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   374
                ip6 = '2001:db8::192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   375
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   376
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   377
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.1.0/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   378
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   379
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   380
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   381
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8:1::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   382
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   383
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   384
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
   385
    def testHostDelegate(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   386
        h = Host.build('host', 'example.com',
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
   387
                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
   388
                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
   389
                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
   390
                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
   391
        )
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
   392
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
   393
        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
   394
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
   395
        })
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
   396
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
   397
        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
   398
            ('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
   399
        })
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   400
        
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   401
        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
   402
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   403
        })
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
   404
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   405
    def testHostsConflict(self):
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   406
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   407
                Host.build('foo', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   408
                    ip      = '192.0.2.1',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   409
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   410
                Host.build('bar', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   411
                    ip      = '192.0.2.1',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   412
                )
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   413
        ]
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   414
        
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   415
        with self.assertRaises(zone.HostZoneError):
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   416
            self.assertZoneEquals(zone.apply_hosts_reverse(self.options, hosts, ipaddr.IPNetwork('192.0.2.1/24')), { })
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   417
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   418
    def testHostsGenerateUnknown(self):
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   419
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   420
                Host.build('foo', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   421
                    ip      = '192.0.2.1',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   422
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   423
                Host.build('bar', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   424
                    ip      = '192.0.2.5',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   425
                ),
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   426
        ]
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   427
        
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   428
        self.options.unknown_host = 'ufc'
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   429
        self.options.hosts_domain = 'domain'
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   430
        self.assertZoneEquals(zone.apply_hosts_reverse(self.options, hosts, ipaddr.IPNetwork('192.0.2.1/29')), {
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   431
            ('1', 'PTR'): ['foo.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   432
            ('2', 'PTR'): ['ufc.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   433
            ('3', 'PTR'): ['ufc.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   434
            ('4', 'PTR'): ['ufc.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   435
            ('5', 'PTR'): ['bar.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   436
            ('6', 'PTR'): ['ufc.domain.'],
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   437
        })
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   438
479
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   439
class TestDhcp(unittest.TestCase):
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   440
    def setUp(self):
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   441
        self.options = pvl.args.options(
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   442
                hosts_charset   = 'utf-8',
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   443
                hosts_domain    = None,
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   444
                hosts_include   = None,
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   445
        )
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   446
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   447
    def assertBlocksEqual(self, blockdefs, expected):
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   448
        for (_block, _items, _opts), (block, items, opts) in zip(blockdefs, expected):
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   449
            self.assertEqual(_block, block)
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   450
            self.assertItemsEqual(_items, items)
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   451
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   452
            if opts is not None:
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   453
                self.assertEqual(_opts, opts)
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   454
        
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   455
        self.assertEqual(len(blockdefs), len(expected))
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   456
    
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   457
    def testHost(self):
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   458
        host = Host.build('foo', 'test',
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   459
                ip          = '192.0.2.1',
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   460
                ethernet    = '00:11:22:33:44:55',
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   461
        )
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   462
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   463
        self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   464
            (('host', 'foo'), [
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   465
                ('option', 'host-name', "foo"),
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   466
                ('fixed-address', '192.0.2.1'),
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   467
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   468
            ], None)
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   469
        ])
1e68e3a30b51 pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 477
diff changeset
   470
480
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   471
    def testHostDynamic(self):
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   472
        host = Host.build('foo', 'test',
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   473
                ethernet    = '00:11:22:33:44:55',
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   474
        )
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   475
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   476
        self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   477
            (('host', 'foo'), [
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   478
                ('option', 'host-name', "foo"),
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   479
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   480
            ], None)
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   481
        ])
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   482
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   483
    def testHostBoot(self):
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   484
        host = Host.build('foo', 'test',
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   485
                ethernet    = '00:11:22:33:44:55',
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   486
                boot        = 'boot.lan:debian/wheezy/pxelinux.0',
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   487
        )
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   488
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   489
        self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   490
            (('host', 'foo'), [
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   491
                ('option', 'host-name', "foo"),
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   492
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   493
                ('next-server', 'boot.lan'),
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   494
                ('filename', 'debian/wheezy/pxelinux.0'),
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   495
            ], None)
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   496
        ])
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   497
483
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   498
    def testHosts(self):
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   499
        hosts = [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   500
                Host.build('foo', 'test',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   501
                        ip          = '192.0.2.1',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   502
                        ethernet    = '00:11:22:33:44:55',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   503
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   504
                Host.build('bar', 'test',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   505
                        ip          = '192.0.2.2',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   506
                        ethernet    = '01:23:45:67:89:ab',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   507
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   508
        ]
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   509
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   510
        self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   511
            (('host', 'foo'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   512
                ('option', 'host-name', "foo"),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   513
                ('fixed-address', '192.0.2.1'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   514
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   515
            ], None),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   516
            (('host', 'bar'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   517
                ('option', 'host-name', "bar"),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   518
                ('fixed-address', '192.0.2.2'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   519
                ('hardware', 'ethernet', '01:23:45:67:89:ab'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   520
            ], None),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   521
        ])
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   522
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   523
    def testHostConflict(self):
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   524
        hosts = [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   525
                Host.build('foo', 'test1',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   526
                        ethernet    = '00:11:22:33:44:55',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   527
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   528
                Host.build('foo', 'test2',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   529
                        ethernet    = '01:23:45:67:89:ab',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   530
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   531
        ]
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   532
        
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   533
        with self.assertRaises(dhcp.HostDHCPError):
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   534
            list(dhcp.dhcp_hosts(hosts))
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   535
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   536
    def testHostMultinet(self):
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   537
        hosts = [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   538
                Host.build('foo', 'test1',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   539
                    ip              = '192.0.1.1',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   540
                    ethernet        = { 'eth1': '00:11:22:33:44:55' },
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   541
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   542
                Host.build('foo', 'test2',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   543
                    ip              = '192.0.2.1',
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   544
                    ethernet        = { 'eth2': '01:23:45:67:89:ab' },
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   545
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   546
        ]
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   547
        
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   548
        self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   549
                (('host', 'foo-eth1'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   550
                    ('option', 'host-name', "foo"),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   551
                    ('fixed-address', '192.0.1.1'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   552
                    ('hardware', 'ethernet', '00:11:22:33:44:55'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   553
                ], None),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   554
                (('host', 'foo-eth2'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   555
                    ('option', 'host-name', "foo"),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   556
                    ('fixed-address', '192.0.2.1'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   557
                    ('hardware', 'ethernet', '01:23:45:67:89:ab'),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   558
                ], None),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   559
        ])
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   560
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   561
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
   562
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
   563
    unittest.main()