]> xenbits.xensource.com Git - libvirt.git/commitdiff
Network: Add regression tests for the command-line arguments
authorMichal Novotny <minovotn@redhat.com>
Fri, 24 Jun 2011 10:04:37 +0000 (12:04 +0200)
committerLaine Stump <laine@laine.org>
Fri, 24 Jun 2011 20:15:27 +0000 (16:15 -0400)
The regression testing done by comparison of command-line
generated from the network XML file and the expected
command-line arguments (read from file).

Signed-off-by: Michal Novotny <minovotn@redhat.com>
14 files changed:
tests/Makefile.am
tests/networkxml2argvdata/isolated-network.argv [new file with mode: 0644]
tests/networkxml2argvdata/isolated-network.xml [new file with mode: 0644]
tests/networkxml2argvdata/nat-network-dns-txt-record.argv [new file with mode: 0644]
tests/networkxml2argvdata/nat-network-dns-txt-record.xml [new file with mode: 0644]
tests/networkxml2argvdata/nat-network.argv [new file with mode: 0644]
tests/networkxml2argvdata/nat-network.xml [new file with mode: 0644]
tests/networkxml2argvdata/netboot-network.argv [new file with mode: 0644]
tests/networkxml2argvdata/netboot-network.xml [new file with mode: 0644]
tests/networkxml2argvdata/netboot-proxy-network.argv [new file with mode: 0644]
tests/networkxml2argvdata/netboot-proxy-network.xml [new file with mode: 0644]
tests/networkxml2argvdata/routed-network.argv [new file with mode: 0644]
tests/networkxml2argvdata/routed-network.xml [new file with mode: 0644]
tests/networkxml2argvtest.c [new file with mode: 0644]

index 5e0b69f2bf17a77bf5dceeeec59aab21ffe95fb9..7db9d1f9d0806f98ad2c5cb615ecdcc5590ea946 100644 (file)
@@ -50,6 +50,7 @@ EXTRA_DIST =          \
        networkschematest \
        networkxml2xmlin \
        networkxml2xmlout \
+       networkxml2argvdata \
        nodedevschemadata \
        nodedevschematest \
        nodeinfodata     \
@@ -113,6 +114,8 @@ endif
 
 check_PROGRAMS += networkxml2xmltest
 
+check_PROGRAMS += networkxml2argvtest
+
 check_PROGRAMS += nwfilterxml2xmltest
 
 check_PROGRAMS += storagevolxml2xmltest storagepoolxml2xmltest
@@ -226,6 +229,8 @@ endif
 
 TESTS += networkxml2xmltest
 
+TESTS += networkxml2argvtest
+
 TESTS += storagevolxml2xmltest storagepoolxml2xmltest
 
 TESTS += nodedevxml2xmltest
@@ -353,6 +358,11 @@ networkxml2xmltest_SOURCES = \
        testutils.c testutils.h
 networkxml2xmltest_LDADD = $(LDADDS)
 
+networkxml2argvtest_SOURCES = \
+       networkxml2argvtest.c \
+       testutils.c testutils.h
+networkxml2argvtest_LDADD = ../src/libvirt_driver_network.la $(LDADDS)
+
 nwfilterxml2xmltest_SOURCES = \
        nwfilterxml2xmltest.c \
        testutils.c testutils.h
diff --git a/tests/networkxml2argvdata/isolated-network.argv b/tests/networkxml2argvdata/isolated-network.argv
new file mode 100644 (file)
index 0000000..e0993fb
--- /dev/null
@@ -0,0 +1 @@
+/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= --except-interface lo --dhcp-option=3 --listen-address 192.168.152.1 --dhcp-range 192.168.152.2,192.168.152.254 --dhcp-leasefile=/var/lib/libvirt/dnsmasq/private.leases --dhcp-lease-max=253 --dhcp-no-override
\ No newline at end of file
diff --git a/tests/networkxml2argvdata/isolated-network.xml b/tests/networkxml2argvdata/isolated-network.xml
new file mode 100644 (file)
index 0000000..cc320a9
--- /dev/null
@@ -0,0 +1,11 @@
+<network>
+  <name>private</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <bridge name='virbr2' stp='on' delay='0' />
+  <mac address='52:54:00:17:3F:37'/>
+  <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/networkxml2argvdata/nat-network-dns-txt-record.argv b/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
new file mode 100644 (file)
index 0000000..c000808
--- /dev/null
@@ -0,0 +1 @@
+/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= --except-interface lo --txt-record=example,example value --listen-address 192.168.122.1 --listen-address 192.168.123.1 --listen-address 2001:db8:ac10:fe01::1 --listen-address 2001:db8:ac10:fd01::1 --listen-address 10.24.10.1 --dhcp-range 192.168.122.2,192.168.122.254 --dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases --dhcp-lease-max=253 --dhcp-no-override
\ No newline at end of file
diff --git a/tests/networkxml2argvdata/nat-network-dns-txt-record.xml b/tests/networkxml2argvdata/nat-network-dns-txt-record.xml
new file mode 100644 (file)
index 0000000..bd16976
--- /dev/null
@@ -0,0 +1,24 @@
+<network>
+  <name>default</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <forward dev='eth1' mode='nat'/>
+  <bridge name='virbr0' stp='on' delay='0' />
+  <dns>
+    <txt name='example' value='example value' />
+  </dns>
+  <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>
+  <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+  </ip>
+  <ip family='ipv4' address='10.24.10.1'>
+  </ip>
+</network>
diff --git a/tests/networkxml2argvdata/nat-network.argv b/tests/networkxml2argvdata/nat-network.argv
new file mode 100644 (file)
index 0000000..d58672f
--- /dev/null
@@ -0,0 +1 @@
+/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= --except-interface lo --listen-address 192.168.122.1 --listen-address 192.168.123.1 --listen-address 2001:db8:ac10:fe01::1 --listen-address 2001:db8:ac10:fd01::1 --listen-address 10.24.10.1 --dhcp-range 192.168.122.2,192.168.122.254 --dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases --dhcp-lease-max=253 --dhcp-no-override
\ No newline at end of file
diff --git a/tests/networkxml2argvdata/nat-network.xml b/tests/networkxml2argvdata/nat-network.xml
new file mode 100644 (file)
index 0000000..eb71d9e
--- /dev/null
@@ -0,0 +1,21 @@
+<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>
+  <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+  </ip>
+  <ip family='ipv4' address='10.24.10.1'>
+  </ip>
+</network>
diff --git a/tests/networkxml2argvdata/netboot-network.argv b/tests/networkxml2argvdata/netboot-network.argv
new file mode 100644 (file)
index 0000000..c5db9e0
--- /dev/null
@@ -0,0 +1 @@
+/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com --conf-file= --except-interface lo --listen-address 192.168.122.1 --dhcp-range 192.168.122.2,192.168.122.254 --dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases --dhcp-lease-max=253 --dhcp-no-override --enable-tftp --tftp-root /var/lib/tftproot --dhcp-boot pxeboot.img
\ No newline at end of file
diff --git a/tests/networkxml2argvdata/netboot-network.xml b/tests/networkxml2argvdata/netboot-network.xml
new file mode 100644 (file)
index 0000000..b8a4d99
--- /dev/null
@@ -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>
diff --git a/tests/networkxml2argvdata/netboot-proxy-network.argv b/tests/networkxml2argvdata/netboot-proxy-network.argv
new file mode 100644 (file)
index 0000000..06e5b08
--- /dev/null
@@ -0,0 +1 @@
+/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com --conf-file= --except-interface lo --listen-address 192.168.122.1 --dhcp-range 192.168.122.2,192.168.122.254 --dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases --dhcp-lease-max=253 --dhcp-no-override --dhcp-boot pxeboot.img,,10.20.30.40
\ No newline at end of file
diff --git a/tests/networkxml2argvdata/netboot-proxy-network.xml b/tests/networkxml2argvdata/netboot-proxy-network.xml
new file mode 100644 (file)
index 0000000..e11c50b
--- /dev/null
@@ -0,0 +1,13 @@
+<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'>
+    <dhcp>
+      <range start='192.168.122.2' end='192.168.122.254' />
+      <bootp file='pxeboot.img' server='10.20.30.40' />
+    </dhcp>
+  </ip>
+</network>
diff --git a/tests/networkxml2argvdata/routed-network.argv b/tests/networkxml2argvdata/routed-network.argv
new file mode 100644 (file)
index 0000000..bf5f579
--- /dev/null
@@ -0,0 +1 @@
+/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= --except-interface lo --listen-address 192.168.122.1
\ No newline at end of file
diff --git a/tests/networkxml2argvdata/routed-network.xml b/tests/networkxml2argvdata/routed-network.xml
new file mode 100644 (file)
index 0000000..3aa8109
--- /dev/null
@@ -0,0 +1,9 @@
+<network>
+  <name>local</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <forward dev='eth1' mode='route'/>
+  <bridge name='virbr1' stp='on' delay='0' />
+  <mac address='12:34:56:78:9A:BC'/>
+  <ip address='192.168.122.1' netmask='255.255.255.0'>
+  </ip>
+</network>
diff --git a/tests/networkxml2argvtest.c b/tests/networkxml2argvtest.c
new file mode 100644 (file)
index 0000000..98c84ad
--- /dev/null
@@ -0,0 +1,108 @@
+#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 "command.h"
+#include "memory.h"
+#include "network/bridge_driver.h"
+
+static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
+    char *inXmlData = NULL;
+    char *outArgvData = NULL;
+    char *actual = NULL;
+    int ret = -1;
+    virNetworkDefPtr dev = NULL;
+    virNetworkObjPtr obj = NULL;
+    virCommandPtr cmd = NULL;
+    char *pidfile = NULL;
+
+    if (virtTestLoadFile(inxml, &inXmlData) < 0)
+        goto fail;
+
+    if (virtTestLoadFile(outargv, &outArgvData) < 0)
+        goto fail;
+
+    if (!(dev = virNetworkDefParseString(inXmlData)))
+        goto fail;
+
+    if (VIR_ALLOC(obj) < 0)
+        goto fail;
+
+    obj->def = dev;
+
+    if (networkBuildDhcpDaemonCommandLine(obj, &cmd, pidfile) < 0)
+        goto fail;
+
+    if (!(actual = virCommandToString(cmd)))
+        goto fail;
+
+    if (STRNEQ(outArgvData, actual)) {
+        virtTestDifference(stderr, outArgvData, actual);
+        goto fail;
+    }
+
+    ret = 0;
+
+ fail:
+    free(inXmlData);
+    free(outArgvData);
+    free(actual);
+    VIR_FREE(pidfile);
+    virCommandFree(cmd);
+    virNetworkObjFree(obj);
+    return ret;
+}
+
+static int
+testCompareXMLToArgvHelper(const void *data)
+{
+    int result = -1;
+    char *inxml = NULL;
+    char *outxml = NULL;
+
+    if (virAsprintf(&inxml, "%s/networkxml2argvdata/%s.xml",
+                    abs_srcdir, (const char*)data) < 0 ||
+        virAsprintf(&outxml, "%s/networkxml2argvdata/%s.argv",
+                    abs_srcdir, (const char*)data) < 0) {
+        goto cleanup;
+    }
+
+    result = testCompareXMLToArgvFiles(inxml, outxml);
+
+cleanup:
+    free(inxml);
+    free(outxml);
+
+    return result;
+}
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+#define DO_TEST(name) \
+    if (virtTestRun("Network XML-2-Argv " name, \
+                    1, testCompareXMLToArgvHelper, (name)) < 0) \
+        ret = -1
+
+    DO_TEST("isolated-network");
+    DO_TEST("routed-network");
+    DO_TEST("nat-network");
+    DO_TEST("netboot-network");
+    DO_TEST("netboot-proxy-network");
+    DO_TEST("nat-network-dns-txt-record");
+
+    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+VIRT_TEST_MAIN(mymain)