mirror of https://gitee.com/openkylin/libvirt.git
tests: Add network XML to XML tests.
This commit is contained in:
parent
4027461865
commit
6d8331fd58
|
@ -13,6 +13,7 @@ qemuxml2xmltest
|
||||||
qemuxml2argvtest
|
qemuxml2argvtest
|
||||||
qemuargv2xmltest
|
qemuargv2xmltest
|
||||||
qemuhelptest
|
qemuhelptest
|
||||||
|
networkxml2xmltest
|
||||||
nodedevxml2xmltest
|
nodedevxml2xmltest
|
||||||
interfacexml2xmltest
|
interfacexml2xmltest
|
||||||
storagepoolxml2xmltest
|
storagepoolxml2xmltest
|
||||||
|
|
|
@ -56,7 +56,8 @@ EXTRA_DIST = \
|
||||||
capabilityschematest \
|
capabilityschematest \
|
||||||
capabilityschemadata \
|
capabilityschemadata \
|
||||||
networkschematest \
|
networkschematest \
|
||||||
networkschemadata \
|
networkpoolxml2xmlout \
|
||||||
|
networkpoolxml2xmlin \
|
||||||
domainschematest \
|
domainschematest \
|
||||||
domainschemadata \
|
domainschemadata \
|
||||||
interfaceschemadata \
|
interfaceschemadata \
|
||||||
|
@ -96,6 +97,8 @@ if WITH_CIL
|
||||||
noinst_PROGRAMS += object-locking
|
noinst_PROGRAMS += object-locking
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
noinst_PROGRAMS += networkxml2xmltest
|
||||||
|
|
||||||
noinst_PROGRAMS += storagepoolxml2xmltest
|
noinst_PROGRAMS += storagepoolxml2xmltest
|
||||||
|
|
||||||
noinst_PROGRAMS += nodedevxml2xmltest
|
noinst_PROGRAMS += nodedevxml2xmltest
|
||||||
|
@ -171,6 +174,8 @@ noinst_PROGRAMS += eventtest
|
||||||
TESTS += eventtest
|
TESTS += eventtest
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
TESTS += networkxml2xmltest
|
||||||
|
|
||||||
TESTS += storagepoolxml2xmltest
|
TESTS += storagepoolxml2xmltest
|
||||||
|
|
||||||
TESTS += nodedevxml2xmltest
|
TESTS += nodedevxml2xmltest
|
||||||
|
@ -269,6 +274,11 @@ else
|
||||||
EXTRA_DIST += esxutilstest.c vmx2xmltest.c xml2vmxtest.c
|
EXTRA_DIST += esxutilstest.c vmx2xmltest.c xml2vmxtest.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
networkxml2xmltest_SOURCES = \
|
||||||
|
networkxml2xmltest.c \
|
||||||
|
testutils.c testutils.h
|
||||||
|
networkxml2xmltest_LDADD = $(LDADDS)
|
||||||
|
|
||||||
storagepoolxml2xmltest_SOURCES = \
|
storagepoolxml2xmltest_SOURCES = \
|
||||||
storagepoolxml2xmltest.c \
|
storagepoolxml2xmltest.c \
|
||||||
testutils.c testutils.h
|
testutils.c testutils.h
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
source ./schematestutils.sh
|
source ./schematestutils.sh
|
||||||
|
|
||||||
DIRS="../src/network networkschemadata"
|
DIRS="../src/network networkxml2xmlin networkxml2xmlout"
|
||||||
SCHEMA="network.rng"
|
SCHEMA="network.rng"
|
||||||
|
|
||||||
check_schema "$DIRS" "$SCHEMA"
|
check_schema "$DIRS" "$SCHEMA"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<network>
|
||||||
|
<name>private</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<bridge name="virbr2" />
|
||||||
|
<ip address="192.168.152.1" netmask="255.255.255.0">
|
||||||
|
<dhcp>
|
||||||
|
<range start="192.168.152.2" end="192.168.152.254" />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<network>
|
||||||
|
<name>default</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<bridge name="virbr0" />
|
||||||
|
<forward mode="nat" dev="eth1"/>
|
||||||
|
<ip address="192.168.122.1" netmask="255.255.255.0">
|
||||||
|
<dhcp>
|
||||||
|
<range start="192.168.122.2" end="192.168.122.254" />
|
||||||
|
<host mac="00:16:3e:77:e2:ed" name="a.example.com" ip="192.168.122.10" />
|
||||||
|
<host mac="00:16:3e:3e:a9:1a" name="b.example.com" ip="192.168.122.11" />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
|
@ -1,6 +1,8 @@
|
||||||
<network>
|
<network>
|
||||||
<name>netboot</name>
|
<name>netboot</name>
|
||||||
<bridge name="virbr1" />
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<bridge name="virbr1" stp='off' delay='1'/>
|
||||||
|
<domain name="example.com"/>
|
||||||
<forward/>
|
<forward/>
|
||||||
<ip address="192.168.122.1" netmask="255.255.255.0">
|
<ip address="192.168.122.1" netmask="255.255.255.0">
|
||||||
<tftp root="/var/lib/tftproot" />
|
<tftp root="/var/lib/tftproot" />
|
|
@ -0,0 +1,11 @@
|
||||||
|
<network>
|
||||||
|
<name>local</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<bridge name="virbr1" />
|
||||||
|
<forward mode="route" dev="eth1"/>
|
||||||
|
<ip address="192.168.122.1" netmask="255.255.255.0">
|
||||||
|
<dhcp>
|
||||||
|
<range start="192.168.122.2" end="192.168.122.254" />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<network>
|
||||||
|
<name>private</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<bridge name='virbr2' stp='on' delay='0' />
|
||||||
|
<ip address='192.168.152.1' netmask='255.255.255.0'>
|
||||||
|
<dhcp>
|
||||||
|
<range start='192.168.152.2' end='192.168.152.254' />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<network>
|
||||||
|
<name>default</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<forward dev='eth1' mode='nat'/>
|
||||||
|
<bridge name='virbr0' stp='on' delay='0' />
|
||||||
|
<ip address='192.168.122.1' netmask='255.255.255.0'>
|
||||||
|
<dhcp>
|
||||||
|
<range start='192.168.122.2' end='192.168.122.254' />
|
||||||
|
<host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10' />
|
||||||
|
<host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11' />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<network>
|
||||||
|
<name>netboot</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<forward mode='nat'/>
|
||||||
|
<bridge name='virbr1' stp='off' delay='1' />
|
||||||
|
<domain name='example.com'/>
|
||||||
|
<ip address='192.168.122.1' netmask='255.255.255.0'>
|
||||||
|
<tftp root='/var/lib/tftproot' />
|
||||||
|
<dhcp>
|
||||||
|
<range start='192.168.122.2' end='192.168.122.254' />
|
||||||
|
<bootp file='pxeboot.img' />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<network>
|
||||||
|
<name>local</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<forward dev='eth1' mode='route'/>
|
||||||
|
<bridge name='virbr1' stp='on' delay='0' />
|
||||||
|
<ip address='192.168.122.1' netmask='255.255.255.0'>
|
||||||
|
<dhcp>
|
||||||
|
<range start='192.168.122.2' end='192.168.122.254' />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
|
@ -0,0 +1,96 @@
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "internal.h"
|
||||||
|
#include "testutils.h"
|
||||||
|
#include "network_conf.h"
|
||||||
|
#include "testutilsqemu.h"
|
||||||
|
|
||||||
|
static char *progname;
|
||||||
|
static char *abs_srcdir;
|
||||||
|
|
||||||
|
#define MAX_FILE 4096
|
||||||
|
|
||||||
|
|
||||||
|
static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
|
||||||
|
char inXmlData[MAX_FILE];
|
||||||
|
char *inXmlPtr = &(inXmlData[0]);
|
||||||
|
char outXmlData[MAX_FILE];
|
||||||
|
char *outXmlPtr = &(outXmlData[0]);
|
||||||
|
char *actual = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
virNetworkDefPtr dev = NULL;
|
||||||
|
|
||||||
|
if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
|
||||||
|
goto fail;
|
||||||
|
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (!(dev = virNetworkDefParseString(NULL, inXmlData)))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (!(actual = virNetworkDefFormat(NULL, dev)))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (STRNEQ(outXmlData, actual)) {
|
||||||
|
virtTestDifference(stderr, outXmlData, actual);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
free(actual);
|
||||||
|
virNetworkDefFree(dev);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareXMLToXMLHelper(const void *data) {
|
||||||
|
char inxml[PATH_MAX];
|
||||||
|
char outxml[PATH_MAX];
|
||||||
|
snprintf(inxml, PATH_MAX, "%s/networkxml2xmlin/%s.xml",
|
||||||
|
abs_srcdir, (const char*)data);
|
||||||
|
snprintf(outxml, PATH_MAX, "%s/networkxml2xmlout/%s.xml",
|
||||||
|
abs_srcdir, (const char*)data);
|
||||||
|
return testCompareXMLToXMLFiles(inxml, outxml);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
mymain(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
char cwd[PATH_MAX];
|
||||||
|
|
||||||
|
progname = argv[0];
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
fprintf(stderr, "Usage: %s\n", progname);
|
||||||
|
return (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
abs_srcdir = getenv("abs_srcdir");
|
||||||
|
if (!abs_srcdir)
|
||||||
|
abs_srcdir = getcwd(cwd, sizeof(cwd));
|
||||||
|
|
||||||
|
#define DO_TEST(name) \
|
||||||
|
if (virtTestRun("Network XML-2-XML " name, \
|
||||||
|
1, testCompareXMLToXMLHelper, (name)) < 0) \
|
||||||
|
ret = -1
|
||||||
|
|
||||||
|
DO_TEST("isolated-network");
|
||||||
|
DO_TEST("routed-network");
|
||||||
|
DO_TEST("nat-network");
|
||||||
|
DO_TEST("netboot-network");
|
||||||
|
|
||||||
|
return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
VIRT_TEST_MAIN(mymain)
|
Loading…
Reference in New Issue