pvl/hosts/tests.py
author Tero Marttila <tero.marttila@aalto.fi>
Tue, 03 Mar 2015 11:58:10 +0200
changeset 713 d5e2d1d9716a
parent 700 88b0d3df1ad7
child 733 45bedeba92e5
permissions -rw-r--r--
pvl.hosts.config: --hosts-include-trace to write out all included files
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
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
     2
import itertools
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
     3
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
     4
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
     5
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
     6
from pvl.hosts import config, dhcp, zone
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
     7
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
     8
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
     9
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    10
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
    11
    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
    12
        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
    13
        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
    14
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
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
    16
    def setUp(self):
490
805645dbb9bb pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    17
        self.options = pvl.args.options(
805645dbb9bb pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    18
                hosts_charset   = 'utf-8',
805645dbb9bb pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    19
                hosts_domain    = None,
805645dbb9bb pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    20
                hosts_include   = None,
713
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
    21
                hosts_include_trace = None,
490
805645dbb9bb pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    22
        )
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
    23
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    24
    def assertHostEqual(self, host, host_str, attrs):
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    25
        self.assertEquals(str(host), host_str)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    26
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    27
        for attr, value in attrs.iteritems():
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    28
            self.assertEquals(getattr(host, attr), value)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    29
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    30
    def assertHostsEqual(self, hosts, expected):
508
a47849709cbf pvl.hosts.test: fix assertHostsEqual to also compare len's
Tero Marttila <tero.marttila@aalto.fi>
parents: 507
diff changeset
    31
        hosts = list(hosts)
a47849709cbf pvl.hosts.test: fix assertHostsEqual to also compare len's
Tero Marttila <tero.marttila@aalto.fi>
parents: 507
diff changeset
    32
692
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
    33
        for host, expect in itertools.izip_longest(hosts, expected):
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
    34
            self.assertIsNotNone(host, expect)
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
    35
            self.assertIsNotNone(expect, host)
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
    36
            
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    37
            host_str, attrs = expect
441
f058fff1f272 pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents: 440
diff changeset
    38
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    39
            self.assertHostEqual(host, host_str, attrs)
508
a47849709cbf pvl.hosts.test: fix assertHostsEqual to also compare len's
Tero Marttila <tero.marttila@aalto.fi>
parents: 507
diff changeset
    40
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    41
    def testApplyHostConfigDict(self):
504
ee0a3dcacb95 pvl.hosts.config: refactor
Tero Marttila <tero.marttila@aalto.fi>
parents: 503
diff changeset
    42
        host = config.apply_host('foo', 'test', {
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    43
            '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
    44
        })
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    45
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    46
        self.assertHostEqual(host, 'foo@test', dict(
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    47
                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
    48
        ))
502
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    49
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    50
    def testApplyHostConfigDictMulti(self):
504
ee0a3dcacb95 pvl.hosts.config: refactor
Tero Marttila <tero.marttila@aalto.fi>
parents: 503
diff changeset
    51
        host = config.apply_host('foo', 'test', {
502
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    52
            'ethernet.eth0': '00:11:22:33:44:55',
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    53
            'ethernet.eth1': '00:11:22:33:44:66',
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    54
        })
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    55
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    56
        self.assertHostEqual(host, 'foo@test', dict(
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    57
                ethernet    = {
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    58
                    'eth0': '00:11:22:33:44:55',
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    59
                    'eth1': '00:11:22:33:44:66',
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    60
                }
ac4e0f2df80c pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents: 501
diff changeset
    61
        ))
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    62
   
661
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    63
    def testApplyHostsConfigErrorExtra(self):
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    64
        host = config.apply_host('foo', 'test', {
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    65
            'ethernet': '00:11:22:33:44:55',
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    66
            'ethernet.eth1': '00:11:22:33:44:66',
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    67
        })
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    68
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    69
        self.assertHostEqual(host, 'foo@test', dict(
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    70
                ethernet    = {
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    71
                    None:   '00:11:22:33:44:55',
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    72
                    'eth1': '00:11:22:33:44:66',
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    73
                }
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    74
        ))
15946375b154 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ...
Tero Marttila <terom@paivola.fi>
parents: 660
diff changeset
    75
 
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    76
501
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    77
    def testApplyHostConfigExtensions(self):
504
ee0a3dcacb95 pvl.hosts.config: refactor
Tero Marttila <tero.marttila@aalto.fi>
parents: 503
diff changeset
    78
        host = config.apply_host('foo', 'test', {
501
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    79
            'link:50':          'foo@test',
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    80
            'link:uplink.49':   'bar@test',
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    81
        })
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    82
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    83
        self.assertHostEqual(host, 'foo@test', dict(
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    84
                extensions = {
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    85
                    'link': {
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    86
                        '50': 'foo@test',
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    87
                        'uplink': { '49': 'bar@test' },
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    88
                    },
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    89
                },
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    90
        ))
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    91
   
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    92
    def testApplyHostFqdn(self):
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    93
        self.assertHostsEqual(config.apply_hosts('test', 'asdf@foo.test', { }), [
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    94
                ('asdf@foo.test', dict()),
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    95
        ])
501
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    96
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    97
        self.assertHostsEqual(config.apply_hosts('test', 'asdf.test2', { }), [
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    98
                ('asdf.test2@', dict()),
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
    99
        ])
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   100
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   101
    def testApplyHostExpand(self):
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   102
        self.assertHostsEqual(config.apply_hosts('test', 'asdf{1-3}', { 'ip': '10.100.100.$' }), [
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   103
                ('asdf1@test', dict(ip=ipaddr.IPAddress('10.100.100.1'))),
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   104
                ('asdf2@test', dict(ip=ipaddr.IPAddress('10.100.100.2'))),
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   105
                ('asdf3@test', dict(ip=ipaddr.IPAddress('10.100.100.3'))),
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   106
        ])
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   107
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   108
    def testApplyHostsFileError(self):
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   109
        with self.assertRaises(config.HostConfigError):
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   110
            list(config.apply_hosts_files(self.options, ['nonexistant']))
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   111
511
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   112
    def testApplyHostsConfig(self):
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   113
        conf_file = ConfFile('test', """
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   114
[foo]
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   115
    ip = 127.0.0.1
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   116
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   117
[bar]
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   118
    ip = 127.0.0.2
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   119
        """)
511
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   120
        
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   121
        self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   122
                ('foo@test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   123
                ('bar@test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
511
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   124
        ])
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   125
511
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   126
    def testApplyHostsConfigNested(self):
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   127
        conf_file = ConfFile('test', """
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   128
[asdf]
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   129
    [[foo]]
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   130
        ip = 127.0.0.1
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   131
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   132
[quux]
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   133
    [[bar]]
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   134
        ip = 127.0.0.2
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   135
        """)
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   136
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   137
        self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   138
                ('foo@asdf.test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   139
                ('bar@quux.test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
99043eab9140 pvl.hosts.config: change nested domains to be relative to parent domain, not absolute
Tero Marttila <tero.marttila@aalto.fi>
parents: 510
diff changeset
   140
        ])
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   141
689
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   142
    def testHostsConfigDdefaults(self):
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   143
        hosts = config.apply_hosts_config(self.options, ConfFile('test', """
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   144
boot.next-server = boot.lan
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   145
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   146
[foo]
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   147
    ip = 192.0.2.1
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   148
    ethernet.eth0 = 00:11:22:33:44:55
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   149
    boot.filename = /pxelinux.0
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   150
        """))
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   151
        
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   152
        self.assertHostsEqual(hosts, [
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   153
                ('foo@test', dict(
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   154
                    ip          = ipaddr.IPAddress('192.0.2.1'),
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   155
                    ethernet    = { 'eth0': '00:11:22:33:44:55' },
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   156
                    boot        = { 'next-server': 'boot.lan', 'filename': '/pxelinux.0' },
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   157
                )),
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   158
        ])
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   159
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   160
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   161
 
507
e3a32f4dff54 pvl.hosts.config: document includes, fix include-only zone, and test
Tero Marttila <tero.marttila@aalto.fi>
parents: 505
diff changeset
   162
    def testApplyIncludes(self):
521
06792c78067e setup and document etc/zone/ structure
Tero Marttila <tero.marttila@aalto.fi>
parents: 518
diff changeset
   163
        self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test']), [
663
8a9de457bb59 pvl.hosts.config: sort directory items for stable host ordering
Tero Marttila <terom@paivola.fi>
parents: 661
diff changeset
   164
                ('bar@test', dict(
8a9de457bb59 pvl.hosts.config: sort directory items for stable host ordering
Tero Marttila <terom@paivola.fi>
parents: 661
diff changeset
   165
                    ip          = ipaddr.IPAddress('192.0.2.2'),
8a9de457bb59 pvl.hosts.config: sort directory items for stable host ordering
Tero Marttila <terom@paivola.fi>
parents: 661
diff changeset
   166
                )),
513
3b45b4fd5102 pvl.hosts.config: revert apply_hosts_directory to treat directory contents as a flat namespace without any parent=basname(directory) magic
Tero Marttila <tero.marttila@aalto.fi>
parents: 511
diff changeset
   167
                ('foo@test', dict(
510
368a568412ed pvl.hosts.config: support direct directory hosts, using the directory name as the parent
Tero Marttila <tero.marttila@aalto.fi>
parents: 509
diff changeset
   168
                    ip          = ipaddr.IPAddress('192.0.2.1'),
368a568412ed pvl.hosts.config: support direct directory hosts, using the directory name as the parent
Tero Marttila <tero.marttila@aalto.fi>
parents: 509
diff changeset
   169
                )),
368a568412ed pvl.hosts.config: support direct directory hosts, using the directory name as the parent
Tero Marttila <tero.marttila@aalto.fi>
parents: 509
diff changeset
   170
        ])
368a568412ed pvl.hosts.config: support direct directory hosts, using the directory name as the parent
Tero Marttila <tero.marttila@aalto.fi>
parents: 509
diff changeset
   171
692
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   172
    def testApplyIncludesDefaults(self):
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   173
        self.assertHostsEqual(config.apply_hosts_config(self.options, ConfFile('test', """
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   174
boot.next-server = boot.lan
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   175
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   176
include = etc/hosts/test
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   177
        """)), [
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   178
                ('bar@test', dict(
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   179
                    ip          = ipaddr.IPAddress('192.0.2.2'),
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   180
                )),
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   181
                ('foo@test', dict(
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   182
                    ip          = ipaddr.IPAddress('192.0.2.1'),
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   183
                )),
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   184
        ])
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   185
34f25380d0e7 pvl.hosts.config: support defaults for included hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 689
diff changeset
   186
518
cd152d6bad32 pvl.hosts.config: test and fix includes path
Tero Marttila <tero.marttila@aalto.fi>
parents: 513
diff changeset
   187
    def testApplyIncludePath(self):
521
06792c78067e setup and document etc/zone/ structure
Tero Marttila <tero.marttila@aalto.fi>
parents: 518
diff changeset
   188
        self.options.hosts_include = 'etc/hosts'
713
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   189
        include_trace = [ ]
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   190
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   191
        hosts = list(config.apply_hosts_files(self.options, ['etc/zones/forward/test'],
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   192
            include_trace   = include_trace,
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   193
        ))
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   194
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   195
        self.assertHostsEqual(hosts, [
663
8a9de457bb59 pvl.hosts.config: sort directory items for stable host ordering
Tero Marttila <terom@paivola.fi>
parents: 661
diff changeset
   196
                ('quux@asdf.test', dict(
8a9de457bb59 pvl.hosts.config: sort directory items for stable host ordering
Tero Marttila <terom@paivola.fi>
parents: 661
diff changeset
   197
                    ip          = ipaddr.IPAddress('192.0.2.5'),
518
cd152d6bad32 pvl.hosts.config: test and fix includes path
Tero Marttila <tero.marttila@aalto.fi>
parents: 513
diff changeset
   198
                )),
cd152d6bad32 pvl.hosts.config: test and fix includes path
Tero Marttila <tero.marttila@aalto.fi>
parents: 513
diff changeset
   199
                ('bar@test', dict(
cd152d6bad32 pvl.hosts.config: test and fix includes path
Tero Marttila <tero.marttila@aalto.fi>
parents: 513
diff changeset
   200
                    ip          = ipaddr.IPAddress('192.0.2.2'),
cd152d6bad32 pvl.hosts.config: test and fix includes path
Tero Marttila <tero.marttila@aalto.fi>
parents: 513
diff changeset
   201
                )),
663
8a9de457bb59 pvl.hosts.config: sort directory items for stable host ordering
Tero Marttila <terom@paivola.fi>
parents: 661
diff changeset
   202
                ('foo@test', dict(
8a9de457bb59 pvl.hosts.config: sort directory items for stable host ordering
Tero Marttila <terom@paivola.fi>
parents: 661
diff changeset
   203
                    ip          = ipaddr.IPAddress('192.0.2.1'),
660
5461fb492345 pvl.hosts.tests: tweak etc/zones/forward/test ordering..
Tero Marttila <terom@paivola.fi>
parents: 521
diff changeset
   204
                )),
518
cd152d6bad32 pvl.hosts.config: test and fix includes path
Tero Marttila <tero.marttila@aalto.fi>
parents: 513
diff changeset
   205
        ])
cd152d6bad32 pvl.hosts.config: test and fix includes path
Tero Marttila <tero.marttila@aalto.fi>
parents: 513
diff changeset
   206
713
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   207
        self.assertEqual(include_trace, [
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   208
            'etc/zones/forward/test',
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   209
            'etc/zones/forward/test/asdf.test',
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   210
            'etc/zones/forward/test/test',
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   211
            'etc/hosts/test.d/',
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   212
            'etc/hosts/test.d/bar',
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   213
            'etc/hosts/test.d/foo',
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   214
        ])
d5e2d1d9716a pvl.hosts.config: --hosts-include-trace to write out all included files
Tero Marttila <tero.marttila@aalto.fi>
parents: 700
diff changeset
   215
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   216
    def testApply(self):
513
3b45b4fd5102 pvl.hosts.config: revert apply_hosts_directory to treat directory contents as a flat namespace without any parent=basname(directory) magic
Tero Marttila <tero.marttila@aalto.fi>
parents: 511
diff changeset
   217
        self.assertHostsEqual(config.apply(self.options, ['etc/hosts/example.com']), [
3b45b4fd5102 pvl.hosts.config: revert apply_hosts_directory to treat directory contents as a flat namespace without any parent=basname(directory) magic
Tero Marttila <tero.marttila@aalto.fi>
parents: 511
diff changeset
   218
                ('foo@example.com', dict(
3b45b4fd5102 pvl.hosts.config: revert apply_hosts_directory to treat directory contents as a flat namespace without any parent=basname(directory) magic
Tero Marttila <tero.marttila@aalto.fi>
parents: 511
diff changeset
   219
                    ip          = ipaddr.IPAddress('192.0.2.1'),
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   220
                    ethernet    = {None: '00:11:22:33:44:55'},
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   221
                )),
513
3b45b4fd5102 pvl.hosts.config: revert apply_hosts_directory to treat directory contents as a flat namespace without any parent=basname(directory) magic
Tero Marttila <tero.marttila@aalto.fi>
parents: 511
diff changeset
   222
                ('bar@example.com', dict(
3b45b4fd5102 pvl.hosts.config: revert apply_hosts_directory to treat directory contents as a flat namespace without any parent=basname(directory) magic
Tero Marttila <tero.marttila@aalto.fi>
parents: 511
diff changeset
   223
                    ip          = ipaddr.IPAddress('192.0.2.2'),
505
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   224
                    ethernet    = {None: '01:23:45:67:89:ab'},
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   225
                )),
e5a76c404679 pvl.hosts.test: rearrange TestConfig test cases
Tero Marttila <tero.marttila@aalto.fi>
parents: 504
diff changeset
   226
        ])
501
41b362e6074b pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
   227
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   228
class 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
   229
    def assertZoneEquals(self, rrs, expected):
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   230
        """
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   231
            Tests that the given list of ZoneRecords is equal to the given {(rr.name, rr.type): str(rr.data)} dict.
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   232
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   233
            Multiple records for the same name/type are gathered as a list. XXX: ordering
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   234
        """
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   235
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
   236
        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
   237
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   238
        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
   239
            key = (rr.name.lower(), rr.type.upper())
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   240
            value = '\t'.join(rr.data)
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   241
            
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   242
            if key not in gather:
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   243
                gather[key] = value
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   244
            elif not isinstance(gather[key], list):
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   245
                gather[key] = [gather[key], value]
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   246
            else:
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   247
                gather[key].append(value)
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
   248
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
   249
        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
   250
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   251
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   252
class TestForwardZone(TestZoneMixin, unittest.TestCase):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   253
    def testHostOutOfOrigin(self):
504
ee0a3dcacb95 pvl.hosts.config: refactor
Tero Marttila <tero.marttila@aalto.fi>
parents: 503
diff changeset
   254
        h = Host.build('host', 'domain', 
ee0a3dcacb95 pvl.hosts.config: refactor
Tero Marttila <tero.marttila@aalto.fi>
parents: 503
diff changeset
   255
                ip  = '10.0.0.1',
ee0a3dcacb95 pvl.hosts.config: refactor
Tero Marttila <tero.marttila@aalto.fi>
parents: 503
diff changeset
   256
        )
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
   257
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
   258
        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
   259
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   260
    def testHostIP(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   261
        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
   262
                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
   263
                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
   264
        )
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
   265
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
   266
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   267
            ('host', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   268
            ('host', 'AAAA'): '2001:db8::c000:201',
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
   269
        })
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   270
    
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   271
    def testHostAlias(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   272
        h = Host.build('host', 'domain',
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   273
                ip      = '192.0.2.1',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   274
                alias   = 'test *.test',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   275
        )
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   276
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   277
        self.assertEquals(h.alias, ['test', '*.test'])
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   278
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   279
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   280
            ('host', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   281
            ('test', 'CNAME'): 'host',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   282
            ('*.test', 'CNAME'): 'host',
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   283
        })
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   284
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   285
    def testHostAlias46(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   286
        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
   287
                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
   288
                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
   289
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   290
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   291
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   292
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   293
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   294
            ('host', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   295
            ('host', 'AAAA'): '2001:db8::c000:201',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   296
            ('test4', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   297
            ('test6', 'AAAA'): '2001:db8::c000:201',
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   298
        })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   299
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   300
    def testHostAlias4Missing(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   301
        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
   302
                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
   303
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   304
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   305
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   306
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   307
        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
   308
            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
   309
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   310
    def testHostAlias6Missing(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   311
        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
   312
                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
   313
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   314
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   315
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   316
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   317
        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
   318
            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
   319
493
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   320
    def testHostFQDN(self):
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   321
        h = Host.build('host.example.net', None,
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   322
                ip          = '192.0.2.3',
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   323
        )
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   324
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   325
        self.assertZoneEquals(zone.host_forward(h, 'example.com'), {
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   326
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   327
        })
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   328
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   329
    def testHostDelegate(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   330
        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
   331
                forward = 'host.example.net',
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   332
        )
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   333
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   334
        self.assertZoneEquals(zone.host_forward(h, 'example.com'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   335
            ('host', 'CNAME'): 'host.example.net.',
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   336
        })
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   337
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   338
    def testHostForwardAlias(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',
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   340
                forward = 'host.example.net',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   341
                alias   = 'test',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   342
        )
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   343
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   344
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   345
            ('host', 'CNAME'): 'host.example.net.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   346
            ('test', 'CNAME'): 'host',
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   347
        })
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   348
470
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   349
    def testHostLocation(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   350
        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
   351
                ip          = '192.0.2.1',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   352
                location    = 'test',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   353
        )
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   354
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   355
        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
   356
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   357
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   358
            ('host', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   359
            ('test', 'CNAME'): 'host',
470
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   360
        })
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   361
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   362
    def testHostLocationDomain(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   363
        h = Host.build('host', 'foo.domain',
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   364
                ip          = '192.0.2.1',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   365
                location    = 'test@bar.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   366
        )
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   367
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   368
        self.assertEquals(h.location, ('test', 'bar.domain'))
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   369
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   370
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   371
            ('host.foo', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   372
            ('test.bar', 'CNAME'): 'host.foo',
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   373
        })
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   374
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   375
    def testHostLocationDomainOutOfOrigin(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   376
        h = Host.build('host', 'foo.domain',
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   377
                ip          = '192.0.2.1',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   378
                location    = 'test@bar.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   379
        )
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   380
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   381
        self.assertEquals(h.location, ('test', 'bar.domain'))
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   382
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   383
        with self.assertRaises(zone.HostZoneError):
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   384
            self.assertZoneEquals(zone.host_forward(h, 'foo.domain'), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   385
                ('host', 'A'): '192.0.2.1',
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   386
            })
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   387
        
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   388
        # TODO
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   389
        #self.assertZoneEquals(zone.host_forward(h, 'bar.domain'), {
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   390
        #    ('test', 'CNAME'): ['host.foo'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   391
        #})
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   392
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   393
    def testHostsForward(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   394
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   395
                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
   396
                    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
   397
                    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
   398
                    alias   = 'test',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   399
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   400
                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
   401
                    ip      = '192.0.2.2',
496
530f22575889 pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents: 494
diff changeset
   402
                ),
530f22575889 pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents: 494
diff changeset
   403
                Host.build('quux', 'example',
530f22575889 pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents: 494
diff changeset
   404
                    ip      = '192.0.2.3',
530f22575889 pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents: 494
diff changeset
   405
                ),
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   406
        ]
497
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   407
                
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   408
        rrs = zone.apply_hosts_forward(hosts, 'domain', add_origin=True)
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   409
    
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   410
        # handle the $ORIGIN directive
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   411
        rd = next(rrs)
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   412
497
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   413
        self.assertEquals(unicode(rd), '$ORIGIN\tdomain.')
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   414
0082d2092d1f pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents: 496
diff changeset
   415
        self.assertZoneEquals(rrs, {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   416
            ('foo', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   417
            ('foo', 'AAAA'): '2001:db8::c000:201',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   418
            ('test', 'CNAME'): 'foo',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   419
            ('bar', 'A'): '192.0.2.2',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   420
        })
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   421
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   422
    def testHostsMultiAlias(self):
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   423
        hosts = [
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   424
                Host.build('foo', 'domain',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   425
                    ip      = '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   426
                    alias4  = 'test',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   427
                ),
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   428
                Host.build('bar', 'domain',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   429
                    ip      = '192.0.2.2',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   430
                    alias4  = 'test',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   431
                )
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   432
        ]
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   433
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   434
        self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain', check_conflicts=False), {
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   435
            ('foo', 'A'): '192.0.2.1',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   436
            ('bar', 'A'): '192.0.2.2',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   437
            ('test', 'A'): ['192.0.2.1', '192.0.2.2'],
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   438
        })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   439
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   440
    def testHostsConflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   441
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   442
                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
   443
                    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
   444
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   445
                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
   446
                    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
   447
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   448
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   449
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   450
        with self.assertRaises(zone.HostZoneError):
687
f99f9e3d02cf pvl.hosts.zone: make non-CNAME check_conflicts optional
Tero Marttila <tero.marttila@aalto.fi>
parents: 677
diff changeset
   451
            self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain', check_conflicts=True), { })
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   452
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   453
    def testHostsAliasConflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   454
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   455
                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
   456
                    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
   457
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   458
                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
   459
                    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
   460
                    alias       = 'foo',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   461
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   462
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   463
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   464
        # with A first
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   465
        with self.assertRaises(zone.HostZoneError):
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   466
            self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain'), { })
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   467
    
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   468
        # 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
   469
        with self.assertRaises(zone.HostZoneError):
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   470
            self.assertZoneEquals(zone.apply_hosts_forward(reversed(hosts), 'domain'), { })
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   471
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   472
    def testHostsAlias4Conflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   473
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   474
                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
   475
                    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
   476
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   477
                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
   478
                    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
   479
                    alias4      = 'foo',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   480
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   481
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   482
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   483
        with self.assertRaises(zone.HostZoneError):
687
f99f9e3d02cf pvl.hosts.zone: make non-CNAME check_conflicts optional
Tero Marttila <tero.marttila@aalto.fi>
parents: 677
diff changeset
   484
            self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain', check_conflicts=True), { })
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   485
    
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   486
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   487
class TestReverseZone(TestZoneMixin, unittest.TestCase):
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   488
    def testHostIP(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   489
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   490
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   491
                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
   492
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   493
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   494
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   495
            ('1', 'PTR'): 'host.domain.',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   496
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   497
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   498
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   499
            ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): 'host.domain.',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   500
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   501
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   502
    def testHostIP4(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   503
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   504
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   505
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   506
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   507
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   508
            ('1', 'PTR'): 'host.domain.',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   509
        })
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   510
        
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   511
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/16'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   512
            ('1.2', 'PTR'): 'host.domain.',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   513
        })
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   514
        
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   515
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/12'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   516
            ('1.2.0', 'PTR'): 'host.domain.',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   517
        })
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   518
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   519
        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
   520
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   521
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   522
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   523
    def testHostIP6(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   524
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   525
                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
   526
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   527
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   528
        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
   529
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   530
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   531
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   532
            ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): 'host.domain.',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   533
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   534
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   535
    def testHostIPOutOfPrefix(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   536
        h = Host.build('host', 'domain',
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   537
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   538
                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
   539
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   540
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   541
        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
   542
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   543
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   544
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   545
        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
   546
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   547
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   548
493
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   549
    def testHostFQDN(self):
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   550
        h = Host.build('host.example.net', None,
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   551
                ip          = '192.0.2.3',
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   552
                ip6         = '2001:db8::192.0.2.3',
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   553
        )
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   554
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   555
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   556
            ('3', 'PTR'): 'host.example.net.',
493
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   557
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   558
        })
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   559
        
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   560
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   561
            ('3.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): 'host.example.net.',
493
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   562
        })
c9725dd0d48c pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 492
diff changeset
   563
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
   564
    def testHostDelegate(self):
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   565
        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
   566
                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
   567
                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
   568
                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
   569
                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
   570
        )
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
   571
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
   572
        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
   573
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
   574
        })
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
   575
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
   576
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   577
            ('1', 'CNAME'): '1.0/28.2.0.192.in-addr.arpa.',
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
   578
        })
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   579
        
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   580
        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
   581
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   582
        })
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
   583
494
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   584
    def testHosts(self):
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   585
        hosts = [
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   586
                Host.build('foo', 'domain',
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   587
                    ip      = '192.0.2.1',
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   588
                ),
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   589
                Host.build('bar', 'domain',
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   590
                    ip      = '192.0.2.2',
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   591
                )
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   592
        ]
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   593
        
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   594
        self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/24')), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   595
            ('1', 'PTR'): 'foo.domain.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   596
            ('2', 'PTR'): 'bar.domain.',
494
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   597
        })
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   598
        
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   599
        # in ip order
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   600
        self.assertZoneEquals(zone.apply_hosts_reverse(reversed(hosts), ipaddr.IPNetwork('192.0.2.1/24')), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   601
            ('1', 'PTR'): 'foo.domain.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   602
            ('2', 'PTR'): 'bar.domain.',
494
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   603
        })
6d258338b363 pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 493
diff changeset
   604
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   605
    def testHostsConflict(self):
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   606
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   607
                Host.build('foo', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   608
                    ip      = '192.0.2.1',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   609
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   610
                Host.build('bar', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   611
                    ip      = '192.0.2.1',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   612
                )
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   613
        ]
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   614
        
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   615
        with self.assertRaises(zone.HostZoneError):
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   616
            self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/24')), { })
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   617
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   618
    def testHostsGenerateUnknown(self):
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   619
        hosts = [
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   620
                Host.build('foo', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   621
                    ip      = '192.0.2.1',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   622
                ),
477
6ad810c8039c pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents: 474
diff changeset
   623
                Host.build('bar', 'domain',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   624
                    ip      = '192.0.2.5',
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   625
                ),
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   626
        ]
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   627
        
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   628
        self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/29'),
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   629
                unknown_host = 'ufc',
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   630
                unknown_domain = 'domain',
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   631
        ), {
688
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   632
            ('1', 'PTR'): 'foo.domain.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   633
            ('2', 'PTR'): 'ufc.domain.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   634
            ('3', 'PTR'): 'ufc.domain.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   635
            ('4', 'PTR'): 'ufc.domain.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   636
            ('5', 'PTR'): 'bar.domain.',
dfc5fcb6a06c pvl.hosts.tests: support multiple values for record name/type in assertZoneEquals; test multi-alias hosts
Tero Marttila <tero.marttila@aalto.fi>
parents: 687
diff changeset
   637
            ('6', 'PTR'): 'ufc.domain.',
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 473
diff changeset
   638
        })
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   639
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
   640
class TestDhcp(unittest.TestCase):
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   641
    def assertBlockEqual(self, block, (key, items, blocks)):
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   642
        self.assertEqual(block.key, key)
697
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   643
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   644
        for _item, item in itertools.izip_longest(sorted(block.items), sorted(items)):
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   645
            self.assertIsNotNone(_item, item)
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   646
            self.assertIsNotNone(item, _item)
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   647
            
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   648
            self.assertEqual(tuple(pvl.dhcp.config.quote(field) for field in _item), item)
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
   649
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   650
        for _block, expect_block in itertools.izip_longest(block.blocks, blocks):
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   651
            self.assertBlockEqual(_block, expect_block)
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   652
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   653
    def assertBlocksEqual(self, blocks, expected):
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   654
        for _block, block in itertools.izip_longest(blocks, expected):
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   655
            self.assertIsNotNone(_block, block)
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   656
            self.assertIsNotNone(block, _block)
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   657
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   658
            self.assertBlockEqual(_block, block)
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
   659
    
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
   660
    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
   661
        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
   662
                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
   663
                ethernet    = '00:11:22:33:44:55',
492
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   664
                owner       = 'foo',
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
   665
        )
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
   666
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
   667
        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
   668
            (('host', 'foo'), [
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   669
                    ('option', 'host-name', "foo"),
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   670
                    ('fixed-address', '192.0.2.1'),
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   671
                    ('hardware', 'ethernet', '00:11:22:33:44:55'),
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   672
            ], [])
492
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   673
        ])
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   674
677
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   675
    def testHostFQDN(self):
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   676
        host = Host.build('foo.test', 'test',
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   677
                ip          = '192.0.2.1',
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   678
                ethernet    = '00:11:22:33:44:55',
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   679
        )
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   680
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   681
        self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   682
            (('host', 'foo.test'), [
697
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   683
                    ('option', 'host-name', '"foo.test"'),
677
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   684
                    ('fixed-address', '192.0.2.1'),
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   685
                    ('hardware', 'ethernet', '00:11:22:33:44:55'),
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   686
            ], [])
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   687
        ])
8e3dfa27d8d1 pvl.hosts.test: host with fqdn name still gets a dhcp option host-name
Tero Marttila <terom@paivola.fi>
parents: 669
diff changeset
   688
492
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   689
    def testHostStatic(self):
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   690
        host = Host.build('foo', 'test',
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   691
                ip          = '192.0.2.1',
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   692
        )
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   693
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   694
        self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [
ddd13dadf6a8 pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents: 491
diff changeset
   695
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
   696
        ])
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
   697
480
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   698
    def testHostDynamic(self):
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   699
        host = Host.build('foo', 'test',
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   700
                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
   701
        )
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   702
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   703
        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
   704
            (('host', 'foo'), [
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   705
                ('option', 'host-name', "foo"),
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   706
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   707
            ], [])
480
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   708
        ])
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   709
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   710
    def testHostBoot(self):
491
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   711
        hosts = [
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   712
                Host.build('foo1', 'test',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   713
                        ethernet    = '00:11:22:33:44:55',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   714
                        boot        = 'boot.lan:debian/wheezy/pxelinux.0',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   715
                ),
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   716
                Host.build('foo2', 'test',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   717
                        ethernet    = '00:11:22:33:44:55',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   718
                        boot        = 'boot.lan:',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   719
                ),
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   720
                Host.build('foo3', 'test',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   721
                        ethernet    = '00:11:22:33:44:55',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   722
                        boot        = '/debian/wheezy/pxelinux.0',
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   723
                ),
689
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   724
                Host.build('foo4', 'test',
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   725
                        ethernet    = '00:11:22:33:44:55',
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   726
                        boot        = {'next-server': 'boot.lan', 'filename': '/debian/wheezy/pxelinux.0' },
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   727
                ),
491
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   728
        ]
480
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   729
491
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   730
        self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   731
            (('host', 'foo1'), [
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   732
                ('option', 'host-name', "foo1"),
480
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   733
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
697
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   734
                ('next-server', '"boot.lan"'),
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   735
                ('filename', '"debian/wheezy/pxelinux.0"'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   736
            ], []),
491
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   737
            (('host', 'foo2'), [
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   738
                ('option', 'host-name', "foo2"),
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   739
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
697
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   740
                ('next-server', '"boot.lan"'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   741
            ], []),
491
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   742
            (('host', 'foo3'), [
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   743
                ('option', 'host-name', "foo3"),
cfcb47a3dc3e pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents: 490
diff changeset
   744
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
697
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   745
                ('filename', '"/debian/wheezy/pxelinux.0"'),
689
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   746
            ], []),
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   747
            (('host', 'foo4'), [
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   748
                ('option', 'host-name', "foo4"),
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   749
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
697
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   750
                ('next-server', '"boot.lan"'),
3c3ac207ce3f pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
Tero Marttila <tero.marttila@aalto.fi>
parents: 692
diff changeset
   751
                ('filename', '"/debian/wheezy/pxelinux.0"'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   752
            ], []),
480
7e44854e85d4 README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents: 479
diff changeset
   753
        ])
689
c258e3ff6d32 pvl.hosts: update boot= to support split boot.next-server= boot.filename=, which enables inheriting defaults
Tero Marttila <tero.marttila@aalto.fi>
parents: 688
diff changeset
   754
    
483
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   755
    def testHosts(self):
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   756
        hosts = [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   757
                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
   758
                        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
   759
                        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
   760
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   761
                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
   762
                        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
   763
                        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
   764
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   765
        ]
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   766
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   767
        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
   768
            (('host', 'foo'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   769
                ('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
   770
                ('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
   771
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   772
            ], []),
483
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   773
            (('host', 'bar'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   774
                ('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
   775
                ('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
   776
                ('hardware', 'ethernet', '01:23:45:67:89:ab'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   777
            ], []),
483
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   778
        ])
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   779
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   780
    def testHostConflict(self):
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   781
        hosts = [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   782
                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
   783
                        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
   784
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   785
                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
   786
                        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
   787
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   788
        ]
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   789
        
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   790
        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
   791
            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
   792
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   793
    def testHostMultinet(self):
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   794
        hosts = [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   795
                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
   796
                    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
   797
                    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
   798
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   799
                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
   800
                    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
   801
                    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
   802
                ),
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   803
        ]
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   804
        
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   805
        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
   806
                (('host', 'foo-eth1'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   807
                    ('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
   808
                    ('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
   809
                    ('hardware', 'ethernet', '00:11:22:33:44:55'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   810
                ], []),
483
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   811
                (('host', 'foo-eth2'), [
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   812
                    ('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
   813
                    ('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
   814
                    ('hardware', 'ethernet', '01:23:45:67:89:ab'),
669
83e9bff09a0b pvl.hosts.dhcp: update for pvl.dhcp.config
Tero Marttila <terom@paivola.fi>
parents: 663
diff changeset
   815
                ], []),
483
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   816
        ])
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   817
698
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   818
    def testHostSubclass(self):
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   819
        hosts = [Host.build('foo', 'test',
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   820
                ethernet    = '00:11:22:33:44:55',
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   821
                extensions  = dict(dhcp=dict(
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   822
                    subclass    = 'debian',
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   823
                )),
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   824
        )]
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   825
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   826
        self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   827
            (('host', 'foo'), [
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   828
                ('option', 'host-name', "foo"),
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   829
                ('hardware', 'ethernet', '00:11:22:33:44:55'),
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   830
            ], []),
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   831
            (None, [
700
88b0d3df1ad7 pvl.hosts.dhcp: subclass class name is a String
Tero Marttila <tero.marttila@aalto.fi>
parents: 698
diff changeset
   832
                ('subclass', '"debian"', '1:00:11:22:33:44:55'),
698
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   833
            ], []),
656178fb8607 pvl.hosts.dhcp: implement support for dhcp:subclass=... using hardware ethernet
Tero Marttila <tero.marttila@aalto.fi>
parents: 697
diff changeset
   834
        ])
483
19d084bb4afd pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents: 480
diff changeset
   835
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
   836
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
   837
    unittest.main()