pvl/hosts/tests.py
changeset 689 c258e3ff6d32
parent 688 dfc5fcb6a06c
child 692 34f25380d0e7
equal deleted inserted replaced
688:dfc5fcb6a06c 689:c258e3ff6d32
   135         self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [
   135         self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [
   136                 ('foo@asdf.test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
   136                 ('foo@asdf.test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
   137                 ('bar@quux.test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
   137                 ('bar@quux.test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
   138         ])
   138         ])
   139 
   139 
       
   140     def testHostsConfigDdefaults(self):
       
   141         hosts = config.apply_hosts_config(self.options, ConfFile('test', """
       
   142 boot.next-server = boot.lan
       
   143 
       
   144 [foo]
       
   145     ip = 192.0.2.1
       
   146     ethernet.eth0 = 00:11:22:33:44:55
       
   147     boot.filename = /pxelinux.0
       
   148         """))
       
   149         
       
   150         self.assertHostsEqual(hosts, [
       
   151                 ('foo@test', dict(
       
   152                     ip          = ipaddr.IPAddress('192.0.2.1'),
       
   153                     ethernet    = { 'eth0': '00:11:22:33:44:55' },
       
   154                     boot        = { 'next-server': 'boot.lan', 'filename': '/pxelinux.0' },
       
   155                 )),
       
   156         ])
       
   157 
       
   158 
       
   159  
   140     def testApplyIncludes(self):
   160     def testApplyIncludes(self):
   141         self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test']), [
   161         self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test']), [
   142                 ('bar@test', dict(
   162                 ('bar@test', dict(
   143                     ip          = ipaddr.IPAddress('192.0.2.2'),
   163                     ip          = ipaddr.IPAddress('192.0.2.2'),
   144                 )),
   164                 )),
   661                         boot        = 'boot.lan:',
   681                         boot        = 'boot.lan:',
   662                 ),
   682                 ),
   663                 Host.build('foo3', 'test',
   683                 Host.build('foo3', 'test',
   664                         ethernet    = '00:11:22:33:44:55',
   684                         ethernet    = '00:11:22:33:44:55',
   665                         boot        = '/debian/wheezy/pxelinux.0',
   685                         boot        = '/debian/wheezy/pxelinux.0',
       
   686                 ),
       
   687                 Host.build('foo4', 'test',
       
   688                         ethernet    = '00:11:22:33:44:55',
       
   689                         boot        = {'next-server': 'boot.lan', 'filename': '/debian/wheezy/pxelinux.0' },
   666                 ),
   690                 ),
   667         ]
   691         ]
   668 
   692 
   669         self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
   693         self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
   670             (('host', 'foo1'), [
   694             (('host', 'foo1'), [
   679                 ('next-server', 'boot.lan'),
   703                 ('next-server', 'boot.lan'),
   680             ], []),
   704             ], []),
   681             (('host', 'foo3'), [
   705             (('host', 'foo3'), [
   682                 ('option', 'host-name', "foo3"),
   706                 ('option', 'host-name', "foo3"),
   683                 ('hardware', 'ethernet', '00:11:22:33:44:55'),
   707                 ('hardware', 'ethernet', '00:11:22:33:44:55'),
   684                 ('filename', 'debian/wheezy/pxelinux.0'),
   708                 ('filename', '/debian/wheezy/pxelinux.0'),
   685             ], []),
   709             ], []),
   686         ])
   710             (('host', 'foo4'), [
   687 
   711                 ('option', 'host-name', "foo4"),
       
   712                 ('hardware', 'ethernet', '00:11:22:33:44:55'),
       
   713                 ('next-server', 'boot.lan'),
       
   714                 ('filename', '/debian/wheezy/pxelinux.0'),
       
   715             ], []),
       
   716         ])
       
   717     
   688     def testHosts(self):
   718     def testHosts(self):
   689         hosts = [
   719         hosts = [
   690                 Host.build('foo', 'test',
   720                 Host.build('foo', 'test',
   691                         ip          = '192.0.2.1',
   721                         ip          = '192.0.2.1',
   692                         ethernet    = '00:11:22:33:44:55',
   722                         ethernet    = '00:11:22:33:44:55',