pacemaker  2.1.3-ea053b43a
Scalable High-Availability cluster resource manager
pe_base_name_eq_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 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 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17 
18 #include <crm/common/xml.h>
19 #include <crm/pengine/internal.h>
20 #include <crm/pengine/status.h>
21 #include <crm/pengine/pe_types.h>
22 
23 xmlNode *input = NULL;
25 
28 
29 static int
30 setup(void **state) {
31  char *path = NULL;
32 
33  crm_xml_init();
34 
35  path = crm_strdup_printf("%s/crm_mon.xml", getenv("PCMK_CTS_CLI_DIR"));
37  free(path);
38 
39  if (input == NULL) {
40  return 1;
41  }
42 
44 
45  if (data_set == NULL) {
46  return 1;
47  }
48 
50  data_set->input = input;
51 
53 
54  /* Get references to several resources we use frequently. */
55  for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) {
56  pe_resource_t *rsc = (pe_resource_t *) iter->data;
57 
58  if (strcmp(rsc->id, "dummy") == 0) {
59  dummy = rsc;
60  } else if (strcmp(rsc->id, "exim-group") == 0) {
61  exim_group = rsc;
62  } else if (strcmp(rsc->id, "httpd-bundle") == 0) {
63  httpd_bundle = rsc;
64  } else if (strcmp(rsc->id, "mysql-clone-group") == 0) {
65  for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
66  pe_resource_t *child = (pe_resource_t *) iter->data;
67 
68  if (strcmp(child->id, "mysql-group:0") == 0) {
69  mysql_group_0 = child;
70  } else if (strcmp(child->id, "mysql-group:1") == 0) {
71  mysql_group_1 = child;
72  }
73  }
74  } else if (strcmp(rsc->id, "promotable-clone") == 0) {
75  for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
76  pe_resource_t *child = (pe_resource_t *) iter->data;
77 
78  if (strcmp(child->id, "promotable-rsc:0") == 0) {
79  promotable_0 = child;
80  } else if (strcmp(child->id, "promotable-rsc:1") == 0) {
81  promotable_1 = child;
82  }
83  }
84  }
85  }
86 
87  return 0;
88 }
89 
90 static int
91 teardown(void **state) {
93 
94  return 0;
95 }
96 
97 static void
98 bad_args(void **state) {
99  char *id = dummy->id;
100 
101  assert_false(pe_base_name_eq(NULL, "dummy"));
102  assert_false(pe_base_name_eq(dummy, NULL));
103 
104  dummy->id = NULL;
105  assert_false(pe_base_name_eq(dummy, "dummy"));
106  dummy->id = id;
107 }
108 
109 static void
110 primitive_rsc(void **state) {
111  assert_true(pe_base_name_eq(dummy, "dummy"));
112  assert_false(pe_base_name_eq(dummy, "DUMMY"));
113  assert_false(pe_base_name_eq(dummy, "dUmMy"));
114  assert_false(pe_base_name_eq(dummy, "dummy0"));
115  assert_false(pe_base_name_eq(dummy, "dummy:0"));
116 }
117 
118 static void
119 group_rsc(void **state) {
120  assert_true(pe_base_name_eq(exim_group, "exim-group"));
121  assert_false(pe_base_name_eq(exim_group, "EXIM-GROUP"));
122  assert_false(pe_base_name_eq(exim_group, "exim-group0"));
123  assert_false(pe_base_name_eq(exim_group, "exim-group:0"));
124  assert_false(pe_base_name_eq(exim_group, "Public-IP"));
125 }
126 
127 static void
128 clone_rsc(void **state) {
129  assert_true(pe_base_name_eq(promotable_0, "promotable-rsc"));
130  assert_true(pe_base_name_eq(promotable_1, "promotable-rsc"));
131 
132  assert_false(pe_base_name_eq(promotable_0, "promotable-rsc:0"));
133  assert_false(pe_base_name_eq(promotable_1, "promotable-rsc:1"));
134  assert_false(pe_base_name_eq(promotable_0, "PROMOTABLE-RSC"));
135  assert_false(pe_base_name_eq(promotable_1, "PROMOTABLE-RSC"));
136  assert_false(pe_base_name_eq(promotable_0, "Promotable-rsc"));
137  assert_false(pe_base_name_eq(promotable_1, "Promotable-rsc"));
138 }
139 
140 static void
141 bundle_rsc(void **state) {
142  assert_true(pe_base_name_eq(httpd_bundle, "httpd-bundle"));
143  assert_false(pe_base_name_eq(httpd_bundle, "HTTPD-BUNDLE"));
144  assert_false(pe_base_name_eq(httpd_bundle, "httpd"));
145  assert_false(pe_base_name_eq(httpd_bundle, "httpd-docker-0"));
146 }
147 
148 int main(int argc, char **argv) {
149  const struct CMUnitTest tests[] = {
150  cmocka_unit_test(bad_args),
151  cmocka_unit_test(primitive_rsc),
152  cmocka_unit_test(group_rsc),
153  cmocka_unit_test(clone_rsc),
154  cmocka_unit_test(bundle_rsc),
155  };
156 
157  cmocka_set_message_output(CM_OUTPUT_TAP);
158  return cmocka_run_group_tests(tests, setup, teardown);
159 }
void pe_free_working_set(pe_working_set_t *data_set)
Free a working set.
Definition: status.c:50
GList * children
Definition: pe_types.h:391
pe_resource_t * promotable_1
pe_working_set_t * pe_new_working_set(void)
Create a new working set.
Definition: status.c:34
#define pe_flag_no_compat
Definition: pe_types.h:132
void crm_xml_init(void)
Initialize the CRM XML subsystem.
Definition: xml.c:2835
#define pe_flag_no_counts
Don&#39;t count total, disabled and blocked resource instances.
Definition: pe_types.h:127
xmlNode * filename2xml(const char *filename)
Definition: xml.c:1045
GList * resources
Definition: pe_types.h:165
int main(int argc, char **argv)
pe_working_set_t * data_set
pe_resource_t * promotable_0
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
Wrappers for and extensions to libxml2.
xmlNode * input
Definition: pe_types.h:144
uint32_t id
Definition: cpg.c:45
Cluster status and scheduling.
pe_resource_t * mysql_group_0
const char * path
Definition: cib.c:26
gboolean cluster_status(pe_working_set_t *data_set)
Definition: status.c:71
pe_resource_t * dummy
xmlNode * input
#define pe__set_working_set_flags(working_set, flags_to_set)
Definition: internal.h:37
pe_resource_t * httpd_bundle
pe_resource_t * exim_group
Data types for cluster status.
pe_resource_t * mysql_group_1
char * id
Definition: pe_types.h:336