10 #include "network_conf.h"
11 #include "testutilsqemu.h"
12 #include "virstring.h"
14 #define VIR_FROM_THIS VIR_FROM_NONE
17 testCompareXMLToXMLFiles(const char *netxml
, const char *updatexml
,
18 const char *outxml
, unsigned int flags
,
19 unsigned int command
, unsigned int section
,
20 int parentIndex
, bool expectFailure
)
22 char *updateXmlData
= NULL
;
25 virNetworkDefPtr def
= NULL
;
27 if (virTestLoadFile(updatexml
, &updateXmlData
) < 0)
30 if (!(def
= virNetworkDefParseFile(netxml
, NULL
)))
33 if (virNetworkDefUpdateSection(def
, command
, section
, parentIndex
,
34 updateXmlData
, 0) < 0)
37 if (!(actual
= virNetworkDefFormat(def
, NULL
, flags
)))
41 if (virTestCompareToFile(actual
, outxml
) < 0)
50 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s", "Failed to fail.");
58 VIR_FREE(updateXmlData
);
60 virNetworkDefFree(def
);
66 const char *updatexml
;
77 testCompareXMLToXMLHelper(const void *data
)
79 const struct testInfo
*info
= data
;
82 char *updatexml
= NULL
;
85 if (virAsprintf(&netxml
, "%s/networkxml2xmlin/%s.xml",
86 abs_srcdir
, info
->netxml
) < 0 ||
87 virAsprintf(&updatexml
, "%s/networkxml2xmlupdatein/%s.xml",
88 abs_srcdir
, info
->updatexml
) < 0 ||
89 virAsprintf(&outxml
, "%s/networkxml2xmlupdateout/%s.xml",
90 abs_srcdir
, info
->outxml
) < 0) {
94 result
= testCompareXMLToXMLFiles(netxml
, updatexml
, outxml
, info
->flags
,
95 info
->command
, info
->section
,
96 info
->parentIndex
, info
->expectFailure
);
110 unsigned int section
;
112 #define DO_TEST_FULL(name, updatexml, netxml, outxml, command, section, \
113 parentIndex, flags, expectFailure) \
115 const struct testInfo info = {name, updatexml, netxml, outxml, \
116 command, section, flags, \
117 parentIndex, expectFailure}; \
118 if (virTestRun("Network XML-2-XML " name, \
119 testCompareXMLToXMLHelper, &info) < 0) \
123 #define DO_TEST(name, updatexml, netxml, outxml, command) \
124 DO_TEST_FULL(name, updatexml, netxml, outxml, command, section, -12435, \
126 #define DO_TEST_FAIL(name, updatexml, netxml, command) \
127 DO_TEST_FULL(name, updatexml, netxml, "n/a", command, section, -12345, \
130 #define DO_TEST_INDEX(name, updatexml, netxml, outxml, command, index) \
131 DO_TEST_FULL(name, updatexml, netxml, outxml, command, section, index, \
133 #define DO_TEST_INDEX_FAIL(name, updatexml, netxml, command, index) \
134 DO_TEST_FULL(name, updatexml, netxml, "n/a", command, section, index, \
138 section
= VIR_NETWORK_SECTION_IP_DHCP_HOST
;
139 DO_TEST_INDEX_FAIL("add-host-incomplete",
142 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
,
144 DO_TEST_INDEX_FAIL("add-host-new-incomplete",
145 "host-new-incomplete",
147 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
,
149 DO_TEST_INDEX_FAIL("add-host-existing",
152 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
,
154 DO_TEST_INDEX("add-host-new",
158 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
,
160 DO_TEST_INDEX_FAIL("modify-host-missing",
163 VIR_NETWORK_UPDATE_COMMAND_MODIFY
,
165 DO_TEST_INDEX_FAIL("modify-host-incomplete",
168 VIR_NETWORK_UPDATE_COMMAND_MODIFY
,
170 DO_TEST_INDEX("modify-host",
173 "nat-network-host-updated",
174 VIR_NETWORK_UPDATE_COMMAND_MODIFY
,
176 DO_TEST_INDEX("delete-host-incomplete",
179 "nat-network-one-host",
180 VIR_NETWORK_UPDATE_COMMAND_DELETE
,
182 DO_TEST_INDEX("delete-host-existing",
185 "nat-network-one-host",
186 VIR_NETWORK_UPDATE_COMMAND_DELETE
,
188 DO_TEST_INDEX_FAIL("delete-host-missing",
191 VIR_NETWORK_UPDATE_COMMAND_DELETE
,
195 section
= VIR_NETWORK_SECTION_IP_DHCP_RANGE
;
196 DO_TEST_INDEX("add-dhcp-range",
198 "dhcp6host-routed-network",
199 "dhcp6host-routed-network-range",
200 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
,
202 DO_TEST_INDEX_FAIL("add-dhcp-range-outside-net",
204 "dhcp6host-routed-network",
205 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
,
207 DO_TEST_INDEX("append-dhcp-range",
209 "dhcp6host-routed-network",
210 "dhcp6host-routed-network-another-range",
211 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
,
213 DO_TEST_INDEX("delete-dhcp-range",
214 "dhcp-range-existing",
216 "nat-network-no-range",
217 VIR_NETWORK_UPDATE_COMMAND_DELETE
,
219 DO_TEST_INDEX_FAIL("delete-dhcp-range",
222 VIR_NETWORK_UPDATE_COMMAND_DELETE
,
226 section
= VIR_NETWORK_SECTION_FORWARD_INTERFACE
;
227 DO_TEST("insert-forward-interface",
229 "nat-network-dns-srv-record",
230 "nat-network-forward-ifaces",
231 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
);
232 DO_TEST("delete-forward-interface",
234 "nat-network-dns-srv-record",
235 "nat-network-no-forward-ifaces",
236 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
237 DO_TEST_FAIL("delete-forward-interface",
239 "nat-network-dns-srv-record",
240 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
243 section
= VIR_NETWORK_SECTION_PORTGROUP
;
244 DO_TEST("insert-portgroup",
247 "openvswitch-net-more-portgroups",
248 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
);
249 DO_TEST_FAIL("append-duplicate-portgroup",
250 "portgroup-alice-new",
252 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
);
253 DO_TEST("modify-portgroup",
254 "portgroup-alice-new",
256 "openvswitch-net-modified",
257 VIR_NETWORK_UPDATE_COMMAND_MODIFY
);
258 DO_TEST_FAIL("modify-missing-portgroup",
261 VIR_NETWORK_UPDATE_COMMAND_MODIFY
);
262 DO_TEST("delete-portgroup",
263 "portgroup-alice-new",
265 "openvswitch-net-without-alice",
266 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
267 DO_TEST_FAIL("delete-missing-portgroup",
268 "portgroup-alice-new",
269 "nat-network-dns-srv-record",
270 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
273 section
= VIR_NETWORK_SECTION_DNS_HOST
;
274 DO_TEST_FAIL("insert-incomplete-host",
275 "dns-host-gateway-incomplete",
276 "nat-network-dns-hosts",
277 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
);
278 DO_TEST("insert-host",
280 "nat-network-dns-hosts",
281 "nat-network-dns-more-hosts",
282 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
);
283 DO_TEST_FAIL("delete-missing-unparsable-dns-host",
284 "unparsable-dns-host",
286 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
287 DO_TEST("delete-dns-host",
288 "dns-host-gateway-incomplete",
289 "nat-network-dns-hosts",
290 "nat-network-no-hosts",
291 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
294 section
= VIR_NETWORK_SECTION_DNS_TXT
;
295 DO_TEST("insert-dns-txt-record",
296 "dns-txt-record-snowman",
297 "nat-network-dns-txt-record",
298 "nat-network-dns-txt-records",
299 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
);
300 DO_TEST_FAIL("append-duplicate-dns-txt-record",
301 "dns-txt-record-example",
302 "nat-network-dns-txt-record",
303 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
);
304 DO_TEST("delete-dns-txt-record",
305 "dns-txt-record-example",
306 "nat-network-dns-txt-record",
307 "nat-network-dns-txt-none",
308 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
309 DO_TEST_FAIL("delete-missing-dns-txt-record",
310 "dns-txt-record-snowman",
311 "nat-network-dns-txt-record",
312 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
315 section
= VIR_NETWORK_SECTION_DNS_SRV
;
316 DO_TEST("insert-first-srv-record-service",
319 "nat-network-dns-srv-record",
320 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST
);
321 DO_TEST("append-first-srv-record-service",
324 "nat-network-dns-srv-record",
325 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
);
326 DO_TEST_FAIL("add-existing-dns-srv-record",
328 "nat-network-dns-srv-record",
329 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
);
330 DO_TEST("append-srv-record-service",
332 "nat-network-dns-srv-record",
333 "nat-network-dns-srv-records",
334 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST
);
336 DO_TEST_FAIL("delete-missing-srv-record-service",
337 "srv-record-service",
339 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
340 DO_TEST_FAIL("delete-srv-record-invalid",
341 "srv-record-invalid",
342 "nat-network-dns-srv-record",
343 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
344 DO_TEST("delete-srv-record-donkey",
346 "nat-network-dns-srv-records",
347 "nat-network-dns-srv-record",
348 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
349 DO_TEST_FAIL("delete-ambiguous-srv-record-service",
350 "srv-record-service",
351 "nat-network-dns-srv-records",
352 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
353 DO_TEST("delete-srv-record-protocol",
354 "srv-record-protocol",
355 "nat-network-dns-srv-record",
357 VIR_NETWORK_UPDATE_COMMAND_DELETE
);
360 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
363 VIR_TEST_MAIN(mymain
)