diff -r 5149c39f3dfc -r 74352351d6f5 pvl/hosts/tests.py --- a/pvl/hosts/tests.py Tue Mar 10 00:11:43 2015 +0200 +++ b/pvl/hosts/tests.py Tue Mar 10 00:26:31 2015 +0200 @@ -1,4 +1,4 @@ -import ipaddr +import ipaddress import itertools import pvl.args import unittest @@ -122,11 +122,11 @@ def testApplyHostExpand(self): self.assertHostsEqual(config.apply_hosts('test', 'asdf{1-3}', - { 'ip': '10.100.100.$' } + { 'ip': u'10.100.100.$' } ), [ - ('asdf1@test', dict(ip4=ipaddr.IPAddress('10.100.100.1'))), - ('asdf2@test', dict(ip4=ipaddr.IPAddress('10.100.100.2'))), - ('asdf3@test', dict(ip4=ipaddr.IPAddress('10.100.100.3'))), + ('asdf1@test', dict(ip4=ipaddress.ip_address(u'10.100.100.1'))), + ('asdf2@test', dict(ip4=ipaddress.ip_address(u'10.100.100.2'))), + ('asdf3@test', dict(ip4=ipaddress.ip_address(u'10.100.100.3'))), ]) def testApplyHostsFileError(self): @@ -143,8 +143,8 @@ """) self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [ - ('foo@test', dict(ip4=ipaddr.IPAddress('127.0.0.1'))), - ('bar@test', dict(ip4=ipaddr.IPAddress('127.0.0.2'))), + ('foo@test', dict(ip4=ipaddress.ip_address(u'127.0.0.1'))), + ('bar@test', dict(ip4=ipaddress.ip_address(u'127.0.0.2'))), ]) def testApplyHostsConfigNested(self): @@ -159,8 +159,8 @@ """) self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [ - ('foo@asdf.test', dict(ip4=ipaddr.IPAddress('127.0.0.1'))), - ('bar@quux.test', dict(ip4=ipaddr.IPAddress('127.0.0.2'))), + ('foo@asdf.test', dict(ip4=ipaddress.ip_address(u'127.0.0.1'))), + ('bar@quux.test', dict(ip4=ipaddress.ip_address(u'127.0.0.2'))), ]) def testHostsConfigDdefaults(self): @@ -175,7 +175,7 @@ self.assertHostsEqual(hosts, [ ('foo@test', dict( - ip4 = ipaddr.IPAddress('192.0.2.1'), + ip4 = ipaddress.ip_address(u'192.0.2.1'), ethernet = { 'eth0': '00:11:22:33:44:55' }, extensions = dict( dhcp = { 'next_server': 'boot.lan', 'filename': '/pxelinux.0' } @@ -188,10 +188,10 @@ def testApplyIncludes(self): self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test']), [ ('bar@test', dict( - ip4 = ipaddr.IPAddress('192.0.2.2'), + ip4 = ipaddress.ip_address(u'192.0.2.2'), )), ('foo@test', dict( - ip4 = ipaddr.IPAddress('192.0.2.1'), + ip4 = ipaddress.ip_address(u'192.0.2.1'), )), ]) @@ -202,10 +202,10 @@ include = etc/hosts/test """)), [ ('bar@test', dict( - ip4 = ipaddr.IPAddress('192.0.2.2'), + ip4 = ipaddress.ip_address(u'192.0.2.2'), )), ('foo@test', dict( - ip4 = ipaddr.IPAddress('192.0.2.1'), + ip4 = ipaddress.ip_address(u'192.0.2.1'), )), ]) @@ -220,13 +220,13 @@ self.assertHostsEqual(hosts, [ ('quux@asdf.test', dict( - ip4 = ipaddr.IPAddress('192.0.2.5'), + ip4 = ipaddress.ip_address(u'192.0.2.5'), )), ('bar@test', dict( - ip4 = ipaddr.IPAddress('192.0.2.2'), + ip4 = ipaddress.ip_address(u'192.0.2.2'), )), ('foo@test', dict( - ip4 = ipaddr.IPAddress('192.0.2.1'), + ip4 = ipaddress.ip_address(u'192.0.2.1'), )), ]) @@ -242,11 +242,11 @@ def testApply(self): self.assertHostsEqual(config.apply(self.options, ['etc/hosts/example.com']), [ ('foo@example.com', dict( - ip4 = ipaddr.IPAddress('192.0.2.1'), + ip4 = ipaddress.ip_address(u'192.0.2.1'), ethernet = {None: '00:11:22:33:44:55'}, )), ('bar@example.com', dict( - ip4 = ipaddr.IPAddress('192.0.2.2'), + ip4 = ipaddress.ip_address(u'192.0.2.2'), ethernet = {None: '01:23:45:67:89:ab'}, )), ]) @@ -278,15 +278,15 @@ class TestForwardZone(TestZoneMixin, unittest.TestCase): def testHostOutOfOrigin(self): h = Host.build('host', 'domain', - ip = '10.0.0.1', + ip = u'10.0.0.1', ) self.assertZoneEquals(zone.host_forward(h, 'test'), { }) def testHostIP(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', - ip6 = '2001:db8::192.0.2.1', + ip = u'192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', ) self.assertZoneEquals(zone.host_forward(h, 'domain'), { @@ -296,7 +296,7 @@ def testHostAlias(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', alias = 'test *.test', ) @@ -310,8 +310,8 @@ def testHostAlias46(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', - ip6 = '2001:db8::192.0.2.1', + ip = u'192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', alias4 = 'test4', alias6 = 'test6', ) @@ -325,7 +325,7 @@ def testHostAlias4Missing(self): h = Host.build('host', 'domain', - ip6 = '2001:db8::192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', alias4 = 'test4', alias6 = 'test6', ) @@ -335,7 +335,7 @@ def testHostAlias6Missing(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', alias4 = 'test4', alias6 = 'test6', ) @@ -345,7 +345,7 @@ def testHostFQDN(self): h = Host.build('host.example.net', None, - ip = '192.0.2.3', + ip = u'192.0.2.3', ) self.assertZoneEquals(zone.host_forward(h, 'example.com'), { @@ -374,7 +374,7 @@ def testHostLocation(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', location = 'test', ) @@ -387,7 +387,7 @@ def testHostLocationDomain(self): h = Host.build('host', 'foo.domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', location = 'test@bar.domain', ) @@ -400,7 +400,7 @@ def testHostLocationDomainOutOfOrigin(self): h = Host.build('host', 'foo.domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', location = 'test@bar.domain', ) @@ -419,15 +419,15 @@ def testHostsForward(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', - ip6 = '2001:db8::192.0.2.1', + ip = u'192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', alias = 'test', ), Host.build('bar', 'domain', - ip = '192.0.2.2', + ip = u'192.0.2.2', ), Host.build('quux', 'example', - ip = '192.0.2.3', + ip = u'192.0.2.3', ), ] @@ -448,11 +448,11 @@ def testHostsMultiAlias(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', alias4 = 'test', ), Host.build('bar', 'domain', - ip = '192.0.2.2', + ip = u'192.0.2.2', alias4 = 'test', ) ] @@ -466,10 +466,10 @@ def testHostsConflict(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ), Host.build('foo', 'domain', - ip = '192.0.2.2', + ip = u'192.0.2.2', ) ] @@ -479,10 +479,10 @@ def testHostsAliasConflict(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ), Host.build('bar', 'domain', - ip = '192.0.2.2', + ip = u'192.0.2.2', alias = 'foo', ) ] @@ -498,10 +498,10 @@ def testHostsAlias4Conflict(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ), Host.build('bar', 'domain', - ip = '192.0.2.2', + ip = u'192.0.2.2', alias4 = 'foo', ) ] @@ -513,84 +513,84 @@ class TestReverseZone(TestZoneMixin, unittest.TestCase): def testHostIP(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', - ip6 = '2001:db8::192.0.2.1', + ip = u'192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', ) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.2.0/24'))), { ('1', 'PTR'): 'host.domain.', }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'2001:db8::/64'))), { ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): 'host.domain.', }) def testHostIP4(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.2.0/24'))), { ('1', 'PTR'): 'host.domain.', }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/16'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.0.0/16'))), { ('1.2', 'PTR'): 'host.domain.', }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/12'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.0.0/12'))), { ('1.2.0', 'PTR'): 'host.domain.', }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'2001:db8::/64'))), { }) def testHostIP6(self): h = Host.build('host', 'domain', - ip6 = '2001:db8::192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', ) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.2.0/24'))), { }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'2001:db8::/64'))), { ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): 'host.domain.', }) def testHostIPOutOfPrefix(self): h = Host.build('host', 'domain', - ip = '192.0.2.1', - ip6 = '2001:db8::192.0.2.1', + ip = u'192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', ) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.1.0/24'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.1.0/24'))), { }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8:1::/64'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'2001:db8:1::/64'))), { }) def testHostFQDN(self): h = Host.build('host.example.net', None, - ip = '192.0.2.3', - ip6 = '2001:db8::192.0.2.3', + ip = u'192.0.2.3', + ip6 = u'2001:db8::192.0.2.3', ) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.2.0/24'))), { ('3', 'PTR'): 'host.example.net.', }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'2001:db8::/64'))), { ('3.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): 'host.example.net.', }) def testHostDelegate(self): h = Host.build('host', 'example.com', - ip = '192.0.2.1', - ip6 = '2001:db8::192.0.2.1', + ip = u'192.0.2.1', + ip6 = u'2001:db8::192.0.2.1', forward = '', reverse = '1.0/28.2.0.192.in-addr.arpa', ) @@ -599,31 +599,31 @@ }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'192.0.2.0/24'))), { ('1', 'CNAME'): '1.0/28.2.0.192.in-addr.arpa.', }) - self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { + self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddress.ip_network(u'2001:db8::/64'))), { }) def testHosts(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ), Host.build('bar', 'domain', - ip = '192.0.2.2', + ip = u'192.0.2.2', ) ] - self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/24')), { + self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddress.ip_network(u'192.0.2.0/24')), { ('1', 'PTR'): 'foo.domain.', ('2', 'PTR'): 'bar.domain.', }) # in ip order - self.assertZoneEquals(zone.apply_hosts_reverse(reversed(hosts), ipaddr.IPNetwork('192.0.2.1/24')), { + self.assertZoneEquals(zone.apply_hosts_reverse(reversed(hosts), ipaddress.ip_network(u'192.0.2.0/24')), { ('1', 'PTR'): 'foo.domain.', ('2', 'PTR'): 'bar.domain.', }) @@ -631,36 +631,36 @@ def testHostsConflict(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ), Host.build('bar', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ) ] with self.assertRaises(zone.HostZoneError): - self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/24')), { }) + self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddress.ip_network(u'192.0.2.0/24')), { }) def testHostsGenerateUnknown(self): hosts = [ Host.build('foo', 'domain', - ip = '192.0.2.1', + ip = u'192.0.2.1', ), Host.build('bar', 'domain', - ip = '192.0.2.5', + ip = u'192.0.2.5', ), ] - self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/29'), + self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddress.ip_network(u'192.0.2.0/29'), unknown_host = 'ufc', unknown_domain = 'domain', ), { - ('1', 'PTR'): 'foo.domain.', - ('2', 'PTR'): 'ufc.domain.', - ('3', 'PTR'): 'ufc.domain.', - ('4', 'PTR'): 'ufc.domain.', - ('5', 'PTR'): 'bar.domain.', - ('6', 'PTR'): 'ufc.domain.', + ('1', 'PTR'): u'foo.domain.', + ('2', 'PTR'): u'ufc.domain.', + ('3', 'PTR'): u'ufc.domain.', + ('4', 'PTR'): u'ufc.domain.', + ('5', 'PTR'): u'bar.domain.', + ('6', 'PTR'): u'ufc.domain.', }) class TestDhcp(unittest.TestCase): @@ -685,7 +685,7 @@ def testHost(self): host = Host.build('foo', 'test', - ip = '192.0.2.1', + ip = u'192.0.2.1', ethernet = '00:11:22:33:44:55', owner = 'foo', ) @@ -700,7 +700,7 @@ def testHostFQDN(self): host = Host.build('foo.test', 'test', - ip = '192.0.2.1', + ip = u'192.0.2.1', ethernet = '00:11:22:33:44:55', ) @@ -714,7 +714,7 @@ def testHostStatic(self): host = Host.build('foo', 'test', - ip = '192.0.2.1', + ip = u'192.0.2.1', ) self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [ @@ -781,11 +781,11 @@ def testHosts(self): hosts = [ Host.build('foo', 'test', - ip = '192.0.2.1', + ip = u'192.0.2.1', ethernet = '00:11:22:33:44:55', ), Host.build('bar', 'test', - ip = '192.0.2.2', + ip = u'192.0.2.2', ethernet = '01:23:45:67:89:ab', ), ] @@ -819,11 +819,11 @@ def testHostMultinet(self): hosts = [ Host.build('foo', 'test1', - ip = '192.0.1.1', + ip = u'192.0.1.1', ethernet = { 'eth1': '00:11:22:33:44:55' }, ), Host.build('foo', 'test2', - ip = '192.0.2.1', + ip = u'192.0.2.1', ethernet = { 'eth2': '01:23:45:67:89:ab' }, ), ]