Exemplo n.º 1
0
    def test_process_event_dropped(self, mock_byref):
        event = self._get_fake_event(cluster_object_name='other_group_name')
        self.assertIsNone(self._listener._process_event(event))

        event = self._get_fake_event(notif_key=2)
        self.assertIsNone(self._listener._process_event(event))

        notif_key = self._listener._NOTIF_KEY_GROUP_COMMON_PROP
        self._clusapi.get_cluster_group_status_info.side_effect = (
            exceptions.ClusterPropertyListEntryNotFound(
                property_name='fake_prop_name'))
        event = self._get_fake_event(notif_key=notif_key)
        self.assertIsNone(self._listener._process_event(event))
Exemplo n.º 2
0
    def get_prop_list_entry_p(self, prop_list_p, prop_list_sz, property_name):
        # We may add a nice property list parser at some point.
        # ResUtilFindULargeIntegerProperty is also helpful for our use case
        # but it's available only starting with WS 2016.
        #
        # NOTE(lpetrut): in most cases, we're using 'byref' when passing
        # references to DLL functions. The issue is that those pointers
        # cannot be used directly, for which reason we have a cast here.
        prop_list_p = ctypes.cast(
            prop_list_p, ctypes.POINTER(ctypes.c_ubyte * prop_list_sz))
        wb_prop_name = bytearray(ctypes.create_unicode_buffer(property_name))

        prop_list_addr = ctypes.addressof(prop_list_p.contents)
        prop_name_pos = bytearray(prop_list_p.contents).find(wb_prop_name)
        if prop_name_pos == -1:
            raise exceptions.ClusterPropertyListEntryNotFound(
                property_name=property_name)

        prop_name_len_pos = prop_name_pos - ctypes.sizeof(wintypes.DWORD)
        prop_name_len_addr = prop_list_addr + prop_name_len_pos
        prop_name_len = self._dword_align(
            wintypes.DWORD.from_address(prop_name_len_addr).value)
        prop_addr = prop_name_len_addr + prop_name_len + ctypes.sizeof(
            wintypes.DWORD)
        if (prop_addr + ctypes.sizeof(wintypes.DWORD * 3) >
                prop_list_addr + prop_list_sz):
            raise exceptions.ClusterPropertyListParsingError()

        prop_entry = {
            'syntax':
            wintypes.DWORD.from_address(prop_addr).value,
            'length':
            wintypes.DWORD.from_address(prop_addr +
                                        ctypes.sizeof(wintypes.DWORD)).value,
            'val_p':
            ctypes.c_void_p(prop_addr + 2 * ctypes.sizeof(wintypes.DWORD))
        }

        return prop_entry