On 12/15/23 13:33, Peter Krempa wrote: > In order to be able to use '<interface type="network"' we need a fake > network driver in qemuxml2argvtest. Create one by simply allowing users > to reuse configs from tests/networkxml2xmlin and tests/virnetworkportxml2xmldata > which will be returned to corresponding functions. > > The driver implements: > > .networkLookupByName = fakeNetworkLookupByName, > - validate syntax of network name, check if config exists > .networkGetXMLDesc = fakeNetworkGetXMLDesc, > - return appropriate XML > .networkPortCreateXML = fakeNetworkPortCreateXML, > - validate that port XML exists > .networkPortGetXMLDesc = fakeNetworkPortGetXMLDesc, > - return appropriate port XML > > With the above and the correspondign test data, all network XMLs can be > enabled. > > Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> > --- > tests/qemuxml2argvtest.c | 98 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 98 insertions(+) > > diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c > index 13d279b301..7197fd35db 100644 > --- a/tests/qemuxml2argvtest.c > +++ b/tests/qemuxml2argvtest.c > @@ -257,6 +257,103 @@ static virNWFilterDriver fakeNWFilterDriver = { > }; > > > +/* name of the fake network shall be constructed as: > + * NETWORKXMLNAME;NETWORKPORTXMLNAME > + * where: > + * NETWORKXMLNAME resolves to abs_srcdir/networkxml2xmlin/NETWORKXMLNAME.xml > + * NETWORKPORTXMLNAME resolves to abs_srcdir/virnetworkportxml2xmldata/NETWORKPORTXMLNAME.xml > + */ > +static virNetworkPtr > +fakeNetworkLookupByName(virConnectPtr conn, > + const char *name) > +{ > + unsigned char uuid[VIR_UUID_BUFLEN]; > + g_autofree char *netname = g_strdup(name); > + g_autofree char *path = NULL; > + char *tmp; > + > + memset(uuid, 0, VIR_UUID_BUFLEN); > + > + if ((tmp = strchr(netname, ';'))) { > + *tmp = '\0'; > + } else { > + virReportError(VIR_ERR_NO_NETWORK, "Malformed fake network name '%s'. See fakeNetworkLookupByName.", name); Long line. > + return NULL; > + } > + > + path = g_strdup_printf(abs_srcdir "/networkxml2xmlin/%s.xml", netname); > + > + if (!virFileExists(path)) { > + virReportError(VIR_ERR_NO_NETWORK, "fake network '%s' not found", path); > + return NULL; > + } > + > + return virGetNetwork(conn, name, uuid); > +} Michal _______________________________________________ Devel mailing list -- devel@xxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx