Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
tests/.gitignore | 1 +
tests/Makefile.am | 12 +++-
tests/networkschemadata/netboot-network.xml | 12 ---
tests/networkschematest | 3 +-
tests/networkxml2xmlin/forward-delay-network.xml | 13 +++
tests/networkxml2xmlin/isolated-network.xml | 10 ++
tests/networkxml2xmlin/nat-network.xml | 13 +++
tests/networkxml2xmlin/netboot-network.xml | 14 +++
tests/networkxml2xmlin/routed-network.xml | 11 +++
tests/networkxml2xmlout/forward-delay-network.xml | 13 +++
tests/networkxml2xmlout/isolated-network.xml | 10 ++
tests/networkxml2xmlout/nat-network.xml | 13 +++
tests/networkxml2xmlout/netboot-network.xml | 14 +++
tests/networkxml2xmlout/routed-network.xml | 11 +++
tests/networkxml2xmltest.c | 97 +++++++++++++++++++++
15 files changed, 232 insertions(+), 15 deletions(-)
delete mode 100644 tests/networkschemadata/netboot-network.xml
create mode 100644 tests/networkxml2xmlin/forward-delay-network.xml
create mode 100644 tests/networkxml2xmlin/isolated-network.xml
create mode 100644 tests/networkxml2xmlin/nat-network.xml
create mode 100644 tests/networkxml2xmlin/netboot-network.xml
create mode 100644 tests/networkxml2xmlin/routed-network.xml
create mode 100644 tests/networkxml2xmlout/forward-delay-network.xml
create mode 100644 tests/networkxml2xmlout/isolated-network.xml
create mode 100644 tests/networkxml2xmlout/nat-network.xml
create mode 100644 tests/networkxml2xmlout/netboot-network.xml
create mode 100644 tests/networkxml2xmlout/routed-network.xml
create mode 100644 tests/networkxml2xmltest.c
diff --git a/tests/.gitignore b/tests/.gitignore
index 41f8454..c202141 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -13,6 +13,7 @@ qemuxml2xmltest
qemuxml2argvtest
qemuargv2xmltest
qemuhelptest
+networkxml2xmltest
nodedevxml2xmltest
interfacexml2xmltest
storagepoolxml2xmltest
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a62c01b..b6acfa4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -56,7 +56,8 @@ EXTRA_DIST = \
capabilityschematest \
capabilityschemadata \
networkschematest \
- networkschemadata \
+ networkpoolxml2xmlout \
+ networkpoolxml2xmlin \
domainschematest \
domainschemadata \
interfaceschemadata \
@@ -96,6 +97,8 @@ if WITH_CIL
noinst_PROGRAMS += object-locking
endif
+noinst_PROGRAMS += networkxml2xmltest
+
noinst_PROGRAMS += storagepoolxml2xmltest
noinst_PROGRAMS += nodedevxml2xmltest
@@ -171,6 +174,8 @@ noinst_PROGRAMS += eventtest
TESTS += eventtest
endif
+TESTS += networkxml2xmltest
+
TESTS += storagepoolxml2xmltest
TESTS += nodedevxml2xmltest
@@ -269,6 +274,11 @@ else
EXTRA_DIST += esxutilstest.c vmx2xmltest.c xml2vmxtest.c
endif
+networkxml2xmltest_SOURCES = \
+ networkxml2xmltest.c \
+ testutils.c testutils.h
+networkxml2xmltest_LDADD = $(LDADDS)
+
storagepoolxml2xmltest_SOURCES = \
storagepoolxml2xmltest.c \
testutils.c testutils.h
diff --git a/tests/networkschemadata/netboot-network.xml
b/tests/networkschemadata/netboot-network.xml
deleted file mode 100644
index 7274ee6..0000000
--- a/tests/networkschemadata/netboot-network.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<network>
- <name>netboot</name>
- <bridge name="virbr1" />
- <forward/>
- <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>
diff --git a/tests/networkschematest b/tests/networkschematest
index 8bb24cd..6305576 100755
--- a/tests/networkschematest
+++ b/tests/networkschematest
@@ -2,8 +2,7 @@
source ./schematestutils.sh
-DIRS="../src/network networkschemadata"
+DIRS="../src/network networkxml2xmlin networkxml2xmlout"
SCHEMA="network.rng"
check_schema "$DIRS" "$SCHEMA"
-
diff --git a/tests/networkxml2xmlin/forward-delay-network.xml
b/tests/networkxml2xmlin/forward-delay-network.xml
new file mode 100644
index 0000000..d97e185
--- /dev/null
+++ b/tests/networkxml2xmlin/forward-delay-network.xml
@@ -0,0 +1,13 @@
+<network>
+ <name>default</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <bridge name="virbr0" forwardDelay='2'/>
+ <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>
diff --git a/tests/networkxml2xmlin/isolated-network.xml
b/tests/networkxml2xmlin/isolated-network.xml
new file mode 100644
index 0000000..507e3bb
--- /dev/null
+++ b/tests/networkxml2xmlin/isolated-network.xml
@@ -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>
diff --git a/tests/networkxml2xmlin/nat-network.xml
b/tests/networkxml2xmlin/nat-network.xml
new file mode 100644
index 0000000..93ab186
--- /dev/null
+++ b/tests/networkxml2xmlin/nat-network.xml
@@ -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>
diff --git a/tests/networkxml2xmlin/netboot-network.xml
b/tests/networkxml2xmlin/netboot-network.xml
new file mode 100644
index 0000000..ed75663
--- /dev/null
+++ b/tests/networkxml2xmlin/netboot-network.xml
@@ -0,0 +1,14 @@
+<network>
+ <name>netboot</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <bridge name="virbr1" stp='off' delay='1'/>
+ <domain name="example.com"/>
+ <forward/>
+ <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>
diff --git a/tests/networkxml2xmlin/routed-network.xml
b/tests/networkxml2xmlin/routed-network.xml
new file mode 100644
index 0000000..824ad75
--- /dev/null
+++ b/tests/networkxml2xmlin/routed-network.xml
@@ -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>
diff --git a/tests/networkxml2xmlout/forward-delay-network.xml
b/tests/networkxml2xmlout/forward-delay-network.xml
new file mode 100644
index 0000000..54c62c4
--- /dev/null
+++ b/tests/networkxml2xmlout/forward-delay-network.xml
@@ -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' forwardDelay='2' />
+ <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>
diff --git a/tests/networkxml2xmlout/isolated-network.xml
b/tests/networkxml2xmlout/isolated-network.xml
new file mode 100644
index 0000000..b21ead0
--- /dev/null
+++ b/tests/networkxml2xmlout/isolated-network.xml
@@ -0,0 +1,10 @@
+<network>
+ <name>private</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <bridge name='virbr2' stp='on' forwardDelay='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>
diff --git a/tests/networkxml2xmlout/nat-network.xml
b/tests/networkxml2xmlout/nat-network.xml
new file mode 100644
index 0000000..35914d2
--- /dev/null
+++ b/tests/networkxml2xmlout/nat-network.xml
@@ -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' forwardDelay='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>
diff --git a/tests/networkxml2xmlout/netboot-network.xml
b/tests/networkxml2xmlout/netboot-network.xml
new file mode 100644
index 0000000..773cb86
--- /dev/null
+++ b/tests/networkxml2xmlout/netboot-network.xml
@@ -0,0 +1,14 @@
+<network>
+ <name>netboot</name>
+ <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+ <forward mode='nat'/>
+ <bridge name='virbr1' stp='off' forwardDelay='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>
diff --git a/tests/networkxml2xmlout/routed-network.xml
b/tests/networkxml2xmlout/routed-network.xml
new file mode 100644
index 0000000..e9b873e
--- /dev/null
+++ b/tests/networkxml2xmlout/routed-network.xml
@@ -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' forwardDelay='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>
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
new file mode 100644
index 0000000..569809d
--- /dev/null
+++ b/tests/networkxml2xmltest.c
@@ -0,0 +1,97 @@
+#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");
+ DO_TEST("forward-delay-network");
+
+ return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+VIRT_TEST_MAIN(mymain)
--
1.6.5.rc2