]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuxml2argvtest: Adapt to ethernet automatic tap creation
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 23 Mar 2016 15:19:26 +0000 (16:19 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Mar 2016 06:38:46 +0000 (07:38 +0100)
After 9c17d665fdc5 the tap device for ethernet network type is
automatically precreated before spawning qemu. Problem is, the
qemuxml2argvtest wasn't updated and thus is failing. Because of
all the APIs that new code is calling, I had to mock a lot. Also,
since the tap FDs are labeled separately from the rest of the
devices/files I had to enable NOP security driver for the test
too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
cfg.mk
tests/qemuhotplugtest.c
tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-timeout.args
tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.args
tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args
tests/qemuxml2argvdata/qemuxml2argv-net-eth.args
tests/qemuxml2argvmock.c
tests/testutilsqemu.c

diff --git a/cfg.mk b/cfg.mk
index 6f28eef29cfb01e52270ccc3b831ad5c05e80403..f5573dbd63e6a7a94a635294f7795435aa980430 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -1139,7 +1139,7 @@ exclude_file_name_regexp--sc_copyright_usage = \
   ^COPYING(|\.LESSER)$$
 
 exclude_file_name_regexp--sc_flags_usage = \
-  ^(docs/|src/util/virnetdevtap\.c$$|tests/(vir(cgroup|pci|usb)|nss)mock\.c$$)
+  ^(docs/|src/util/virnetdevtap\.c$$|tests/(vir(cgroup|pci|usb)|nss|qemuxml2argv)mock\.c$$)
 
 exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \
   ^(src/rpc/gendispatch\.pl$$|tests/)
index 2298a68ffe46bfca715133bca3304c4cf6c8d425..1eb2b6a881f25ceec0c8c6eb8240020f5f7c00c2 100644 (file)
@@ -341,7 +341,6 @@ mymain(void)
 {
     int ret = 0;
     struct qemuHotplugTestData data = {0};
-    virSecurityManagerPtr mgr;
 
 #if !WITH_YAJL
     fputs("libvirt not compiled with yajl, skipping this test\n", stderr);
@@ -369,12 +368,6 @@ mymain(void)
     if (!driver.lockManager)
         return EXIT_FAILURE;
 
-    if (!(mgr = virSecurityManagerNew("none", "qemu",
-                                      VIR_SECURITY_MANAGER_PRIVILEGED)))
-        return EXIT_FAILURE;
-    if (!(driver.securityManager = virSecurityManagerNewStack(mgr)))
-        return EXIT_FAILURE;
-
     /* wait only 100ms for DEVICE_DELETED event */
     qemuDomainRemoveDeviceWaitTime = 100;
 
index 7ca17ae10835669febcc1baabcc8f434006de854..8a29a7e9f65d07ea022b1fc8d22e73aeeeba0c24 100644 (file)
@@ -26,7 +26,7 @@ id=virtio-disk0 \
 media=cdrom,id=drive-ide0-1-0 \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 \
 -device rtl8139,vlan=0,id=net0,mac=52:54:00:71:70:89,bus=pci.0,addr=0x7 \
--net tap,script=/etc/qemu-ifup,vlan=0,name=hostnet0 \
+-net tap,fd=3,vlan=0,name=hostnet0 \
 -serial pty \
 -device usb-tablet,id=input0 \
 -spice port=5900 \
index 22d6dd0b72fc2d6f62a9080a3b439ec96ff7268d..b96c933ff1c7aaccfd4abb00378ca2c52cfe9ab9 100644 (file)
@@ -20,4 +20,4 @@ QEMU_AUDIO_DRV=none \
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
 -device rtl8139,vlan=0,id=net0,mac=00:11:22:33:44:55,bus=pci.0,addr=0x3 \
--net tap,ifname=nic02,script=/etc/qemu-ifup,vlan=0,name=hostnet0
+-net tap,fd=3,vlan=0,name=hostnet0
index 0704178e9314689f22013bc5cec0b1fea90fc32b..a2c3f87ba0034d4c2afe12fe3aaaaeb361cdfcf9 100644 (file)
@@ -20,7 +20,7 @@ QEMU_AUDIO_DRV=none \
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
 -device rtl8139,vlan=0,id=net0,mac=00:11:22:33:44:55,bus=pci.0,addr=0x3 \
--net tap,script=/etc/qemu-ifup,vlan=0,name=hostnet0 \
+-net tap,fd=3,vlan=0,name=hostnet0 \
 -device e1000,vlan=1,id=net1,mac=00:11:22:33:44:56,bus=pci.0,addr=0x4 \
--net tap,script=/etc/qemu-ifup,vlan=1,name=hostnet1 \
+-net tap,fd=3,vlan=1,name=hostnet1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
index b69cf52a3fc1e3bcd688b8b96478fe6b61134368..b96c933ff1c7aaccfd4abb00378ca2c52cfe9ab9 100644 (file)
@@ -20,4 +20,4 @@ QEMU_AUDIO_DRV=none \
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
 -device rtl8139,vlan=0,id=net0,mac=00:11:22:33:44:55,bus=pci.0,addr=0x3 \
--net tap,script=/etc/qemu-ifup,vlan=0,name=hostnet0
+-net tap,fd=3,vlan=0,name=hostnet0
index b7dfebba2995bea7da1a792bd45c42e2d15910ec..e2c19a647061de459bc74e971ac5cb6e2342944b 100644 (file)
 #include <config.h>
 
 #include "internal.h"
-#include "virnuma.h"
+#include "vircommand.h"
 #include "virmock.h"
-#include "virutil.h"
+#include "virnetdev.h"
+#include "virnetdevtap.h"
+#include "virnuma.h"
+#include "virscsi.h"
 #include "virstring.h"
 #include "virtpm.h"
-#include "virscsi.h"
+#include "virutil.h"
 #include <time.h>
 #include <unistd.h>
 
@@ -98,3 +101,43 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix ATTRIBUTE_UNUSED,
     ignore_value(VIR_STRDUP(ret, "sg0"));
     return ret;
 }
+
+int
+virNetDevTapCreate(char **ifname,
+                   const char *tunpath ATTRIBUTE_UNUSED,
+                   int *tapfd,
+                   size_t tapfdSize,
+                   unsigned int flags ATTRIBUTE_UNUSED)
+{
+    size_t i;
+
+    for (i = 0; i < tapfdSize; i++)
+        tapfd[i] = STDERR_FILENO + 1 + i;
+
+    return VIR_STRDUP(*ifname, "vnet0");
+}
+
+int
+virNetDevSetMAC(const char *ifname ATTRIBUTE_UNUSED,
+                const virMacAddr *macaddr ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
+
+int
+virCommandRun(virCommandPtr cmd ATTRIBUTE_UNUSED,
+              int *exitstatus)
+{
+    if (exitstatus)
+        *exitstatus = 0;
+
+    return 0;
+}
+
+void
+virCommandPassFD(virCommandPtr cmd ATTRIBUTE_UNUSED,
+                 int fd ATTRIBUTE_UNUSED,
+                 unsigned int flags ATTRIBUTE_UNUSED)
+{
+    /* nada */
+}
index 1f854f50b5ed917cadd98ed28ec9774baf66a760..eb4c6c86777b796a15ca6be4d8173d548e76586d 100644 (file)
@@ -555,6 +555,8 @@ int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, const char *binary,
 
 int qemuTestDriverInit(virQEMUDriver *driver)
 {
+    virSecurityManagerPtr mgr = NULL;
+
     memset(driver, 0, sizeof(*driver));
 
     if (virMutexInit(&driver->lock) < 0)
@@ -588,9 +590,16 @@ int qemuTestDriverInit(virQEMUDriver *driver)
     if (qemuTestCapsCacheInsert(driver->qemuCapsCache, "empty", NULL) < 0)
         goto error;
 
+    if (!(mgr = virSecurityManagerNew("none", "qemu",
+                                      VIR_SECURITY_MANAGER_PRIVILEGED)))
+        goto error;
+    if (!(driver->securityManager = virSecurityManagerNewStack(mgr)))
+        goto error;
+
     return 0;
 
  error:
+    virObjectUnref(mgr);
     qemuTestDriverFree(driver);
     return -1;
 }