pacemaker  2.1.5-b7adf64e51
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 
13 
14 #include <crm/common/xml.h>
15 #include <crm/pengine/internal.h>
16 #include <crm/pengine/status.h>
17 #include <crm/pengine/pe_types.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 (data_set == NULL) {
42  return 1;
43  }
44 
46  data_set->input = input;
47 
49 
50  /* Get references to several resources we use frequently. */
51  for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) {
52  pe_resource_t *rsc = (pe_resource_t *) iter->data;
53 
54  if (strcmp(rsc->id, "dummy") == 0) {
55  dummy = rsc;
56  } else if (strcmp(rsc->id, "exim-group") == 0) {
57  exim_group = rsc;
58  } else if (strcmp(rsc->id, "httpd-bundle") == 0) {
59  httpd_bundle = rsc;
60  } else if (strcmp(rsc->id, "mysql-clone-group") == 0) {
61  for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
62  pe_resource_t *child = (pe_resource_t *) iter->data;
63 
64  if (strcmp(child->id, "mysql-group:0") == 0) {
65  mysql_group_0 = child;
66  } else if (strcmp(child->id, "mysql-group:1") == 0) {
67  mysql_group_1 = child;
68  }
69  }
70  } else if (strcmp(rsc->id, "promotable-clone") == 0) {
71  for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
72  pe_resource_t *child = (pe_resource_t *) iter->data;
73 
74  if (strcmp(child->id, "promotable-rsc:0") == 0) {
75  promotable_0 = child;
76  } else if (strcmp(child->id, "promotable-rsc:1") == 0) {
77  promotable_1 = child;
78  }
79  }
80  }
81  }
82 
83  return 0;
84 }
85 
86 static int
87 teardown(void **state) {
89 
90  return 0;
91 }
92 
93 static void
94 bad_args(void **state) {
95  char *id = dummy->id;
96 
97  assert_false(pe_base_name_eq(NULL, "dummy"));
98  assert_false(pe_base_name_eq(dummy, NULL));
99 
100  dummy->id = NULL;
101  assert_false(pe_base_name_eq(dummy, "dummy"));
102  dummy->id = id;
103 }
104 
105 static void
106 primitive_rsc(void **state) {
107  assert_true(pe_base_name_eq(dummy, "dummy"));
108  assert_false(pe_base_name_eq(dummy, "DUMMY"));
109  assert_false(pe_base_name_eq(dummy, "dUmMy"));
110  assert_false(pe_base_name_eq(dummy, "dummy0"));
111  assert_false(pe_base_name_eq(dummy, "dummy:0"));
112 }
113 
114 static void
115 group_rsc(void **state) {
116  assert_true(pe_base_name_eq(exim_group, "exim-group"));
117  assert_false(pe_base_name_eq(exim_group, "EXIM-GROUP"));
118  assert_false(pe_base_name_eq(exim_group, "exim-group0"));
119  assert_false(pe_base_name_eq(exim_group, "exim-group:0"));
120  assert_false(pe_base_name_eq(exim_group, "Public-IP"));
121 }
122 
123 static void
124 clone_rsc(void **state) {
125  assert_true(pe_base_name_eq(promotable_0, "promotable-rsc"));
126  assert_true(pe_base_name_eq(promotable_1, "promotable-rsc"));
127 
128  assert_false(pe_base_name_eq(promotable_0, "promotable-rsc:0"));
129  assert_false(pe_base_name_eq(promotable_1, "promotable-rsc:1"));
130  assert_false(pe_base_name_eq(promotable_0, "PROMOTABLE-RSC"));
131  assert_false(pe_base_name_eq(promotable_1, "PROMOTABLE-RSC"));
132  assert_false(pe_base_name_eq(promotable_0, "Promotable-rsc"));
133  assert_false(pe_base_name_eq(promotable_1, "Promotable-rsc"));
134 }
135 
136 static void
137 bundle_rsc(void **state) {
138  assert_true(pe_base_name_eq(httpd_bundle, "httpd-bundle"));
139  assert_false(pe_base_name_eq(httpd_bundle, "HTTPD-BUNDLE"));
140  assert_false(pe_base_name_eq(httpd_bundle, "httpd"));
141  assert_false(pe_base_name_eq(httpd_bundle, "httpd-docker-0"));
142 }
143 
144 PCMK__UNIT_TEST(setup, teardown,
145  cmocka_unit_test(bad_args),
146  cmocka_unit_test(primitive_rsc),
147  cmocka_unit_test(group_rsc),
148  cmocka_unit_test(clone_rsc),
149  cmocka_unit_test(bundle_rsc))
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:384
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:2971
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
#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:1106
GList * resources
Definition: pe_types.h:165
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:62
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:329