Beispiel #1
0
 def test_badarg_count(self):
     # 1 or 2 args
     with self.assertRaises(TypeError) as cm:
         kea.Pkt4()
     self.assertEqual(('function takes exactly 2 arguments (0 given)', ),
                      cm.exception.args)
     with self.assertRaises(TypeError) as cm:
         kea.Pkt4(1, 2, 3)
     self.assertEqual(('function takes exactly 2 arguments (3 given)', ),
                      cm.exception.args)
     with self.assertRaises(TypeError) as cm:
         kea.Pkt4(x=1)
     self.assertEqual(('keyword arguments are not supported', ),
                      cm.exception.args)
Beispiel #2
0
 def test_badarg_type(self):
     # 1 arg - bytes
     with self.assertRaises(TypeError) as cm:
         kea.Pkt4(42)
     self.assertEqual(("argument 1 must be bytes, not int", ),
                      cm.exception.args)
     # 2 args - type, trans_id
     with self.assertRaises(TypeError) as cm:
         kea.Pkt4('1', 42)
     self.assertEqual(("an integer is required (got type str)", ),
                      cm.exception.args)
     with self.assertRaises(TypeError) as cm:
         kea.Pkt4(1, '42')
     self.assertEqual(("argument 2 must be int, not str", ),
                      cm.exception.args)
Beispiel #3
0
 def test_empty(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertEqual(
         textwrap.dedent("""\
         local_address=0.0.0.0:67, remote_address=0.0.0.0:68, msg_type=DHCPREQUEST (3), transid=0x2a,
         options:
           type=053, len=001: 3 (uint8)"""), p.toText())  # noqa: E501
Beispiel #4
0
 def test_filled(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)  # 53
     p.setLocalAddr('1.2.3.4')
     p.setRemoteAddr('2.3.4.5')
     subnet = IPv4Network('10.0.0.0/20')
     p.addOption(
         kea.Option(kea.DHO_SUBNET_MASK).setBytes(
             subnet.netmask.packed))  # 1
     p.addOption(kea.Option(kea.DHO_ROUTERS).setBytes(
         subnet[1].packed))  # 3
     p.addOption(kea.Option(
         kea.DHO_DOMAIN_NAME).setString('test.org'))  # 15
     p.addOption(kea.Option(kea.DHO_DHCP_LEASE_TIME).setUint32(7200))  # 51
     p.addOption(kea.Option(
         kea.DHO_DHCP_RENEWAL_TIME).setUint32(1800))  # 58
     p.addOption(kea.Option(
         kea.DHO_DHCP_REBINDING_TIME).setUint32(3600))  # 59
     self.assertEqual(
         textwrap.dedent("""\
         local_address=1.2.3.4:67, remote_address=2.3.4.5:68, msg_type=DHCPREQUEST (3), transid=0x2a,
         options:
           type=001, len=004: ff:ff:f0:00
           type=003, len=004: 0a:00:00:01
           type=015, len=008: 74:65:73:74:2e:6f:72:67
           type=051, len=004: 00:00:1c:20
           type=053, len=001: 3 (uint8)
           type=058, len=004: 00:00:07:08
           type=059, len=004: 00:00:0e:10"""), p.toText())  # noqa: E501
Beispiel #5
0
 def test_response4_ok(self):
     h = kea.CalloutHandle(kea.CalloutManager())
     x = kea.Pkt4(kea.DHCPACK, 42)
     self.assertEqual(1, x.use_count)
     self.assertIsNone(h.setArgument('response4', x))
     self.assertEqual(2, x.use_count)
     self.assertEqual(kea.DHCPACK, h.getArgument('response4').getType())
Beispiel #6
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     o = kea.Option(kea.DHO_DHCP_AGENT_OPTIONS)
     self.assertEqual(1, o.use_count)
     self.assertIs(p, p.addOption(o))
     self.assertEqual(2, o.use_count)
     n = p.getOption(kea.DHO_DHCP_AGENT_OPTIONS)
     self.assertEqual(kea.DHO_DHCP_AGENT_OPTIONS, n.getType())
Beispiel #7
0
 def test_badarg_type(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     with self.assertRaises(TypeError) as cm:
         p.setHWAddr(1)
     self.assertEqual(("argument 1 must be str, not int", ),
                      cm.exception.args)
     with self.assertRaises(TypeError) as cm:
         p.setHWAddr('foo')
     self.assertEqual(("invalid format of the decoded string 'foo'", ),
                      cm.exception.args)
Beispiel #8
0
 def test_badarg_type(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     with self.assertRaises(TypeError) as cm:
         p.setYiaddr(1)
     self.assertEqual(("argument 1 must be str, not int", ),
                      cm.exception.args)
     with self.assertRaises(TypeError) as cm:
         p.setYiaddr('foo')
     self.assertEqual(
         ("Failed to convert string to address 'foo': Invalid argument", ),
         cm.exception.args)
Beispiel #9
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertEqual(0, p.getFlags())
Beispiel #10
0
 def test_badarg_count(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assert_method_no_arguments(p.getFlags)
Beispiel #11
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     p.setType(kea.DHCPNAK)
     self.assertEqual(kea.DHCPNAK, p.getType())
Beispiel #12
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertEqual('0.0.0.0', p.getYiaddr())
Beispiel #13
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     wire = p.pack()
     p = kea.Pkt4(wire)
     self.assertIsNone(p.unpack())
Beispiel #14
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertIs(p, p.setHWAddr('01:02:03:04:05:06'))
     self.assertEqual('01:02:03:04:05:06', p.getHWAddr())
Beispiel #15
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertEqual(1, p.use_count)
Beispiel #16
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertIs(p, p.setYiaddr('1.2.3.4'))
     self.assertEqual('1.2.3.4', p.getYiaddr())
Beispiel #17
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertEqual('', p.getHWAddr())
Beispiel #18
0
 def test_bytes_option_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     o = kea.Option(25)
     self.assertIs(p, p.addOption(o))
     self.assertEqual(2, o.use_count)
Beispiel #19
0
 def test_badarg_type(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     with self.assertRaises(TypeError) as cm:
         p.addOption('foo')
     self.assertEqual(("argument 1 must be kea.Option, not str", ),
                      cm.exception.args)
Beispiel #20
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assertFalse(p.delOption(42))
Beispiel #21
0
 def test_badarg_count(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     self.assert_method_one_arg_no_keywords(p.setFlags)
Beispiel #22
0
 def test_badarg_type(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     with self.assertRaises(TypeError) as cm:
         p.setFlags('foo')
     self.assertEqual(("an integer is required (got type str)", ),
                      cm.exception.args)
Beispiel #23
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     wire = p.pack()
     self.assertIsInstance(wire, bytes)
Beispiel #24
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     p.setFlags(0xbeef)
     self.assertEqual(0xbeef, p.getFlags())
Beispiel #25
0
 def test_ok(self):
     p = kea.Pkt4(kea.DHCPREQUEST, 42)
     o = p.getOption(kea.DHO_DHCP_MESSAGE_TYPE)
     self.assertIsInstance(o, kea.Option)
     self.assertEqual(bytes([kea.DHCPREQUEST]), o.getBytes())