pvl/hosts/tests.py
changeset 483 19d084bb4afd
parent 480 7e44854e85d4
child 487 920394061b6f
equal deleted inserted replaced
482:41622bb9b95c 483:19d084bb4afd
   493                 ('next-server', 'boot.lan'),
   493                 ('next-server', 'boot.lan'),
   494                 ('filename', 'debian/wheezy/pxelinux.0'),
   494                 ('filename', 'debian/wheezy/pxelinux.0'),
   495             ], None)
   495             ], None)
   496         ])
   496         ])
   497 
   497 
       
   498     def testHosts(self):
       
   499         hosts = [
       
   500                 Host.build('foo', 'test',
       
   501                         ip          = '192.0.2.1',
       
   502                         ethernet    = '00:11:22:33:44:55',
       
   503                 ),
       
   504                 Host.build('bar', 'test',
       
   505                         ip          = '192.0.2.2',
       
   506                         ethernet    = '01:23:45:67:89:ab',
       
   507                 ),
       
   508         ]
       
   509 
       
   510         self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
       
   511             (('host', 'foo'), [
       
   512                 ('option', 'host-name', "foo"),
       
   513                 ('fixed-address', '192.0.2.1'),
       
   514                 ('hardware', 'ethernet', '00:11:22:33:44:55'),
       
   515             ], None),
       
   516             (('host', 'bar'), [
       
   517                 ('option', 'host-name', "bar"),
       
   518                 ('fixed-address', '192.0.2.2'),
       
   519                 ('hardware', 'ethernet', '01:23:45:67:89:ab'),
       
   520             ], None),
       
   521         ])
       
   522 
       
   523     def testHostConflict(self):
       
   524         hosts = [
       
   525                 Host.build('foo', 'test1',
       
   526                         ethernet    = '00:11:22:33:44:55',
       
   527                 ),
       
   528                 Host.build('foo', 'test2',
       
   529                         ethernet    = '01:23:45:67:89:ab',
       
   530                 ),
       
   531         ]
       
   532         
       
   533         with self.assertRaises(dhcp.HostDHCPError):
       
   534             list(dhcp.dhcp_hosts(hosts))
       
   535 
       
   536     def testHostMultinet(self):
       
   537         hosts = [
       
   538                 Host.build('foo', 'test1',
       
   539                     ip              = '192.0.1.1',
       
   540                     ethernet        = { 'eth1': '00:11:22:33:44:55' },
       
   541                 ),
       
   542                 Host.build('foo', 'test2',
       
   543                     ip              = '192.0.2.1',
       
   544                     ethernet        = { 'eth2': '01:23:45:67:89:ab' },
       
   545                 ),
       
   546         ]
       
   547         
       
   548         self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
       
   549                 (('host', 'foo-eth1'), [
       
   550                     ('option', 'host-name', "foo"),
       
   551                     ('fixed-address', '192.0.1.1'),
       
   552                     ('hardware', 'ethernet', '00:11:22:33:44:55'),
       
   553                 ], None),
       
   554                 (('host', 'foo-eth2'), [
       
   555                     ('option', 'host-name', "foo"),
       
   556                     ('fixed-address', '192.0.2.1'),
       
   557                     ('hardware', 'ethernet', '01:23:45:67:89:ab'),
       
   558                 ], None),
       
   559         ])
       
   560 
       
   561 
   498 if __name__ == '__main__':
   562 if __name__ == '__main__':
   499     unittest.main()
   563     unittest.main()