diff --git a/include/crm/common/scheduler.h b/include/crm/common/scheduler.h index 4400047776..a2ffb27a68 100644 --- a/include/crm/common/scheduler.h +++ b/include/crm/common/scheduler.h @@ -1,257 +1,259 @@ /* * Copyright 2004-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #ifndef PCMK__CRM_COMMON_SCHEDULER__H # define PCMK__CRM_COMMON_SCHEDULER__H #include // time_t #include // xmlNode #include // guint, GList, GHashTable #include // crm_time_t #include #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif /*! * \file * \brief Scheduler API * \ingroup core */ //! Possible responses to loss of quorum enum pe_quorum_policy { pcmk_no_quorum_freeze, // pcmk_tag_t *) int blocked_resources; //!< Number of blocked resources in cluster int disabled_resources; //!< Number of disabled resources in cluster GList *param_check; //!< History entries that need to be checked GList *stop_needed; //!< Containers that need stop actions time_t recheck_by; //!< Hint to controller when to reschedule int ninstances; //!< Total number of resource instances guint shutdown_lock; //!< How long to lock resources (seconds) int priority_fencing_delay; //!< Priority fencing delay // pcmk__output_t * void *priv; //!< For Pacemaker use only guint node_pending_timeout; //!< Pending join times out after this (ms) }; /* Whether the scheduler input currently being processed has warnings or errors * * @COMPAT When we can break API compatibility, we should make these * internal-only. Ideally they would be converted to pcmk_scheduler_flags * values, but everywhere they're needed doesn't currently have access to the * scheduler data. */ //!@{ //! \deprecated Do not use extern gboolean was_processing_error; extern gboolean was_processing_warning; //!@} pcmk_node_t *pcmk_get_dc(const pcmk_scheduler_t *scheduler); +enum pe_quorum_policy pcmk_get_no_quorum_policy(const pcmk_scheduler_t + *scheduler); int pcmk_set_scheduler_cib(pcmk_scheduler_t *scheduler, xmlNode *cib); #ifdef __cplusplus } #endif #endif // PCMK__CRM_COMMON_SCHEDULER__H diff --git a/lib/common/scheduler.c b/lib/common/scheduler.c index 38dfc4040d..61002221f1 100644 --- a/lib/common/scheduler.c +++ b/lib/common/scheduler.c @@ -1,57 +1,74 @@ /* * Copyright 2004-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include // uint32_t #include // EINVAL #include // gboolean, FALSE #include // xmlNode #include uint32_t pcmk__warnings = 0; gboolean was_processing_error = FALSE; gboolean was_processing_warning = FALSE; /*! * \internal * \brief Get the Designated Controller node from scheduler data * * \param[in] scheduler Scheduler data * * \return Designated Controller node from scheduler data, or NULL if none */ pcmk_node_t * pcmk_get_dc(const pcmk_scheduler_t *scheduler) { return (scheduler == NULL)? NULL : scheduler->dc_node; } +/*! + * \internal + * \brief Get the no quorum policy from scheduler data + * + * \param[in] scheduler Scheduler data + * + * \return No quorum policy from scheduler data + */ +enum pe_quorum_policy +pcmk_get_no_quorum_policy(const pcmk_scheduler_t *scheduler) +{ + if (scheduler == NULL) { + return pcmk_no_quorum_stop; // The default + } + return scheduler->no_quorum_policy; +} + /*! * \internal * \brief Set CIB XML as scheduler input in scheduler data * * \param[out] scheduler Scheduler data * \param[in] cib CIB XML to set as scheduler input * * \return Standard Pacemaker return code (EINVAL if \p scheduler is NULL, * otherwise pcmk_rc_ok) * \note This will not free any previously set scheduler CIB. */ int pcmk_set_scheduler_cib(pcmk_scheduler_t *scheduler, xmlNode *cib) { if (scheduler == NULL) { return EINVAL; } scheduler->input = cib; return pcmk_rc_ok; } diff --git a/lib/common/tests/scheduler/Makefile.am b/lib/common/tests/scheduler/Makefile.am index afa1e4e929..33c2bf2e72 100644 --- a/lib/common/tests/scheduler/Makefile.am +++ b/lib/common/tests/scheduler/Makefile.am @@ -1,17 +1,18 @@ # # Copyright 2024 the Pacemaker project contributors # # The version control history for this file may have further details. # # This source code is licensed under the GNU General Public License version 2 # or later (GPLv2+) WITHOUT ANY WARRANTY. # include $(top_srcdir)/mk/tap.mk include $(top_srcdir)/mk/unittest.mk # Add "_test" to the end of all test program names to simplify .gitignore. check_PROGRAMS = pcmk_get_dc_test \ + pcmk_get_no_quorum_policy_test \ pcmk_set_scheduler_cib_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/scheduler/pcmk_get_no_quorum_policy_test.c b/lib/common/tests/scheduler/pcmk_get_no_quorum_policy_test.c new file mode 100644 index 0000000000..61c97e6a03 --- /dev/null +++ b/lib/common/tests/scheduler/pcmk_get_no_quorum_policy_test.c @@ -0,0 +1,34 @@ +/* + * Copyright 2024 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. + */ + +#include + +#include +#include + +static void +null_scheduler(void **state) +{ + assert_int_equal(pcmk_get_no_quorum_policy(NULL), pcmk_no_quorum_stop); +} + +static void +valid_no_quorum_policy(void **state) +{ + pcmk_scheduler_t scheduler = { + .no_quorum_policy = pcmk_no_quorum_fence, + }; + + assert_int_equal(pcmk_get_no_quorum_policy(&scheduler), + pcmk_no_quorum_fence); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(null_scheduler), + cmocka_unit_test(valid_no_quorum_policy))