pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk_xe_mask_probe_failure_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 <stdlib.h>
16 #include <setjmp.h>
17 #include <cmocka.h>
18 
19 static void
20 op_is_not_probe_test(void **state) {
21  xmlNode *node = NULL;
22 
23  /* Not worth testing this thoroughly since it's just a duplicate of whether
24  * pcmk_op_is_probe works or not.
25  */
26 
27  node = string2xml("<lrm_rsc_op operation=\"start\" interval=\"0\"/>");
28  assert_false(pcmk_xe_mask_probe_failure(node));
29  free_xml(node);
30 }
31 
32 static void
33 op_does_not_have_right_values_test(void **state) {
34  xmlNode *node = NULL;
35 
36  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\"/>");
37  assert_false(pcmk_xe_mask_probe_failure(node));
38  free_xml(node);
39 
40  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"0\" op-status=\"\"/>");
41  assert_false(pcmk_xe_mask_probe_failure(node));
42  free_xml(node);
43 }
44 
45 static void
46 check_values_test(void **state) {
47  xmlNode *node = NULL;
48 
49  /* PCMK_EXEC_NOT_SUPPORTED */
50  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"0\" op-status=\"3\"/>");
51  assert_false(pcmk_xe_mask_probe_failure(node));
52  free_xml(node);
53 
54  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"5\" op-status=\"3\"/>");
55  assert_true(pcmk_xe_mask_probe_failure(node));
56  free_xml(node);
57 
58  /* PCMK_EXEC_DONE */
59  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"0\" op-status=\"0\"/>");
60  assert_false(pcmk_xe_mask_probe_failure(node));
61  free_xml(node);
62 
63  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"2\" op-status=\"0\"/>");
64  assert_true(pcmk_xe_mask_probe_failure(node));
65  free_xml(node);
66 
67  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"5\" op-status=\"0\"/>");
68  assert_true(pcmk_xe_mask_probe_failure(node));
69  free_xml(node);
70 
71  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"6\" op-status=\"0\"/>");
72  assert_false(pcmk_xe_mask_probe_failure(node));
73  free_xml(node);
74 
75  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"7\" op-status=\"0\"/>");
76  assert_false(pcmk_xe_mask_probe_failure(node));
77  free_xml(node);
78 
79  /* PCMK_EXEC_NOT_INSTALLED */
80  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"0\" op-status=\"7\"/>");
81  assert_true(pcmk_xe_mask_probe_failure(node));
82  free_xml(node);
83 
84  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"5\" op-status=\"7\"/>");
85  assert_true(pcmk_xe_mask_probe_failure(node));
86  free_xml(node);
87 
88  /* PCMK_EXEC_ERROR */
89  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"0\" op-status=\"4\"/>");
90  assert_false(pcmk_xe_mask_probe_failure(node));
91  free_xml(node);
92 
93  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"2\" op-status=\"4\"/>");
94  assert_true(pcmk_xe_mask_probe_failure(node));
95  free_xml(node);
96 
97  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"5\" op-status=\"4\"/>");
98  assert_true(pcmk_xe_mask_probe_failure(node));
99  free_xml(node);
100 
101  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"6\" op-status=\"4\"/>");
102  assert_false(pcmk_xe_mask_probe_failure(node));
103  free_xml(node);
104 
105  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"7\" op-status=\"4\"/>");
106  assert_false(pcmk_xe_mask_probe_failure(node));
107  free_xml(node);
108 
109  /* PCMK_EXEC_ERROR_HARD */
110  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"0\" op-status=\"5\"/>");
111  assert_false(pcmk_xe_mask_probe_failure(node));
112  free_xml(node);
113 
114  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"2\" op-status=\"5\"/>");
115  assert_true(pcmk_xe_mask_probe_failure(node));
116  free_xml(node);
117 
118  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"5\" op-status=\"5\"/>");
119  assert_true(pcmk_xe_mask_probe_failure(node));
120  free_xml(node);
121 
122  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"6\" op-status=\"5\"/>");
123  assert_false(pcmk_xe_mask_probe_failure(node));
124  free_xml(node);
125 
126  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"7\" op-status=\"5\"/>");
127  assert_false(pcmk_xe_mask_probe_failure(node));
128  free_xml(node);
129 
130  /* PCMK_EXEC_ERROR_FATAL */
131  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"0\" op-status=\"6\"/>");
132  assert_false(pcmk_xe_mask_probe_failure(node));
133  free_xml(node);
134 
135  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"2\" op-status=\"6\"/>");
136  assert_true(pcmk_xe_mask_probe_failure(node));
137  free_xml(node);
138 
139  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"5\" op-status=\"6\"/>");
140  assert_true(pcmk_xe_mask_probe_failure(node));
141  free_xml(node);
142 
143  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"6\" op-status=\"6\"/>");
144  assert_false(pcmk_xe_mask_probe_failure(node));
145  free_xml(node);
146 
147  node = string2xml("<lrm_rsc_op operation=\"monitor\" interval=\"0\" rc-code=\"7\" op-status=\"6\"/>");
148  assert_false(pcmk_xe_mask_probe_failure(node));
149  free_xml(node);
150 }
151 
152 int main(int argc, char **argv)
153 {
154  const struct CMUnitTest tests[] = {
155  cmocka_unit_test(op_is_not_probe_test),
156  cmocka_unit_test(op_does_not_have_right_values_test),
157  cmocka_unit_test(check_values_test),
158  };
159 
160  cmocka_set_message_output(CM_OUTPUT_TAP);
161  return cmocka_run_group_tests(tests, NULL, NULL);
162 }
xmlNode * string2xml(const char *input)
Definition: xml.c:869
bool pcmk_xe_mask_probe_failure(xmlNode *xml_op)
Definition: operations.c:563
void free_xml(xmlNode *child)
Definition: xml.c:824
int main(int argc, char **argv)