pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
parse_op_key_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020-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 <glib.h>
15 
16 static void
17 basic(void **state)
18 {
19  char *rsc = NULL;
20  char *ty = NULL;
21  guint ms = 0;
22 
23  assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms));
24  assert_string_equal(rsc, "Fencing");
25  assert_string_equal(ty, "monitor");
26  assert_int_equal(ms, 60000);
27  free(rsc);
28  free(ty);
29 
30  // Single-character resource name
31  assert_true(parse_op_key("R_monitor_100000", &rsc, &ty, &ms));
32  assert_string_equal(rsc, "R");
33  assert_string_equal(ty, "monitor");
34  assert_int_equal(ms, 100000);
35  free(rsc);
36  free(ty);
37 
38  // Single-character action name
39  assert_true(parse_op_key("R_A_0", &rsc, &ty, &ms));
40  assert_string_equal(rsc, "R");
41  assert_string_equal(ty, "A");
42  assert_int_equal(ms, 0);
43  free(rsc);
44  free(ty);
45 }
46 
47 static void
48 rsc_just_underbars(void **state)
49 {
50  char *rsc = NULL;
51  char *ty = NULL;
52  guint ms = 0;
53 
54  assert_true(parse_op_key("__monitor_1000", &rsc, &ty, &ms));
55  assert_string_equal(rsc, "_");
56  assert_string_equal(ty, "monitor");
57  assert_int_equal(ms, 1000);
58  free(rsc);
59  free(ty);
60 
61  assert_true(parse_op_key("___migrate_from_0", &rsc, &ty, &ms));
62  assert_string_equal(rsc, "__");
63  assert_string_equal(ty, "migrate_from");
64  assert_int_equal(ms, 0);
65  free(rsc);
66  free(ty);
67 
68  assert_true(parse_op_key("____pre_notify_stop_0", &rsc, &ty, &ms));
69  assert_string_equal(rsc, "___");
70  assert_string_equal(ty, "pre_notify_stop");
71  assert_int_equal(ms, 0);
72  free(rsc);
73  free(ty);
74 }
75 
76 static void
77 colon_in_rsc(void **state)
78 {
79  char *rsc = NULL;
80  char *ty = NULL;
81  guint ms = 0;
82 
83  assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms));
84  assert_string_equal(rsc, "ClusterIP:0");
85  assert_string_equal(ty, "start");
86  assert_int_equal(ms, 0);
87  free(rsc);
88  free(ty);
89 
90  assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms));
91  assert_string_equal(rsc, "imagestoreclone:1");
92  assert_string_equal(ty, "post_notify_stop");
93  assert_int_equal(ms, 0);
94  free(rsc);
95  free(ty);
96 }
97 
98 static void
99 dashes_in_rsc(void **state)
100 {
101  char *rsc = NULL;
102  char *ty = NULL;
103  guint ms = 0;
104 
105  assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms));
106  assert_string_equal(rsc, "httpd-bundle-0");
107  assert_string_equal(ty, "monitor");
108  assert_int_equal(ms, 30000);
109  free(rsc);
110  free(ty);
111 
112  assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms));
113  assert_string_equal(rsc, "httpd-bundle-ip-192.168.122.132");
114  assert_string_equal(ty, "start");
115  assert_int_equal(ms, 0);
116  free(rsc);
117  free(ty);
118 }
119 
120 static void
121 migrate_to_from(void **state)
122 {
123  char *rsc = NULL;
124  char *ty = NULL;
125  guint ms = 0;
126 
127  assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms));
128  assert_string_equal(rsc, "vm");
129  assert_string_equal(ty, "migrate_from");
130  assert_int_equal(ms, 0);
131  free(rsc);
132  free(ty);
133 
134  assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms));
135  assert_string_equal(rsc, "vm");
136  assert_string_equal(ty, "migrate_to");
137  assert_int_equal(ms, 0);
138  free(rsc);
139  free(ty);
140 
141  assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms));
142  assert_string_equal(rsc, "vm_idcc_devel");
143  assert_string_equal(ty, "migrate_to");
144  assert_int_equal(ms, 0);
145  free(rsc);
146  free(ty);
147 }
148 
149 static void
150 pre_post(void **state)
151 {
152  char *rsc = NULL;
153  char *ty = NULL;
154  guint ms = 0;
155 
156  assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms));
157  assert_string_equal(rsc, "rsc_drbd_7788:1");
158  assert_string_equal(ty, "post_notify_start");
159  assert_int_equal(ms, 0);
160  free(rsc);
161  free(ty);
162 
163  assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms));
164  assert_string_equal(rsc, "rabbitmq-bundle-clone");
165  assert_string_equal(ty, "pre_notify_stop");
166  assert_int_equal(ms, 0);
167  free(rsc);
168  free(ty);
169 
170  assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms));
171  assert_string_equal(rsc, "post_notify");
172  assert_string_equal(ty, "start");
173  assert_int_equal(ms, 0);
174  free(rsc);
175  free(ty);
176 
177  assert_true(parse_op_key("r_confirmed-post_notify_start_0",
178  &rsc, &ty, &ms));
179  assert_string_equal(rsc, "r");
180  assert_string_equal(ty, "confirmed-post_notify_start");
181  assert_int_equal(ms, 0);
182  free(rsc);
183  free(ty);
184 }
185 
186 static void
187 skip_rsc(void **state)
188 {
189  char *ty = NULL;
190  guint ms = 0;
191 
192  assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms));
193  assert_string_equal(ty, "monitor");
194  assert_int_equal(ms, 60000);
195  free(ty);
196 }
197 
198 static void
199 skip_ty(void **state)
200 {
201  char *rsc = NULL;
202  guint ms = 0;
203 
204  assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms));
205  assert_string_equal(rsc, "Fencing");
206  assert_int_equal(ms, 60000);
207  free(rsc);
208 }
209 
210 static void
211 skip_ms(void **state)
212 {
213  char *rsc = NULL;
214  char *ty = NULL;
215 
216  assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL));
217  assert_string_equal(rsc, "Fencing");
218  assert_string_equal(ty, "monitor");
219  free(rsc);
220  free(ty);
221 }
222 
223 static void
224 empty_input(void **state)
225 {
226  char *rsc = NULL;
227  char *ty = NULL;
228  guint ms = 0;
229 
230  assert_false(parse_op_key("", &rsc, &ty, &ms));
231  assert_null(rsc);
232  assert_null(ty);
233  assert_int_equal(ms, 0);
234 
235  assert_false(parse_op_key(NULL, &rsc, &ty, &ms));
236  assert_null(rsc);
237  assert_null(ty);
238  assert_int_equal(ms, 0);
239 }
240 
241 static void
242 malformed_input(void **state)
243 {
244  char *rsc = NULL;
245  char *ty = NULL;
246  guint ms = 0;
247 
248  assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms));
249  assert_null(rsc);
250  assert_null(ty);
251  assert_int_equal(ms, 0);
252 
253  assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms));
254  assert_null(rsc);
255  assert_null(ty);
256  assert_int_equal(ms, 0);
257 
258  assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms));
259  assert_null(rsc);
260  assert_null(ty);
261  assert_int_equal(ms, 0);
262 }
263 
264 PCMK__UNIT_TEST(NULL, NULL,
265  cmocka_unit_test(basic),
266  cmocka_unit_test(rsc_just_underbars),
267  cmocka_unit_test(colon_in_rsc),
268  cmocka_unit_test(dashes_in_rsc),
269  cmocka_unit_test(migrate_to_from),
270  cmocka_unit_test(pre_post),
271  cmocka_unit_test(skip_rsc),
272  cmocka_unit_test(skip_ty),
273  cmocka_unit_test(skip_ms),
274  cmocka_unit_test(empty_input),
275  cmocka_unit_test(malformed_input))
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))
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
Definition: actions.c:96