Example #1
0
 def test_read_invalid_data_len(self):
     '''raise assert error if data size is smaller than required size'''
     buf = bytearray(32)
     with self.assertRaises(AssertionError) as context:
         read_rta_oper_state(buf)
     self.assertTrue('length of data is smaller than RTATTR_START_OFFSET' in
                     str(context.exception))
Example #2
0
 def test_read_invalid_data_len(self):
     """raise assert error if data size is smaller than required size"""
     buf = bytearray(32)
     with self.assertRaises(AssertionError) as context:
         read_rta_oper_state(buf)
     self.assertTrue("length of data is smaller than RTATTR_START_OFFSET" in
                     str(context.exception))
Example #3
0
 def test_read_invalid_rta_ifname_none(self):
     """read_rta_oper_state returns none if ifname is none"""
     buf = bytearray(40)
     struct.pack_into("HHc", buf, RTATTR_START_OFFSET, 5, 16,
                      int_to_bytes(OPER_DOWN))
     interface_state = read_rta_oper_state(buf)
     self.assertIsNone(interface_state)
Example #4
0
 def test_read_invalid_rta_ifname_none(self):
     '''read_rta_oper_state returns none if ifname is none'''
     buf = bytearray(40)
     struct.pack_into("HHc", buf, RTATTR_START_OFFSET, 5, 16,
                      int_to_bytes(OPER_DOWN))
     interface_state = read_rta_oper_state(buf)
     self.assertIsNone(interface_state)
Example #5
0
 def test_read_invalid_rta_operstate_none(self):
     """read_rta_oper_state returns none if operstate is none"""
     ifname = "eth0"
     buf = bytearray(40)
     bytes = ifname.encode("utf-8")
     struct.pack_into("HH4s", buf, RTATTR_START_OFFSET, 8, 3, bytes)
     interface_state = read_rta_oper_state(buf)
     self.assertIsNone(interface_state)
Example #6
0
 def test_read_invalid_rta_operstate_none(self):
     '''read_rta_oper_state returns none if operstate is none'''
     ifname = "eth0"
     buf = bytearray(40)
     bytes = ifname.encode("utf-8")
     struct.pack_into("HH4s", buf, RTATTR_START_OFFSET, 8, 3, bytes)
     interface_state = read_rta_oper_state(buf)
     self.assertIsNone(interface_state)
Example #7
0
 def test_read_rta_oper_state(self):
     '''read_rta_oper_state could parse netlink message and extract data'''
     ifname = "eth0"
     bytes = ifname.encode("utf-8")
     buf = bytearray(48)
     struct.pack_into("HH4sHHc", buf, RTATTR_START_OFFSET, 8, 3, bytes, 5,
                      16, int_to_bytes(OPER_DOWN))
     interface_state = read_rta_oper_state(buf)
     self.assertEqual(interface_state.ifname, ifname)
     self.assertEqual(interface_state.operstate, OPER_DOWN)
Example #8
0
 def test_read_rta_oper_state(self):
     '''read_rta_oper_state could parse netlink message and extract data'''
     ifname = "eth0"
     bytes = ifname.encode("utf-8")
     buf = bytearray(48)
     struct.pack_into("HH4sHHc", buf, RTATTR_START_OFFSET, 8, 3, bytes, 5,
                      16, int_to_bytes(OPER_DOWN))
     interface_state = read_rta_oper_state(buf)
     self.assertEqual(interface_state.ifname, ifname)
     self.assertEqual(interface_state.operstate, OPER_DOWN)
Example #9
0
 def test_read_none_data(self):
     """read_rta_oper_state raises assert error if data is none"""
     data = None
     with self.assertRaises(AssertionError) as context:
         read_rta_oper_state(data)
     self.assertEqual("data is none", str(context.exception))
Example #10
0
 def test_read_none_data(self):
     '''read_rta_oper_state raises assert error if data is none'''
     data = None
     with self.assertRaises(AssertionError) as context:
         read_rta_oper_state(data)
     self.assertTrue('data is none', str(context.exception))
Example #11
0
 def test_read_none_data(self):
     '''read_rta_oper_state raises assert error if data is none'''
     data = None
     with self.assertRaises(AssertionError) as context:
         read_rta_oper_state(data)
     self.assertTrue('data is none', str(context.exception))