root/lib/pengine/tests/native/pe_base_name_eq_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. bad_args
  4. primitive_rsc
  5. group_rsc
  6. clone_rsc
  7. bundle_rsc

   1 /*
   2  * Copyright 2022-2023 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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/common/unittest_internal.h>
  13 
  14 #include <crm/common/xml.h>
  15 #include <crm/common/scheduler.h>
  16 #include <crm/pengine/internal.h>
  17 #include <crm/pengine/status.h>
  18 
  19 xmlNode *input = NULL;
  20 pcmk_scheduler_t *scheduler = NULL;
  21 
  22 pcmk_resource_t *exim_group, *promotable_0, *promotable_1, *dummy;
  23 pcmk_resource_t *httpd_bundle, *mysql_group_0, *mysql_group_1;
  24 
  25 static int
  26 setup(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  27     char *path = NULL;
  28 
  29     crm_xml_init();
  30 
  31     path = crm_strdup_printf("%s/crm_mon.xml", getenv("PCMK_CTS_CLI_DIR"));
  32     input = filename2xml(path);
  33     free(path);
  34 
  35     if (input == NULL) {
  36         return 1;
  37     }
  38 
  39     scheduler = pe_new_working_set();
  40 
  41     if (scheduler == NULL) {
  42         return 1;
  43     }
  44 
  45     pe__set_working_set_flags(scheduler,
  46                               pcmk_sched_no_counts|pcmk_sched_no_compat);
  47     scheduler->input = input;
  48 
  49     cluster_status(scheduler);
  50 
  51     /* Get references to several resources we use frequently. */
  52     for (GList *iter = scheduler->resources; iter != NULL; iter = iter->next) {
  53         pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data;
  54 
  55         if (strcmp(rsc->id, "dummy") == 0) {
  56             dummy = rsc;
  57         } else if (strcmp(rsc->id, "exim-group") == 0) {
  58             exim_group = rsc;
  59         } else if (strcmp(rsc->id, "httpd-bundle") == 0) {
  60             httpd_bundle = rsc;
  61         } else if (strcmp(rsc->id, "mysql-clone-group") == 0) {
  62             for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
  63                 pcmk_resource_t *child = (pcmk_resource_t *) iter->data;
  64 
  65                 if (strcmp(child->id, "mysql-group:0") == 0) {
  66                     mysql_group_0 = child;
  67                 } else if (strcmp(child->id, "mysql-group:1") == 0) {
  68                     mysql_group_1 = child;
  69                 }
  70             }
  71         } else if (strcmp(rsc->id, "promotable-clone") == 0) {
  72             for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
  73                 pcmk_resource_t *child = (pcmk_resource_t *) iter->data;
  74 
  75                 if (strcmp(child->id, "promotable-rsc:0") == 0) {
  76                     promotable_0 = child;
  77                 } else if (strcmp(child->id, "promotable-rsc:1") == 0) {
  78                     promotable_1 = child;
  79                 }
  80             }
  81         }
  82     }
  83 
  84     return 0;
  85 }
  86 
  87 static int
  88 teardown(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  89     pe_free_working_set(scheduler);
  90 
  91     return 0;
  92 }
  93 
  94 static void
  95 bad_args(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  96     char *id = dummy->id;
  97 
  98     assert_false(pe_base_name_eq(NULL, "dummy"));
  99     assert_false(pe_base_name_eq(dummy, NULL));
 100 
 101     dummy->id = NULL;
 102     assert_false(pe_base_name_eq(dummy, "dummy"));
 103     dummy->id = id;
 104 }
 105 
 106 static void
 107 primitive_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 108     assert_true(pe_base_name_eq(dummy, "dummy"));
 109     assert_false(pe_base_name_eq(dummy, "DUMMY"));
 110     assert_false(pe_base_name_eq(dummy, "dUmMy"));
 111     assert_false(pe_base_name_eq(dummy, "dummy0"));
 112     assert_false(pe_base_name_eq(dummy, "dummy:0"));
 113 }
 114 
 115 static void
 116 group_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 117     assert_true(pe_base_name_eq(exim_group, "exim-group"));
 118     assert_false(pe_base_name_eq(exim_group, "EXIM-GROUP"));
 119     assert_false(pe_base_name_eq(exim_group, "exim-group0"));
 120     assert_false(pe_base_name_eq(exim_group, "exim-group:0"));
 121     assert_false(pe_base_name_eq(exim_group, "Public-IP"));
 122 }
 123 
 124 static void
 125 clone_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 126     assert_true(pe_base_name_eq(promotable_0, "promotable-rsc"));
 127     assert_true(pe_base_name_eq(promotable_1, "promotable-rsc"));
 128 
 129     assert_false(pe_base_name_eq(promotable_0, "promotable-rsc:0"));
 130     assert_false(pe_base_name_eq(promotable_1, "promotable-rsc:1"));
 131     assert_false(pe_base_name_eq(promotable_0, "PROMOTABLE-RSC"));
 132     assert_false(pe_base_name_eq(promotable_1, "PROMOTABLE-RSC"));
 133     assert_false(pe_base_name_eq(promotable_0, "Promotable-rsc"));
 134     assert_false(pe_base_name_eq(promotable_1, "Promotable-rsc"));
 135 }
 136 
 137 static void
 138 bundle_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 139     assert_true(pe_base_name_eq(httpd_bundle, "httpd-bundle"));
 140     assert_false(pe_base_name_eq(httpd_bundle, "HTTPD-BUNDLE"));
 141     assert_false(pe_base_name_eq(httpd_bundle, "httpd"));
 142     assert_false(pe_base_name_eq(httpd_bundle, "httpd-docker-0"));
 143 }
 144 
 145 PCMK__UNIT_TEST(setup, teardown,
 146                 cmocka_unit_test(bad_args),
 147                 cmocka_unit_test(primitive_rsc),
 148                 cmocka_unit_test(group_rsc),
 149                 cmocka_unit_test(clone_rsc),
 150                 cmocka_unit_test(bundle_rsc))

/* [previous][next][first][last][top][bottom][index][help] */