tests: mock qemuInterfaceOpenVhostNet

This functions contains logic that tries to use vhost for virtio
interfaces, even if <driver name='vhost'/> was not supplied.
In this case, a failure is non-fatal.

On my system, /dev/vhost-net was not accessible to the user running
'make check', but we should not depend on that.

Mock it to prevent accessing /dev/vhost-net and return some predictable
file descriptor numbers instead.

Introduced by commit c1f684e - deprecate QEMU_CAPS_VHOST_NET.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reported-by: Jiří Denemark <jdenemar@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Ján Tomko 2018-04-17 12:11:17 +02:00
parent 374777ee74
commit 31413101a8
2 changed files with 20 additions and 1 deletions

View File

@ -51,7 +51,7 @@ id=ua-myEncryptedDisk1 \
if=none,id=drive-ua-WhatAnAwesomeCDROM,media=cdrom,readonly=on,cache=none \
-device ide-drive,bus=ide.1,unit=0,drive=drive-ua-WhatAnAwesomeCDROM,\
id=ua-WhatAnAwesomeCDROM \
-netdev tap,fd=3,id=hostua-CheckoutThisNIC \
-netdev tap,fd=3,id=hostua-CheckoutThisNIC,vhost=on,vhostfd=44 \
-device virtio-net-pci,netdev=hostua-CheckoutThisNIC,id=ua-CheckoutThisNIC,\
mac=52:54:00:d6:c0:0b,bus=pci.0,addr=0x3 \
-netdev socket,listen=127.0.0.1:1234,id=hostua-WeCanAlsoDoServerMode \

View File

@ -36,6 +36,7 @@
#include "virstring.h"
#include "virtpm.h"
#include "virutil.h"
#include "qemu/qemu_interface.h"
#include <time.h>
#include <unistd.h>
@ -188,3 +189,21 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path ATTRIBUTE_UNUSED,
{
return VIR_STRDUP(*ifname, "vhost-user0");
}
int
qemuInterfaceOpenVhostNet(virDomainDefPtr def ATTRIBUTE_UNUSED,
virDomainNetDefPtr net,
int *vhostfd,
size_t *vhostfdSize)
{
size_t i;
if (!(net->model && STREQ(net->model, "virtio"))) {
*vhostfdSize = 0;
return 0;
}
for (i = 0; i < *vhostfdSize; i++)
vhostfd[i] = STDERR_FILENO + 42 + i;
return 0;
}