10 #include "network_conf.h"
11 #include "vircommand.h"
13 #include "network/bridge_driver.h"
14 #include "virstring.h"
16 #define VIR_FROM_THIS VIR_FROM_NONE
19 testCompareXMLToConfFiles(const char *inxml
, const char *outconf
, dnsmasqCapsPtr caps
)
23 virNetworkDefPtr def
= NULL
;
24 virNetworkObjPtr obj
= NULL
;
25 virCommandPtr cmd
= NULL
;
27 dnsmasqContext
*dctx
= NULL
;
28 virNetworkXMLOptionPtr xmlopt
= NULL
;
30 if (!(xmlopt
= networkDnsmasqCreateXMLConf()))
33 if (!(def
= virNetworkDefParseFile(inxml
, xmlopt
)))
36 if (!(obj
= virNetworkObjNew()))
39 virNetworkObjSetDef(obj
, def
);
41 dctx
= dnsmasqContextNew(def
->name
, "/var/lib/libvirt/dnsmasq");
46 if (networkDnsmasqConfContents(obj
, pidfile
, &actual
, dctx
, caps
) < 0)
49 /* Any changes to this function ^^ should be reflected here too. */
53 if (!(tmp
= virStringReplace(actual
,
54 "except-interface=lo0\n",
55 "except-interface=lo\n")))
58 VIR_STEAL_PTR(actual
, tmp
);
61 if (virTestCompareToFile(actual
, outconf
) < 0)
70 virObjectUnref(xmlopt
);
71 virNetworkObjEndAPI(&obj
);
72 dnsmasqContextFree(dctx
);
82 testCompareXMLToConfHelper(const void *data
)
85 const testInfo
*info
= data
;
89 if (virAsprintf(&inxml
, "%s/networkxml2confdata/%s.xml",
90 abs_srcdir
, info
->name
) < 0 ||
91 virAsprintf(&outconf
, "%s/networkxml2confdata/%s.conf",
92 abs_srcdir
, info
->name
) < 0) {
96 result
= testCompareXMLToConfFiles(inxml
, outconf
, info
->caps
);
109 dnsmasqCapsPtr restricted
110 = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.48", DNSMASQ
);
112 = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.63\n--bind-dynamic", DNSMASQ
);
113 dnsmasqCapsPtr dhcpv6
114 = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.64\n--bind-dynamic", DNSMASQ
);
116 #define DO_TEST(xname, xcaps) \
118 static testInfo info; \
122 if (virTestRun("Network XML-2-Conf " xname, \
123 testCompareXMLToConfHelper, &info) < 0) { \
128 DO_TEST("isolated-network", restricted
);
129 DO_TEST("netboot-network", restricted
);
130 DO_TEST("netboot-proxy-network", restricted
);
131 DO_TEST("nat-network-dns-srv-record-minimal", restricted
);
132 DO_TEST("nat-network-name-with-quotes", restricted
);
133 DO_TEST("routed-network", full
);
134 DO_TEST("routed-network-no-dns", full
);
135 DO_TEST("open-network", full
);
136 DO_TEST("nat-network", dhcpv6
);
137 DO_TEST("nat-network-dns-txt-record", full
);
138 DO_TEST("nat-network-dns-srv-record", full
);
139 DO_TEST("nat-network-dns-hosts", full
);
140 DO_TEST("nat-network-dns-forward-plain", full
);
141 DO_TEST("nat-network-dns-forwarders", full
);
142 DO_TEST("nat-network-dns-forwarder-no-resolv", full
);
143 DO_TEST("nat-network-dns-local-domain", full
);
144 DO_TEST("nat-network-mtu", dhcpv6
);
145 DO_TEST("dhcp6-network", dhcpv6
);
146 DO_TEST("dhcp6-nat-network", dhcpv6
);
147 DO_TEST("dhcp6host-routed-network", dhcpv6
);
148 DO_TEST("ptr-domains-auto", dhcpv6
);
149 DO_TEST("dnsmasq-options", dhcpv6
);
151 virObjectUnref(dhcpv6
);
152 virObjectUnref(full
);
153 virObjectUnref(restricted
);
155 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
158 VIR_TEST_MAIN(mymain
)