622 }) |
622 }) |
623 |
623 |
624 class TestDhcp(unittest.TestCase): |
624 class TestDhcp(unittest.TestCase): |
625 def assertBlockEqual(self, block, (key, items, blocks)): |
625 def assertBlockEqual(self, block, (key, items, blocks)): |
626 self.assertEqual(block.key, key) |
626 self.assertEqual(block.key, key) |
627 self.assertItemsEqual(block.items, items) |
627 |
|
628 for _item, item in itertools.izip_longest(sorted(block.items), sorted(items)): |
|
629 self.assertIsNotNone(_item, item) |
|
630 self.assertIsNotNone(item, _item) |
|
631 |
|
632 self.assertEqual(tuple(pvl.dhcp.config.quote(field) for field in _item), item) |
628 |
633 |
629 for _block, expect_block in itertools.izip_longest(block.blocks, blocks): |
634 for _block, expect_block in itertools.izip_longest(block.blocks, blocks): |
630 self.assertBlockEqual(_block, expect_block) |
635 self.assertBlockEqual(_block, expect_block) |
631 |
636 |
632 def assertBlocksEqual(self, blocks, expected): |
637 def assertBlocksEqual(self, blocks, expected): |
657 ethernet = '00:11:22:33:44:55', |
662 ethernet = '00:11:22:33:44:55', |
658 ) |
663 ) |
659 |
664 |
660 self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [ |
665 self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [ |
661 (('host', 'foo.test'), [ |
666 (('host', 'foo.test'), [ |
662 ('option', 'host-name', "foo.test"), |
667 ('option', 'host-name', '"foo.test"'), |
663 ('fixed-address', '192.0.2.1'), |
668 ('fixed-address', '192.0.2.1'), |
664 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
669 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
665 ], []) |
670 ], []) |
666 ]) |
671 ]) |
667 |
672 |
708 |
713 |
709 self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [ |
714 self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [ |
710 (('host', 'foo1'), [ |
715 (('host', 'foo1'), [ |
711 ('option', 'host-name', "foo1"), |
716 ('option', 'host-name', "foo1"), |
712 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
717 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
713 ('next-server', 'boot.lan'), |
718 ('next-server', '"boot.lan"'), |
714 ('filename', 'debian/wheezy/pxelinux.0'), |
719 ('filename', '"debian/wheezy/pxelinux.0"'), |
715 ], []), |
720 ], []), |
716 (('host', 'foo2'), [ |
721 (('host', 'foo2'), [ |
717 ('option', 'host-name', "foo2"), |
722 ('option', 'host-name', "foo2"), |
718 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
723 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
719 ('next-server', 'boot.lan'), |
724 ('next-server', '"boot.lan"'), |
720 ], []), |
725 ], []), |
721 (('host', 'foo3'), [ |
726 (('host', 'foo3'), [ |
722 ('option', 'host-name', "foo3"), |
727 ('option', 'host-name', "foo3"), |
723 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
728 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
724 ('filename', '/debian/wheezy/pxelinux.0'), |
729 ('filename', '"/debian/wheezy/pxelinux.0"'), |
725 ], []), |
730 ], []), |
726 (('host', 'foo4'), [ |
731 (('host', 'foo4'), [ |
727 ('option', 'host-name', "foo4"), |
732 ('option', 'host-name', "foo4"), |
728 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
733 ('hardware', 'ethernet', '00:11:22:33:44:55'), |
729 ('next-server', 'boot.lan'), |
734 ('next-server', '"boot.lan"'), |
730 ('filename', '/debian/wheezy/pxelinux.0'), |
735 ('filename', '"/debian/wheezy/pxelinux.0"'), |
731 ], []), |
736 ], []), |
732 ]) |
737 ]) |
733 |
738 |
734 def testHosts(self): |
739 def testHosts(self): |
735 hosts = [ |
740 hosts = [ |