pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
pe_base_name_eq_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-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 General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
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;
21 
24 
25 static int
26 setup(void **state) {
27  char *path = NULL;
28 
30 
31  path = crm_strdup_printf("%s/crm_mon.xml", getenv("PCMK_CTS_CLI_DIR"));
33  free(path);
34 
35  if (input == NULL) {
36  return 1;
37  }
38 
40 
41  if (scheduler == NULL) {
42  return 1;
43  }
44 
47 
49 
50  /* Get references to several resources we use frequently. */
51  for (GList *iter = scheduler->priv->resources;
52  iter != NULL; iter = iter->next) {
53 
54  pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data;
55 
56  if (strcmp(rsc->id, "dummy") == 0) {
57  dummy = rsc;
58 
59  } else if (strcmp(rsc->id, "exim-group") == 0) {
60  exim_group = rsc;
61 
62  } else if (strcmp(rsc->id, "httpd-bundle") == 0) {
63  httpd_bundle = rsc;
64 
65  } else if (strcmp(rsc->id, "mysql-clone-group") == 0) {
66  for (GList *iter = rsc->priv->children;
67  iter != NULL; iter = iter->next) {
68 
69  pcmk_resource_t *child = (pcmk_resource_t *) iter->data;
70 
71  if (strcmp(child->id, "mysql-group:0") == 0) {
72  mysql_group_0 = child;
73  } else if (strcmp(child->id, "mysql-group:1") == 0) {
74  mysql_group_1 = child;
75  }
76  }
77 
78  } else if (strcmp(rsc->id, "promotable-clone") == 0) {
79  for (GList *iter = rsc->priv->children;
80  iter != NULL; iter = iter->next) {
81 
82  pcmk_resource_t *child = (pcmk_resource_t *) iter->data;
83 
84  if (strcmp(child->id, "promotable-rsc:0") == 0) {
85  promotable_0 = child;
86  } else if (strcmp(child->id, "promotable-rsc:1") == 0) {
87  promotable_1 = child;
88  }
89  }
90  }
91  }
92 
93  return 0;
94 }
95 
96 static int
97 teardown(void **state) {
100  return 0;
101 }
102 
103 static void
104 bad_args(void **state) {
105  char *id = dummy->id;
106 
107  assert_false(pe_base_name_eq(NULL, "dummy"));
108  assert_false(pe_base_name_eq(dummy, NULL));
109 
110  dummy->id = NULL;
111  assert_false(pe_base_name_eq(dummy, "dummy"));
112  dummy->id = id;
113 }
114 
115 static void
116 primitive_rsc(void **state) {
117  assert_true(pe_base_name_eq(dummy, "dummy"));
118  assert_false(pe_base_name_eq(dummy, "DUMMY"));
119  assert_false(pe_base_name_eq(dummy, "dUmMy"));
120  assert_false(pe_base_name_eq(dummy, "dummy0"));
121  assert_false(pe_base_name_eq(dummy, "dummy:0"));
122 }
123 
124 static void
125 group_rsc(void **state) {
126  assert_true(pe_base_name_eq(exim_group, "exim-group"));
127  assert_false(pe_base_name_eq(exim_group, "EXIM-GROUP"));
128  assert_false(pe_base_name_eq(exim_group, "exim-group0"));
129  assert_false(pe_base_name_eq(exim_group, "exim-group:0"));
130  assert_false(pe_base_name_eq(exim_group, "Public-IP"));
131 }
132 
133 static void
134 clone_rsc(void **state) {
135  assert_true(pe_base_name_eq(promotable_0, "promotable-rsc"));
136  assert_true(pe_base_name_eq(promotable_1, "promotable-rsc"));
137 
138  assert_false(pe_base_name_eq(promotable_0, "promotable-rsc:0"));
139  assert_false(pe_base_name_eq(promotable_1, "promotable-rsc:1"));
140  assert_false(pe_base_name_eq(promotable_0, "PROMOTABLE-RSC"));
141  assert_false(pe_base_name_eq(promotable_1, "PROMOTABLE-RSC"));
142  assert_false(pe_base_name_eq(promotable_0, "Promotable-rsc"));
143  assert_false(pe_base_name_eq(promotable_1, "Promotable-rsc"));
144 }
145 
146 static void
147 bundle_rsc(void **state) {
148  assert_true(pe_base_name_eq(httpd_bundle, "httpd-bundle"));
149  assert_false(pe_base_name_eq(httpd_bundle, "HTTPD-BUNDLE"));
150  assert_false(pe_base_name_eq(httpd_bundle, "httpd"));
151  assert_false(pe_base_name_eq(httpd_bundle, "httpd-docker-0"));
152 }
153 
154 PCMK__UNIT_TEST(setup, teardown,
155  cmocka_unit_test(bad_args),
156  cmocka_unit_test(primitive_rsc),
157  cmocka_unit_test(group_rsc),
158  cmocka_unit_test(clone_rsc),
159  cmocka_unit_test(bundle_rsc))
pcmk_resource_t * dummy
pcmk_resource_t * exim_group
pcmk_resource_t * httpd_bundle
void pcmk__xml_init(void)
Definition: xml.c:1430
pcmk__scheduler_private_t * priv
Definition: scheduler.h:99
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
gboolean cluster_status(pcmk_scheduler_t *scheduler)
Definition: status.c:103
Scheduler API.
void pcmk__xml_cleanup(void)
Definition: xml.c:1456
pcmk_resource_t * promotable_0
pcmk__resource_private_t * priv
Definition: resources.h:61
Wrappers for and extensions to libxml2.
pcmk_scheduler_t * scheduler
pcmk_scheduler_t * pe_new_working_set(void)
Create a new object to hold scheduler data.
Definition: status.c:34
uint32_t id
Definition: cpg.c:48
xmlNode * pcmk__xml_read(const char *filename)
Definition: xml_io.c:102
void pe_free_working_set(pcmk_scheduler_t *scheduler)
Free scheduler data.
Definition: status.c:56
pcmk_resource_t * mysql_group_1
Cluster status and scheduling.
const char * path
Definition: cib.c:28
xmlNode * input
Definition: scheduler.h:81
xmlNode * input
pcmk_resource_t * promotable_1
#define pcmk__set_scheduler_flags(scheduler, flags_to_set)
pcmk_resource_t * mysql_group_0
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1