backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / networkxml2xmlupdatetest.c
blob69c19e800d801d840631d5a0f4c6d02b26d76ab0
1 #include <config.h>
3 #include <unistd.h>
5 #include <sys/types.h>
6 #include <fcntl.h>
8 #include "internal.h"
9 #include "testutils.h"
10 #include "network_conf.h"
11 #include "testutilsqemu.h"
12 #include "virstring.h"
14 #define VIR_FROM_THIS VIR_FROM_NONE
16 static int
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;
23 char *actual = NULL;
24 int ret = -1;
25 virNetworkDefPtr def = NULL;
27 if (virTestLoadFile(updatexml, &updateXmlData) < 0)
28 goto error;
30 if (!(def = virNetworkDefParseFile(netxml, NULL)))
31 goto fail;
33 if (virNetworkDefUpdateSection(def, command, section, parentIndex,
34 updateXmlData, 0) < 0)
35 goto fail;
37 if (!(actual = virNetworkDefFormat(def, NULL, flags)))
38 goto fail;
40 if (!expectFailure) {
41 if (virTestCompareToFile(actual, outxml) < 0)
42 goto error;
45 ret = 0;
47 fail:
48 if (expectFailure) {
49 if (ret == 0) {
50 virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Failed to fail.");
51 ret = -1;
52 } else {
53 virResetLastError();
54 ret = 0;
57 error:
58 VIR_FREE(updateXmlData);
59 VIR_FREE(actual);
60 virNetworkDefFree(def);
61 return ret;
64 struct testInfo {
65 const char *name;
66 const char *updatexml;
67 const char *netxml;
68 const char *outxml;
69 unsigned int command;
70 unsigned int section;
71 int parentIndex;
72 unsigned int flags;
73 bool expectFailure;
76 static int
77 testCompareXMLToXMLHelper(const void *data)
79 const struct testInfo *info = data;
80 int result = -1;
81 char *netxml = NULL;
82 char *updatexml = NULL;
83 char *outxml = 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) {
91 goto cleanup;
94 result = testCompareXMLToXMLFiles(netxml, updatexml, outxml, info->flags,
95 info->command, info->section,
96 info->parentIndex, info->expectFailure);
98 cleanup:
99 VIR_FREE(netxml);
100 VIR_FREE(updatexml);
101 VIR_FREE(outxml);
103 return result;
106 static int
107 mymain(void)
109 int ret = 0;
110 unsigned int section;
112 #define DO_TEST_FULL(name, updatexml, netxml, outxml, command, section, \
113 parentIndex, flags, expectFailure) \
114 do { \
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) \
120 ret = -1; \
121 } while (0)
123 #define DO_TEST(name, updatexml, netxml, outxml, command) \
124 DO_TEST_FULL(name, updatexml, netxml, outxml, command, section, -12435, \
125 0, false)
126 #define DO_TEST_FAIL(name, updatexml, netxml, command) \
127 DO_TEST_FULL(name, updatexml, netxml, "n/a", command, section, -12345, \
128 0, true)
130 #define DO_TEST_INDEX(name, updatexml, netxml, outxml, command, index) \
131 DO_TEST_FULL(name, updatexml, netxml, outxml, command, section, index, \
132 0, false)
133 #define DO_TEST_INDEX_FAIL(name, updatexml, netxml, command, index) \
134 DO_TEST_FULL(name, updatexml, netxml, "n/a", command, section, index, \
135 0, true)
138 section = VIR_NETWORK_SECTION_IP_DHCP_HOST;
139 DO_TEST_INDEX_FAIL("add-host-incomplete",
140 "host-incomplete",
141 "nat-network",
142 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST,
144 DO_TEST_INDEX_FAIL("add-host-new-incomplete",
145 "host-new-incomplete",
146 "nat-network",
147 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST,
149 DO_TEST_INDEX_FAIL("add-host-existing",
150 "host-existing",
151 "nat-network",
152 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST,
154 DO_TEST_INDEX("add-host-new",
155 "host-new",
156 "nat-network",
157 "nat-network-hosts",
158 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST,
160 DO_TEST_INDEX_FAIL("modify-host-missing",
161 "host-new",
162 "nat-network",
163 VIR_NETWORK_UPDATE_COMMAND_MODIFY,
165 DO_TEST_INDEX_FAIL("modify-host-incomplete",
166 "host-incomplete",
167 "nat-network",
168 VIR_NETWORK_UPDATE_COMMAND_MODIFY,
170 DO_TEST_INDEX("modify-host",
171 "host-updated",
172 "nat-network",
173 "nat-network-host-updated",
174 VIR_NETWORK_UPDATE_COMMAND_MODIFY,
176 DO_TEST_INDEX("delete-host-incomplete",
177 "host-incomplete",
178 "nat-network",
179 "nat-network-one-host",
180 VIR_NETWORK_UPDATE_COMMAND_DELETE,
182 DO_TEST_INDEX("delete-host-existing",
183 "host-existing",
184 "nat-network",
185 "nat-network-one-host",
186 VIR_NETWORK_UPDATE_COMMAND_DELETE,
188 DO_TEST_INDEX_FAIL("delete-host-missing",
189 "host-new",
190 "nat-network",
191 VIR_NETWORK_UPDATE_COMMAND_DELETE,
195 section = VIR_NETWORK_SECTION_IP_DHCP_RANGE;
196 DO_TEST_INDEX("add-dhcp-range",
197 "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",
203 "dhcp-range-10",
204 "dhcp6host-routed-network",
205 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST,
207 DO_TEST_INDEX("append-dhcp-range",
208 "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",
215 "nat-network",
216 "nat-network-no-range",
217 VIR_NETWORK_UPDATE_COMMAND_DELETE,
219 DO_TEST_INDEX_FAIL("delete-dhcp-range",
220 "dhcp-range",
221 "nat-network",
222 VIR_NETWORK_UPDATE_COMMAND_DELETE,
226 section = VIR_NETWORK_SECTION_FORWARD_INTERFACE;
227 DO_TEST("insert-forward-interface",
228 "interface-eth47",
229 "nat-network-dns-srv-record",
230 "nat-network-forward-ifaces",
231 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST);
232 DO_TEST("delete-forward-interface",
233 "interface-eth1",
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",
238 "interface-eth47",
239 "nat-network-dns-srv-record",
240 VIR_NETWORK_UPDATE_COMMAND_DELETE);
243 section = VIR_NETWORK_SECTION_PORTGROUP;
244 DO_TEST("insert-portgroup",
245 "portgroup-alison",
246 "openvswitch-net",
247 "openvswitch-net-more-portgroups",
248 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST);
249 DO_TEST_FAIL("append-duplicate-portgroup",
250 "portgroup-alice-new",
251 "openvswitch-net",
252 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
253 DO_TEST("modify-portgroup",
254 "portgroup-alice-new",
255 "openvswitch-net",
256 "openvswitch-net-modified",
257 VIR_NETWORK_UPDATE_COMMAND_MODIFY);
258 DO_TEST_FAIL("modify-missing-portgroup",
259 "portgroup-alison",
260 "openvswitch-net",
261 VIR_NETWORK_UPDATE_COMMAND_MODIFY);
262 DO_TEST("delete-portgroup",
263 "portgroup-alice-new",
264 "openvswitch-net",
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",
279 "dns-host-pudding",
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",
285 "nat-network",
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",
317 "srv-record",
318 "nat-network",
319 "nat-network-dns-srv-record",
320 VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST);
321 DO_TEST("append-first-srv-record-service",
322 "srv-record",
323 "nat-network",
324 "nat-network-dns-srv-record",
325 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
326 DO_TEST_FAIL("add-existing-dns-srv-record",
327 "srv-record",
328 "nat-network-dns-srv-record",
329 VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
330 DO_TEST("append-srv-record-service",
331 "srv-record-donkey",
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",
338 "nat-network",
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",
345 "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",
356 "nat-network",
357 VIR_NETWORK_UPDATE_COMMAND_DELETE);
360 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
363 VIR_TEST_MAIN(mymain)