LCOV - code coverage report
Current view: top level - common - health.c (source / functions) Hit Total Coverage
Test: Pacemaker code coverage Lines: 15 15 100.0 %
Date: 2024-05-07 11:09:47 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright 2024 the Pacemaker project contributors
       3             :  *
       4             :  * The version control history for this file may have further details.
       5             :  *
       6             :  * This source code is licensed under the GNU Lesser General Public License
       7             :  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
       8             :  */
       9             : 
      10             : #include <crm_internal.h>
      11             : 
      12             : /*!
      13             :  * \internal
      14             :  * \brief Ensure a health strategy value is allowed
      15             :  *
      16             :  * \param[in] value  Configured health strategy
      17             :  *
      18             :  * \return true if \p value is an allowed health strategy value, otherwise false
      19             :  */
      20             : bool
      21          84 : pcmk__validate_health_strategy(const char *value)
      22             : {
      23          84 :     return pcmk__strcase_any_of(value,
      24             :                                 PCMK_VALUE_NONE,
      25             :                                 PCMK_VALUE_CUSTOM,
      26             :                                 PCMK_VALUE_ONLY_GREEN,
      27             :                                 PCMK_VALUE_PROGRESSIVE,
      28             :                                 PCMK_VALUE_MIGRATE_ON_RED,
      29             :                                 NULL);
      30             : }
      31             : 
      32             : /*!
      33             :  * \internal
      34             :  * \brief Parse node health strategy from a user-provided string
      35             :  *
      36             :  * \param[in] value  User-provided configuration value for node-health-strategy
      37             :  *
      38             :  * \return Node health strategy corresponding to \p value
      39             :  */
      40             : enum pcmk__health_strategy
      41          48 : pcmk__parse_health_strategy(const char *value)
      42             : {
      43          48 :     if (pcmk__str_eq(value, PCMK_VALUE_NONE,
      44             :                      pcmk__str_null_matches|pcmk__str_casei)) {
      45          41 :         return pcmk__health_strategy_none;
      46             :     }
      47           7 :     if (pcmk__str_eq(value, PCMK_VALUE_MIGRATE_ON_RED, pcmk__str_casei)) {
      48           1 :         return pcmk__health_strategy_no_red;
      49             :     }
      50           6 :     if (pcmk__str_eq(value, PCMK_VALUE_ONLY_GREEN, pcmk__str_casei)) {
      51           1 :         return pcmk__health_strategy_only_green;
      52             :     }
      53           5 :     if (pcmk__str_eq(value, PCMK_VALUE_PROGRESSIVE, pcmk__str_casei)) {
      54           1 :         return pcmk__health_strategy_progressive;
      55             :     }
      56           4 :     if (pcmk__str_eq(value, PCMK_VALUE_CUSTOM, pcmk__str_casei)) {
      57           1 :         return pcmk__health_strategy_custom;
      58             :     } else {
      59           3 :         pcmk__config_err("Using default of \"" PCMK_VALUE_NONE "\" for "
      60             :                          PCMK_OPT_NODE_HEALTH_STRATEGY
      61             :                          " because '%s' is not a valid value",
      62             :                          value);
      63           3 :         return pcmk__health_strategy_none;
      64             :     }
      65             : }

Generated by: LCOV version 1.14