pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pe_base_name_eq_test.c
Go to the documentation of this file.
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 
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 
29  crm_xml_init();
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 
48 
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) {
90 
91  return 0;
92 }
93 
94 static void
95 bad_args(void **state) {
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) {
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) {
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) {
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) {
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))
pcmk_resource_t * dummy
pcmk_resource_t * exim_group
pcmk_resource_t * httpd_bundle
GList * children
Resource&#39;s child resources, if any.
Definition: resources.h:475
void crm_xml_init(void)
Initialize the CRM XML subsystem.
Definition: xml.c:2524
#define pe__set_working_set_flags(scheduler, flags_to_set)
Definition: internal.h:52
xmlNode * filename2xml(const char *filename)
Definition: xml.c:990
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
Implementation of pcmk_scheduler_t.
Definition: scheduler.h:172
gboolean cluster_status(pcmk_scheduler_t *scheduler)
Definition: status.c:71
GList * resources
Resources in cluster.
Definition: scheduler.h:196
Scheduler API.
Implementation of pcmk_resource_t.
Definition: resources.h:399
pcmk_resource_t * promotable_0
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
Wrappers for and extensions to libxml2.
pcmk_scheduler_t * scheduler
xmlNode * input
CIB XML.
Definition: scheduler.h:175
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:45
void pe_free_working_set(pcmk_scheduler_t *scheduler)
Free scheduler data.
Definition: status.c:50
pcmk_resource_t * mysql_group_1
Cluster status and scheduling.
const char * path
Definition: cib.c:28
xmlNode * input
Skip counting of total, disabled, and blocked resource instances.
Definition: scheduler.h:149
pcmk_resource_t * promotable_1
pcmk_resource_t * mysql_group_0
char * id
Resource ID in configuration.
Definition: resources.h:400