This source file includes following definitions.
- assert_rsc_expression
- null_invalid
- id_missing
- fail_standard
- fail_provider
- fail_agent
- no_standard_matches
- no_provider_matches
- no_agent_matches
- no_criteria_matches
- all_match
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <glib.h>
14
15 #include <crm/common/xml.h>
16 #include <crm/common/rules_internal.h>
17 #include <crm/common/unittest_internal.h>
18 #include "crmcommon_private.h"
19
20
21
22
23
24 static pcmk_rule_input_t rule_input = {
25
26 .rsc_standard = PCMK_RESOURCE_CLASS_OCF,
27 .rsc_provider = "heartbeat",
28 .rsc_agent = "IPaddr2",
29 };
30
31
32
33
34
35
36
37
38 static void
39 assert_rsc_expression(const char *xml_string, int reference_rc)
40 {
41 xmlNode *xml = pcmk__xml_parse(xml_string);
42
43 assert_int_equal(pcmk__evaluate_rsc_expression(xml, &rule_input),
44 reference_rc);
45 free_xml(xml);
46 }
47
48
49
50
51
52
53 #define EXPR_ALL_MATCH \
54 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
55 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
56 PCMK_XA_PROVIDER "='heartbeat' " \
57 PCMK_XA_TYPE "='IPaddr2' />"
58
59 static void
60 null_invalid(void **state)
61 {
62 xmlNode *xml = NULL;
63
64 assert_int_equal(pcmk__evaluate_rsc_expression(NULL, NULL), EINVAL);
65
66 xml = pcmk__xml_parse(EXPR_ALL_MATCH);
67 assert_int_equal(pcmk__evaluate_rsc_expression(xml, NULL), EINVAL);
68 free_xml(xml);
69
70 assert_rsc_expression(NULL, EINVAL);
71 }
72
73
74
75
76
77
78 #define EXPR_ID_MISSING \
79 "<" PCMK_XE_RSC_EXPRESSION " " \
80 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
81 PCMK_XA_PROVIDER "='heartbeat' " \
82 PCMK_XA_TYPE "='IPaddr2' />"
83
84 #define EXPR_ID_EMPTY \
85 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='' " \
86 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
87 PCMK_XA_PROVIDER "='heartbeat' " \
88 PCMK_XA_TYPE "='IPaddr2' />"
89
90 static void
91 id_missing(void **state)
92 {
93
94 assert_rsc_expression(EXPR_ID_MISSING, pcmk_rc_ok);
95 assert_rsc_expression(EXPR_ID_EMPTY, pcmk_rc_ok);
96 }
97
98
99
100
101
102
103 #define EXPR_FAIL_STANDARD \
104 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
105 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_LSB "' />"
106
107 #define EXPR_EMPTY_STANDARD \
108 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
109 PCMK_XA_CLASS "='' />"
110
111 static void
112 fail_standard(void **state)
113 {
114 assert_rsc_expression(EXPR_FAIL_STANDARD, pcmk_rc_op_unsatisfied);
115 assert_rsc_expression(EXPR_EMPTY_STANDARD, pcmk_rc_op_unsatisfied);
116
117 rule_input.rsc_standard = NULL;
118 assert_rsc_expression(EXPR_FAIL_STANDARD, pcmk_rc_op_unsatisfied);
119 assert_rsc_expression(EXPR_EMPTY_STANDARD, pcmk_rc_op_unsatisfied);
120 rule_input.rsc_standard = PCMK_RESOURCE_CLASS_OCF;
121 }
122
123 #define EXPR_FAIL_PROVIDER \
124 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
125 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
126 PCMK_XA_PROVIDER "='pacemaker' " \
127 PCMK_XA_TYPE "='IPaddr2' />"
128
129 #define EXPR_EMPTY_PROVIDER \
130 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
131 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
132 PCMK_XA_PROVIDER "='' " PCMK_XA_TYPE "='IPaddr2' />"
133
134 static void
135 fail_provider(void **state)
136 {
137 assert_rsc_expression(EXPR_FAIL_PROVIDER, pcmk_rc_op_unsatisfied);
138 assert_rsc_expression(EXPR_EMPTY_PROVIDER, pcmk_rc_op_unsatisfied);
139
140 rule_input.rsc_provider = NULL;
141 assert_rsc_expression(EXPR_FAIL_PROVIDER, pcmk_rc_op_unsatisfied);
142 assert_rsc_expression(EXPR_EMPTY_PROVIDER, pcmk_rc_op_unsatisfied);
143 rule_input.rsc_provider = "heartbeat";
144 }
145
146 #define EXPR_FAIL_AGENT \
147 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
148 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
149 PCMK_XA_PROVIDER "='heartbeat' " \
150 PCMK_XA_TYPE "='IPaddr3' />"
151
152 #define EXPR_EMPTY_AGENT \
153 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
154 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
155 PCMK_XA_PROVIDER "='heartbeat' " PCMK_XA_TYPE "='' />"
156
157 static void
158 fail_agent(void **state)
159 {
160 assert_rsc_expression(EXPR_FAIL_AGENT, pcmk_rc_op_unsatisfied);
161 assert_rsc_expression(EXPR_EMPTY_AGENT, pcmk_rc_op_unsatisfied);
162
163 rule_input.rsc_agent = NULL;
164 assert_rsc_expression(EXPR_FAIL_AGENT, pcmk_rc_op_unsatisfied);
165 assert_rsc_expression(EXPR_EMPTY_AGENT, pcmk_rc_op_unsatisfied);
166 rule_input.rsc_agent = "IPaddr2";
167 }
168
169 #define EXPR_NO_STANDARD_MATCHES \
170 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
171 PCMK_XA_PROVIDER "='heartbeat' " \
172 PCMK_XA_TYPE "='IPaddr2' />"
173
174 static void
175 no_standard_matches(void **state)
176 {
177 assert_rsc_expression(EXPR_NO_STANDARD_MATCHES, pcmk_rc_ok);
178 }
179
180 #define EXPR_NO_PROVIDER_MATCHES \
181 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
182 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
183 PCMK_XA_TYPE "='IPaddr2' />"
184
185 static void
186 no_provider_matches(void **state)
187 {
188 assert_rsc_expression(EXPR_NO_PROVIDER_MATCHES, pcmk_rc_ok);
189 }
190
191 #define EXPR_NO_AGENT_MATCHES \
192 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' " \
193 PCMK_XA_CLASS "='" PCMK_RESOURCE_CLASS_OCF "' " \
194 PCMK_XA_PROVIDER "='heartbeat' />"
195
196 static void
197 no_agent_matches(void **state)
198 {
199 assert_rsc_expression(EXPR_NO_AGENT_MATCHES, pcmk_rc_ok);
200 }
201
202 #define EXPR_NO_CRITERIA_MATCHES \
203 "<" PCMK_XE_RSC_EXPRESSION " " PCMK_XA_ID "='e' />"
204
205 static void
206 no_criteria_matches(void **state)
207 {
208 assert_rsc_expression(EXPR_NO_CRITERIA_MATCHES, pcmk_rc_ok);
209 }
210
211 static void
212 all_match(void **state)
213 {
214 assert_rsc_expression(EXPR_ALL_MATCH, pcmk_rc_ok);
215 }
216
217 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
218 cmocka_unit_test(null_invalid),
219 cmocka_unit_test(id_missing),
220 cmocka_unit_test(fail_standard),
221 cmocka_unit_test(fail_provider),
222 cmocka_unit_test(fail_agent),
223 cmocka_unit_test(no_standard_matches),
224 cmocka_unit_test(no_provider_matches),
225 cmocka_unit_test(no_agent_matches),
226 cmocka_unit_test(no_criteria_matches),
227 cmocka_unit_test(all_match))