mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-23 11:52:20 +00:00
test: Generate net interface names when assigning XML.
We need interface names to implement InterfaceStats.
This commit is contained in:
parent
13f3d40cbf
commit
3b4a542c06
70
src/test.c
70
src/test.c
@ -228,6 +228,66 @@ static const unsigned long long defaultPoolAlloc = 0;
|
|||||||
|
|
||||||
static int testStoragePoolObjSetDefaults(virConnectPtr conn, virStoragePoolObjPtr pool);
|
static int testStoragePoolObjSetDefaults(virConnectPtr conn, virStoragePoolObjPtr pool);
|
||||||
|
|
||||||
|
static char *
|
||||||
|
testDomainGenerateIfname(virConnectPtr conn,
|
||||||
|
virDomainDefPtr domdef) {
|
||||||
|
int maxif = 1024;
|
||||||
|
int ifctr, i;
|
||||||
|
|
||||||
|
for (ifctr = 0; ifctr < maxif; ++ifctr) {
|
||||||
|
char *ifname;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
if (virAsprintf(&ifname, "testnet%d", ifctr) < 0) {
|
||||||
|
virReportOOMError(conn);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate network interface names */
|
||||||
|
for (i = 0 ; i < domdef->nnets ; i++) {
|
||||||
|
if (domdef->nets[i]->ifname &&
|
||||||
|
STREQ (domdef->nets[i]->ifname, ifname)) {
|
||||||
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
return ifname;
|
||||||
|
}
|
||||||
|
|
||||||
|
testError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Exceeded max iface limit %d"), maxif);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static virDomainObjPtr
|
||||||
|
testDomainAssignDef(virConnectPtr conn,
|
||||||
|
virDomainObjList *domlist,
|
||||||
|
virDomainDefPtr domdef)
|
||||||
|
{
|
||||||
|
virDomainObjPtr domobj = NULL;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < domdef->nnets; i++) {
|
||||||
|
char *ifname;
|
||||||
|
if (domdef->nets[i]->ifname)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ifname = testDomainGenerateIfname(conn, domdef);
|
||||||
|
if (!ifname)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
domdef->nets[i]->ifname = ifname;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(domobj = virDomainAssignDef(conn, domlist, domdef)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return domobj;
|
||||||
|
}
|
||||||
|
|
||||||
static int testOpenDefault(virConnectPtr conn) {
|
static int testOpenDefault(virConnectPtr conn) {
|
||||||
int u;
|
int u;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@ -282,7 +342,7 @@ static int testOpenDefault(virConnectPtr conn) {
|
|||||||
defaultDomainXML,
|
defaultDomainXML,
|
||||||
VIR_DOMAIN_XML_INACTIVE)))
|
VIR_DOMAIN_XML_INACTIVE)))
|
||||||
goto error;
|
goto error;
|
||||||
if (!(domobj = virDomainAssignDef(conn, &privconn->domains, domdef))) {
|
if (!(domobj = testDomainAssignDef(conn, &privconn->domains, domdef))) {
|
||||||
virDomainDefFree(domdef);
|
virDomainDefFree(domdef);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -608,7 +668,7 @@ static int testOpenFromFile(virConnectPtr conn,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(dom = virDomainAssignDef(conn, &privconn->domains, def))) {
|
if (!(dom = testDomainAssignDef(conn, &privconn->domains, def))) {
|
||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -920,7 +980,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml,
|
|||||||
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((dom = virDomainAssignDef(conn, &privconn->domains,
|
if ((dom = testDomainAssignDef(conn, &privconn->domains,
|
||||||
def)) == NULL) {
|
def)) == NULL) {
|
||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1471,7 +1531,7 @@ static int testDomainRestore(virConnectPtr conn,
|
|||||||
if (!def)
|
if (!def)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((dom = virDomainAssignDef(conn, &privconn->domains,
|
if ((dom = testDomainAssignDef(conn, &privconn->domains,
|
||||||
def)) == NULL)
|
def)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -1763,7 +1823,7 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn,
|
|||||||
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((dom = virDomainAssignDef(conn, &privconn->domains,
|
if ((dom = testDomainAssignDef(conn, &privconn->domains,
|
||||||
def)) == NULL) {
|
def)) == NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user