def fake_cluster_group_ctrl(func, group_handle, node_handle, control_code, in_buff_p, in_buff_sz, out_buff_p, out_buff_sz, requested_buff_sz_p): self.assertEqual(self._clusapi.ClusterGroupControl, func) self.assertEqual(mock.sentinel.group_handle, group_handle) self.assertEqual(mock.sentinel.node_handle, node_handle) self.assertEqual(mock.sentinel.control_code, control_code) self.assertEqual(mock.sentinel.in_buff_p, in_buff_p) self.assertEqual(mock.sentinel.in_buff_sz, in_buff_sz) req_buff_sz = ctypes.cast(requested_buff_sz_p, wintypes.PDWORD).contents req_buff_sz.value = requested_buff_sz # We'll just request the tested method to pass us # a buffer this large. if (out_buff_sz.value < requested_buff_sz): raise exceptions.ClusterWin32Exception( error_code=w_const.ERROR_MORE_DATA, func_name='ClusterGroupControl', error_message='error more data') out_buff = ctypes.cast( out_buff_p, ctypes.POINTER( ctypes.c_wchar * (requested_buff_sz // ctypes.sizeof(ctypes.c_wchar)))) out_buff = out_buff.contents out_buff.value = fake_out_buff
def test_open_missing_cluster_group(self): exc = exceptions.ClusterWin32Exception( func_name='OpenClusterGroup', message='expected exception', error_code=w_const.ERROR_GROUP_NOT_FOUND) self._clusapi_utils.open_cluster_group.side_effect = exc self.assertRaises( exceptions.ClusterObjectNotFound, self._cmgr.open_cluster_group(mock.sentinel.group_name).__enter__)
def fake_get_cluster_notify(func, notif_port_h, pp_notif_key, p_filter_and_type, p_buff, p_buff_sz, p_obj_id_buff, p_obj_id_buff_sz, p_parent_id_buff, p_parent_id_buff_sz, p_obj_name_buff, p_obj_name_buff_sz, p_obj_type, p_obj_type_sz, timeout_ms): self.assertEqual(self._clusapi.GetClusterNotifyV2, func) self.assertEqual(fake_notif_port_h, notif_port_h) obj_name_buff_sz = ctypes.cast(p_obj_name_buff_sz, wintypes.PDWORD).contents buff_sz = ctypes.cast(p_buff_sz, wintypes.PDWORD).contents # We'll just request the tested method to pass us # a buffer this large. if (buff_sz.value < requested_buff_sz or obj_name_buff_sz.value < requested_buff_sz): buff_sz.value = requested_buff_sz obj_name_buff_sz.value = requested_buff_sz raise exceptions.ClusterWin32Exception( error_code=w_const.ERROR_MORE_DATA, func_name='GetClusterNotify', error_message='error more data') pp_notif_key = ctypes.cast(pp_notif_key, ctypes.c_void_p) p_notif_key = ctypes.c_void_p.from_address(pp_notif_key.value) p_notif_key.value = ctypes.addressof(notif_key) filter_and_type = ctypes.cast( p_filter_and_type, ctypes.POINTER(clusapi_def.NOTIFY_FILTER_AND_TYPE)).contents filter_and_type.dwObjectType = fake_notif_type filter_and_type.FilterFlags = fake_filter_flags obj_name_buff = ctypes.cast( p_obj_name_buff, ctypes.POINTER( ctypes.c_wchar * (requested_buff_sz // ctypes.sizeof(ctypes.c_wchar)))) obj_name_buff = obj_name_buff.contents ctypes.memset(obj_name_buff, 0, obj_name_buff_sz.value) obj_name_buff.value = fake_clus_obj_name buff = ctypes.cast( p_buff, ctypes.POINTER( ctypes.c_wchar * (requested_buff_sz // ctypes.sizeof(ctypes.c_wchar)))) buff = buff.contents ctypes.memset(buff, 0, buff_sz.value) buff.value = fake_event_buff self.assertEqual(mock.sentinel.timeout_ms, timeout_ms)
def fake_cluster_enum(func, enum_handle, index, buff_p, buff_sz_p, ignored_error_codes=tuple()): self.assertEqual(self._clusapi.ClusterEnumEx, func) self.assertEqual(mock.sentinel.enum_handle, enum_handle) self.assertEqual(mock.sentinel.index, index) buff_sz = ctypes.cast( buff_sz_p, wintypes.PDWORD).contents # We'll just request the tested method to pass us # a buffer this large. if (buff_sz.value < requested_buff_sz): buff_sz.value = requested_buff_sz if w_const.ERROR_MORE_DATA not in ignored_error_codes: raise exceptions.ClusterWin32Exception( error_code=w_const.ERROR_MORE_DATA) return item = ctypes.cast( buff_p, clusapi_def.PCLUSTER_ENUM_ITEM).contents item.lpszId = obj_id_wchar_p item.cbId = len(obj_id)