[libvirt] [PATCH v3] libxl: Add a test suite for libxl_domain_config generator
by Marek Marczykowski-Górecki
From: Jim Fehlig <jfehlig(a)suse.com>
The libxl library allows a libxl_domain_config object to be serialized
from/to a JSON string. Use this to allow testing of the XML to
libxl_domain_config conversion process. Test XML is converted to
libxl_domain_config, which is then serialized to json. A json template
corresponding to the test XML is converted to a libxl_domain_config
object using libxl_domain_config_from_json(), and then serialized
back to json using libxl_domain_config_to_json(). The two json
docs are then compared.
Using libxl to convert the json template to a libxl_domain_config
object and then back to json provides a simple way to account for
any changes or additions to the json representation across Xen
releases.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
[update to v3.5.0-rc1, improve error reporting, use /bin/true emulator]
Signed-off-by: Marek Marczykowski-Górecki <marmarek(a)invisiblethingslab.com>
---
m4/virt-driver-libxl.m4 | 6 +-
tests/Makefile.am | 18 +-
tests/libxlxml2domconfigdata/basic-hvm.json | 89 ++++++++-
tests/libxlxml2domconfigdata/basic-hvm.xml | 36 +++-
tests/libxlxml2domconfigdata/basic-pv.json | 65 ++++++-
tests/libxlxml2domconfigdata/basic-pv.xml | 28 ++-
tests/libxlxml2domconfigdata/moredevs-hvm.json | 111 ++++++++++-
tests/libxlxml2domconfigdata/moredevs-hvm.xml | 63 ++++++-
tests/libxlxml2domconfigtest.c | 205 ++++++++++++++++++-
tests/virmocklibxl.c | 87 ++++++++-
10 files changed, 705 insertions(+), 3 deletions(-)
create mode 100644 tests/libxlxml2domconfigdata/basic-hvm.json
create mode 100644 tests/libxlxml2domconfigdata/basic-hvm.xml
create mode 100644 tests/libxlxml2domconfigdata/basic-pv.json
create mode 100644 tests/libxlxml2domconfigdata/basic-pv.xml
create mode 100644 tests/libxlxml2domconfigdata/moredevs-hvm.json
create mode 100644 tests/libxlxml2domconfigdata/moredevs-hvm.xml
create mode 100644 tests/libxlxml2domconfigtest.c
create mode 100644 tests/virmocklibxl.c
diff --git a/m4/virt-driver-libxl.m4 b/m4/virt-driver-libxl.m4
index 96a9d47..3d635f0 100644
--- a/m4/virt-driver-libxl.m4
+++ b/m4/virt-driver-libxl.m4
@@ -35,7 +35,7 @@ AC_DEFUN([LIBVIRT_DRIVER_CHECK_LIBXL], [
if test "x$with_libxl" = "xyes" ; then
LIBXL_FIRMWARE_DIR=$($PKG_CONFIG --variable xenfirmwaredir xenlight)
LIBXL_EXECBIN_DIR=$($PKG_CONFIG --variable libexec_bin xenlight)
- fi
+ fi
dnl pkgconfig file not found, fallback to lib probe
if test "x$with_libxl" = "xno" ; then
@@ -80,6 +80,10 @@ AC_DEFUN([LIBVIRT_DRIVER_CHECK_LIBXL], [
LIBXL_LIBS="$LIBXL_LIBS -lxenctrl"
])
+ dnl Check if libxl_domain_config_from_json is available for domXML to
+ dnl libxl_domain_config tests
+ LIBS="$LIBS -lxenlight -lxenctrl"
+ AC_CHECK_FUNCS([libxl_domain_config_from_json])
CFLAGS="$old_CFLAGS"
LIBS="$old_LIBS"
fi
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3e3d580..49b9d40 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -99,6 +99,7 @@ EXTRA_DIST = \
genericxml2xmlindata \
genericxml2xmloutdata \
interfaceschemadata \
+ libxlxml2domconfigdata \
lxcconf2xmldata \
lxcxml2xmldata \
lxcxml2xmloutdata \
@@ -271,7 +272,8 @@ test_programs += xml2sexprtest sexpr2xmltest \
endif WITH_XEN
if WITH_LIBXL
-test_programs += xlconfigtest
+test_programs += xlconfigtest libxlxml2domconfigtest
+test_libraries += virmocklibxl.la
endif WITH_LIBXL
if WITH_QEMU
@@ -528,8 +530,20 @@ xlconfigtest_SOURCES = \
xlconfigtest.c testutilsxen.c testutilsxen.h \
testutils.c testutils.h
xlconfigtest_LDADD =$(libxl_LDADDS)
+
+libxlxml2domconfigtest_SOURCES = \
+ libxlxml2domconfigtest.c testutilsxen.c testutilsxen.h \
+ testutils.c testutils.h
+libxlxml2domconfigtest_LDADD = $(libxl_LDADDS) $(LIBXML_LIBS)
+
+virmocklibxl_la_SOURCES = \
+ virmocklibxl.c
+virmocklibxl_la_CFLAGS = $(AM_CFLAGS)
+virmocklibxl_la_LDFLAGS = -module -avoid-version \
+ -rpath /evil/libtool/hack/to/force/shared/lib/creation
+
else ! WITH_LIBXL
-EXTRA_DIST += xlconfigtest.c
+EXTRA_DIST += xlconfigtest.c libxlxml2domconfigtest.c
endif ! WITH_LIBXL
QEMUMONITORTESTUTILS_SOURCES = \
diff --git a/tests/libxlxml2domconfigdata/basic-hvm.json b/tests/libxlxml2domconfigdata/basic-hvm.json
new file mode 100644
index 0000000..6fa41f3
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/basic-hvm.json
@@ -0,0 +1,89 @@
+{
+ "c_info": {
+ "type": "hvm",
+ "name": "test-hvm",
+ "uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b"
+ },
+ "b_info": {
+ "max_vcpus": 4,
+ "avail_vcpus": [
+ 0,
+ 1,
+ 2,
+ 3
+ ],
+ "max_memkb": 1048576,
+ "target_memkb": 1048576,
+ "video_memkb": 8192,
+ "shadow_memkb": 12288,
+ "device_model_version": "qemu_xen",
+ "device_model": "/bin/true",
+ "sched_params": {
+ "weight": 1000
+ },
+ "type.hvm": {
+ "pae": "True",
+ "apic": "True",
+ "acpi": "True",
+ "vga": {
+ "kind": "cirrus"
+ },
+ "vnc": {
+ "enable": "True",
+ "listen": "0.0.0.0",
+ "findunused": "False"
+ },
+ "sdl": {
+ "enable": "False"
+ },
+ "spice": {
+
+ },
+ "boot": "c",
+ "rdm": {
+
+ }
+ },
+ "arch_arm": {
+
+ }
+ },
+ "disks": [
+ {
+ "pdev_path": "/var/lib/xen/images/test-hvm.img",
+ "vdev": "hda",
+ "backend": "qdisk",
+ "format": "raw",
+ "removable": 1,
+ "readwrite": 1
+ }
+ ],
+ "nics": [
+ {
+ "devid": 0,
+ "mac": "00:16:3e:66:12:b4",
+ "bridge": "br0",
+ "script": "/etc/xen/scripts/vif-bridge",
+ "nictype": "vif_ioemu"
+ }
+ ],
+ "vfbs": [
+ {
+ "devid": -1,
+ "vnc": {
+ "enable": "True",
+ "listen": "0.0.0.0",
+ "findunused": "False"
+ },
+ "sdl": {
+ "enable": "False"
+ }
+ }
+ ],
+ "vkbs": [
+ {
+ "devid": -1
+ }
+ ],
+ "on_reboot": "restart"
+}
diff --git a/tests/libxlxml2domconfigdata/basic-hvm.xml b/tests/libxlxml2domconfigdata/basic-hvm.xml
new file mode 100644
index 0000000..d8cd2a2
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/basic-hvm.xml
@@ -0,0 +1,36 @@
+<domain type='xen'>
+ <name>test-hvm</name>
+ <description>None</description>
+ <uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
+ <memory>1048576</memory>
+ <currentMemory>1048576</currentMemory>
+ <vcpu>4</vcpu>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <clock sync='utc'/>
+ <os>
+ <type>hvm</type>
+ <loader>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <apic/>
+ <acpi/>
+ <pae/>
+ </features>
+ <devices>
+ <emulator>/bin/true</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu'/>
+ <source file='/var/lib/xen/images/test-hvm.img'/>
+ <target dev='hda'/>
+ </disk>
+ <interface type='bridge'>
+ <source bridge='br0'/>
+ <mac address='00:16:3e:66:12:b4'/>
+ <script path='/etc/xen/scripts/vif-bridge'/>
+ </interface>
+ <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
+ </devices>
+</domain>
diff --git a/tests/libxlxml2domconfigdata/basic-pv.json b/tests/libxlxml2domconfigdata/basic-pv.json
new file mode 100644
index 0000000..7e1abd3
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/basic-pv.json
@@ -0,0 +1,65 @@
+{
+ "c_info": {
+ "type": "pv",
+ "name": "test-pv",
+ "uuid": "039e9ee6-4a84-3055-4c81-8ba426ae2656"
+ },
+ "b_info": {
+ "max_vcpus": 4,
+ "avail_vcpus": [
+ 0,
+ 1,
+ 2,
+ 3
+ ],
+ "max_memkb": 524288,
+ "target_memkb": 524288,
+ "sched_params": {
+ "weight": 1000
+ },
+ "type.pv": {
+ "bootloader": "pygrub"
+ },
+ "arch_arm": {
+
+ }
+ },
+ "disks": [
+ {
+ "pdev_path": "/var/lib/xen/images/test-pv.img",
+ "vdev": "xvda",
+ "backend": "qdisk",
+ "format": "raw",
+ "removable": 1,
+ "readwrite": 1
+ }
+ ],
+ "nics": [
+ {
+ "devid": 0,
+ "mac": "00:16:3e:3e:86:60",
+ "bridge": "br0",
+ "script": "/etc/xen/scripts/vif-bridge",
+ "nictype": "vif"
+ }
+ ],
+ "vfbs": [
+ {
+ "devid": -1,
+ "vnc": {
+ "enable": "True",
+ "listen": "0.0.0.0",
+ "findunused": "False"
+ },
+ "sdl": {
+ "enable": "False"
+ }
+ }
+ ],
+ "vkbs": [
+ {
+ "devid": -1
+ }
+ ],
+ "on_reboot": "restart"
+}
diff --git a/tests/libxlxml2domconfigdata/basic-pv.xml b/tests/libxlxml2domconfigdata/basic-pv.xml
new file mode 100644
index 0000000..b3bc601
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/basic-pv.xml
@@ -0,0 +1,28 @@
+<domain type='xen'>
+ <name>test-pv</name>
+ <uuid>039e9ee6-4a84-3055-4c81-8ba426ae2656</uuid>
+ <memory>524288</memory>
+ <currentMemory>524288</currentMemory>
+ <vcpu>4</vcpu>
+ <bootloader>pygrub</bootloader>
+ <os>
+ <type arch='i686' machine='xenpv'>linux</type>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='qemu'/>
+ <source file='/var/lib/xen/images/test-pv.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <interface type='bridge'>
+ <source bridge='br0'/>
+ <mac address='00:16:3e:3e:86:60'/>
+ <script path='/etc/xen/scripts/vif-bridge'/>
+ </interface>
+ <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
+ </devices>
+</domain>
diff --git a/tests/libxlxml2domconfigdata/moredevs-hvm.json b/tests/libxlxml2domconfigdata/moredevs-hvm.json
new file mode 100644
index 0000000..8f861f3
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/moredevs-hvm.json
@@ -0,0 +1,111 @@
+{
+ "c_info": {
+ "type": "hvm",
+ "hap": "True",
+ "name": "test-hvm",
+ "uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b"
+ },
+ "b_info": {
+ "max_vcpus": 4,
+ "avail_vcpus": [
+ 0,
+ 1,
+ 2,
+ 3
+ ],
+ "tsc_mode": "native",
+ "max_memkb": 1048576,
+ "target_memkb": 1048576,
+ "video_memkb": 8192,
+ "shadow_memkb": 12288,
+ "device_model_version": "qemu_xen",
+ "device_model": "/bin/true",
+ "sched_params": {
+ "weight": 1000
+ },
+ "type.hvm": {
+ "pae": "True",
+ "apic": "True",
+ "acpi": "True",
+ "hpet": "True",
+ "vga": {
+ "kind": "cirrus"
+ },
+ "vnc": {
+ "enable": "True",
+ "findunused": "False"
+ },
+ "sdl": {
+ "enable": "False"
+ },
+ "spice": {
+
+ },
+ "serial": "pty",
+ "boot": "c",
+ "usbdevice_list": [
+ "mouse",
+ "tablet"
+ ],
+ "rdm": {
+
+ }
+ },
+ "arch_arm": {
+
+ }
+ },
+ "disks": [
+ {
+ "pdev_path": "/var/lib/xen/images/test-hvm.img",
+ "vdev": "hda",
+ "backend": "qdisk",
+ "format": "raw",
+ "removable": 1,
+ "readwrite": 1
+ },
+ {
+ "pdev_path": "/root/boot.iso",
+ "vdev": "hdb",
+ "backend": "qdisk",
+ "format": "raw",
+ "removable": 1,
+ "is_cdrom": 1
+ }
+ ],
+ "nics": [
+ {
+ "devid": 0,
+ "model": "netfront",
+ "mac": "00:16:3e:7a:35:ce",
+ "bridge": "br0",
+ "script": "/etc/xen/scripts/vif-bridge",
+ "nictype": "vif"
+ }
+ ],
+ "pcidevs": [
+ {
+ "dev": 16,
+ "bus": 10,
+ "rdm_policy": "invalid"
+ }
+ ],
+ "vfbs": [
+ {
+ "devid": -1,
+ "vnc": {
+ "enable": "True",
+ "findunused": "False"
+ },
+ "sdl": {
+ "enable": "False"
+ }
+ }
+ ],
+ "vkbs": [
+ {
+ "devid": -1
+ }
+ ],
+ "on_reboot": "restart"
+}
diff --git a/tests/libxlxml2domconfigdata/moredevs-hvm.xml b/tests/libxlxml2domconfigdata/moredevs-hvm.xml
new file mode 100644
index 0000000..f7eb09f
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/moredevs-hvm.xml
@@ -0,0 +1,63 @@
+<domain type='xen'>
+ <name>test-hvm</name>
+ <description>None</description>
+ <uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
+ <memory>1048576</memory>
+ <currentMemory>1048576</currentMemory>
+ <vcpu>4</vcpu>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <clock offset='variable' adjustment='0' basis='utc'>
+ <timer name='tsc' present='yes' mode='native'/>
+ <timer name='hpet' present='yes'/>
+ </clock>
+ <os>
+ <type>hvm</type>
+ <loader>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <apic/>
+ <acpi/>
+ <pae/>
+ <hap/>
+ </features>
+ <devices>
+ <emulator>/bin/true</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='raw' cache='default'/>
+ <source file='/var/lib/xen/images/test-hvm.img'/>
+ <target dev='hda'/>
+ </disk>
+ <disk type='file' device='cdrom'>
+ <driver name='qemu' type='raw' cache='default'/>
+ <source file='/root/boot.iso'/>
+ <target dev='hdb'/>
+ </disk>
+ <interface type='bridge'>
+ <source bridge='br0'/>
+ <mac address='00:16:3e:7a:35:ce'/>
+ <script path='/etc/xen/scripts/vif-bridge'/>
+ <model type='netfront'/>
+ </interface>
+ <interface type='hostdev' managed='yes'>
+ <mac address='00:16:3e:2e:e7:fc'/>
+ <driver name='xen'/>
+ <source>
+ <address type='pci' domain='0x0000' bus='0x0a' slot='0x10' function='0x0'/>
+ </source>
+ </interface>
+ <graphics type='vnc'/>
+ <video>
+ <model type='cirrus' vram='8192' heads='1' primary='yes'/>
+ </video>
+ <console type='pty'>
+ <target port='0'/>
+ </console>
+ <input type='mouse' bus='usb'/>
+ <input type='tablet' bus='usb'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ </devices>
+</domain>
diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
new file mode 100644
index 0000000..d943cf2
--- /dev/null
+++ b/tests/libxlxml2domconfigtest.c
@@ -0,0 +1,205 @@
+/*
+ * libxlxml2domconfigtest.c: test conversion of domXML to
+ * libxl_domain_config structure.
+ *
+ * Copyright (C) 2017 SUSE LINUX Products GmbH, Nuernberg, Germany.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Jim Fehlig <jfehlig(a)suse.com>
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "testutils.h"
+
+#if defined(WITH_LIBXL) && defined(WITH_YAJL) && defined(HAVE_LIBXL_DOMAIN_CONFIG_FROM_JSON)
+
+# include "internal.h"
+# include "viralloc.h"
+# include "libxl/libxl_conf.h"
+# include "datatypes.h"
+# include "virstring.h"
+# include "virmock.h"
+# include "virjson.h"
+# include "testutilsxen.h"
+
+# define VIR_FROM_THIS VIR_FROM_LIBXL
+
+static const char *abs_top_srcdir;
+static virCapsPtr xencaps;
+
+static int
+testCompareXMLToDomConfig(const char *xmlfile,
+ const char *jsonfile)
+{
+ int ret = -1;
+ libxl_domain_config actualconfig;
+ libxl_domain_config expectconfig;
+ xentoollog_logger *log = NULL;
+ libxl_ctx *ctx = NULL;
+ virPortAllocatorPtr gports = NULL;
+ virDomainXMLOptionPtr xmlopt = NULL;
+ virDomainDefPtr vmdef = NULL;
+ char *actualjson = NULL;
+ char *tempjson = NULL;
+ char *expectjson = NULL;
+
+ libxl_domain_config_init(&actualconfig);
+ libxl_domain_config_init(&expectconfig);
+
+ if (!(log = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0)))
+ goto cleanup;
+
+ if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0)
+ goto cleanup;
+
+ if (!(gports = virPortAllocatorNew("vnc", 5900, 6000,
+ VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
+ goto cleanup;
+
+ if (!(xmlopt = libxlCreateXMLConf()))
+ goto cleanup;
+
+ if (!(vmdef = virDomainDefParseFile(xmlfile, xencaps, xmlopt,
+ NULL, VIR_DOMAIN_XML_INACTIVE)))
+ goto cleanup;
+
+ if (libxlBuildDomainConfig(gports, vmdef, NULL, ctx, xencaps, &actualconfig) < 0)
+ goto cleanup;
+
+ if (!(actualjson = libxl_domain_config_to_json(ctx, &actualconfig))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "Failed to retrieve JSON doc for libxl_domain_config");
+ goto cleanup;
+ }
+
+ virTestLoadFile(jsonfile, &tempjson);
+ if (libxl_domain_config_from_json(ctx, &expectconfig, tempjson) != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "Failed to create libxl_domain_config from JSON doc");
+ goto cleanup;
+ }
+ if (!(expectjson = libxl_domain_config_to_json(ctx, &expectconfig))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "Failed to retrieve JSON doc for libxl_domain_config");
+ goto cleanup;
+ }
+
+ if (virTestCompareToString(expectjson, actualjson) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(expectjson);
+ VIR_FREE(actualjson);
+ VIR_FREE(tempjson);
+ virDomainDefFree(vmdef);
+ virObjectUnref(gports);
+ virObjectUnref(xmlopt);
+ libxl_ctx_free(ctx);
+ libxl_domain_config_dispose(&actualconfig);
+ libxl_domain_config_dispose(&expectconfig);
+ xtl_logger_destroy(log);
+ return ret;
+}
+
+
+struct testInfo {
+ const char *name;
+};
+
+
+static int
+testCompareXMLToDomConfigHelper(const void *data)
+{
+ int ret = -1;
+ const struct testInfo *info = data;
+ char *xmlfile = NULL;
+ char *jsonfile = NULL;
+
+ if (virAsprintf(&xmlfile, "%s/libxlxml2domconfigdata/%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&jsonfile, "%s/libxlxml2domconfigdata/%s.json",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
+
+ ret = testCompareXMLToDomConfig(xmlfile, jsonfile);
+
+ cleanup:
+ VIR_FREE(xmlfile);
+ VIR_FREE(jsonfile);
+ return ret;
+}
+
+
+static int
+mymain(void)
+{
+ int ret = 0;
+
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ abs_top_srcdir = abs_srcdir "/..";
+
+ /* Set the timezone because we are mocking the time() function.
+ * If we don't do that, then localtime() may return unpredictable
+ * results. In order to detect things that just work by a blind
+ * chance, we need to set an virtual timezone that no libvirt
+ * developer resides in. */
+ if (setenv("TZ", "VIR00:30", 1) < 0) {
+ perror("setenv");
+ return EXIT_FAILURE;
+ }
+
+ if ((xencaps = testXenCapsInit()) == NULL)
+ return EXIT_FAILURE;
+
+# define DO_TEST(name) \
+ do { \
+ static struct testInfo info = { \
+ name, \
+ }; \
+ if (virTestRun("LibXL XML-2-JSON " name, \
+ testCompareXMLToDomConfigHelper, &info) < 0) \
+ ret = -1; \
+ } while (0)
+
+ DO_TEST("basic-pv");
+ DO_TEST("basic-hvm");
+ DO_TEST("moredevs-hvm");
+
+ return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virmocklibxl.so")
+
+#else
+
+int main(void)
+{
+ return EXIT_AM_SKIP;
+}
+
+#endif /* WITH_LIBXL && WITH_YAJL && HAVE_LIBXL_DOMAIN_CONFIG_FROM_JSON */
diff --git a/tests/virmocklibxl.c b/tests/virmocklibxl.c
new file mode 100644
index 0000000..bc4b53d
--- /dev/null
+++ b/tests/virmocklibxl.c
@@ -0,0 +1,87 @@
+/*
+ * virmocklibxl.c: mocking of xenstore/libxs for libxl
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Daniel P. Berrange <berrange(a)redhat.com>
+ */
+
+#include <config.h>
+
+#if defined(WITH_LIBXL) && defined(WITH_YAJL)
+# include "virmock.h"
+# include <sys/stat.h>
+# include <unistd.h>
+# include <libxl.h>
+# include <xenstore.h>
+# include <xenctrl.h>
+
+VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
+ struct xs_handle *)
+{
+ VIR_MOCK_REAL_INIT(xs_daemon_open);
+ return (void*)0x1;
+}
+
+VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,
+ xc_interface *,
+ xentoollog_logger *, logger,
+ xentoollog_logger *, dombuild_logger,
+ unsigned, open_flags)
+{
+ VIR_MOCK_REAL_INIT(xc_interface_open);
+ return (void*)0x1;
+}
+
+
+VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
+ int, 0,
+ xc_interface *, handle)
+
+VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
+ struct xs_handle *, handle)
+
+VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
+ int, ver,
+ const char *, path,
+ struct stat *, sb)
+{
+ VIR_MOCK_REAL_INIT(__xstat);
+
+ if (strstr(path, "xenstored.pid")) {
+ memset(sb, 0, sizeof(*sb));
+ return 0;
+ }
+
+ return real___xstat(ver, path, sb);
+}
+
+VIR_MOCK_IMPL_RET_ARGS(stat, int,
+ const char *, path,
+ struct stat *, sb)
+{
+ VIR_MOCK_REAL_INIT(stat);
+
+ if (strstr(path, "xenstored.pid")) {
+ memset(sb, 0, sizeof(*sb));
+ return 0;
+ }
+
+ return real_stat(path, sb);
+}
+
+#endif /* WITH_LIBXL && WITH_YAJL */
base-commit: ace45e67abbd9a033be54602db71a9dbc71408d7
--
git-series 0.9.1
7 years, 4 months
[libvirt] [PATCH] docs: make website responsive for mobile devices
by Daniel P. Berrange
The website does not look good in a mobile device as the text is
far too small and the layout assumes a wide screen.
Make the style dynanically adapt based on viewport size, so a
mobile device gets a layout more suited to its dimensions.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
docs/main.css | 1 +
docs/mobile.css | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
docs/page.xsl | 34 +++++++++++++++++++++
3 files changed, 130 insertions(+)
create mode 100644 docs/mobile.css
diff --git a/docs/main.css b/docs/main.css
index 95d5d325d..71f7b7a6a 100644
--- a/docs/main.css
+++ b/docs/main.css
@@ -1,3 +1,4 @@
@import url(fonts/stylesheet.css);
@import url(generic.css);
@import url(libvirt.css);
+@import url(mobile.css);
diff --git a/docs/mobile.css b/docs/mobile.css
new file mode 100644
index 000000000..0fc1e9d71
--- /dev/null
+++ b/docs/mobile.css
@@ -0,0 +1,95 @@
+
+@media (max-width: 1000px) {
+ #home {
+ width: 100%;
+ display: block;
+ margin: 0px;
+ background: white url(logos/logo-banner-dark-256.png) no-repeat center center;
+ height: 94px;
+ }
+ #home a {
+ width: 100%;
+ }
+ #search {
+ width: 100%;
+ display: block;
+ margin: 0px;
+ background: white;
+ padding: 0px;
+ }
+ #search form {
+ padding: 5px;
+ }
+ body.index h1 {
+ display: none;
+ }
+ #jumplinks {
+ padding: 0px;
+ display: block;
+ width: 100%;
+ text-align: center;
+ margin: 0px;
+ height: 1.3em;
+ font-size: 1em;
+ border-top: 3px solid rgb(60, 133, 124);
+ border-bottom: 3px solid rgb(60, 133, 124);
+ }
+ #jumplinks ul {
+ display: block;
+ padding: 0px;
+ margin: 0px;
+ }
+ #jumplinks li {
+ margin: 0px;
+ padding-left: 0.5em;
+ padding-right: 0.5em;
+ }
+ #nav {
+ border: 0px;
+ }
+
+ #search.navhide {
+ display: none !IMPORTANT;
+ }
+ #home.navhide {
+ position: fixed;
+ top: 0px;
+ z-index: 9001;
+ width: 6em;
+ display: block;
+ margin: 0px;
+ background: inherit;
+ height: 1.3em;
+ border-top: 3px solid rgb(60, 133, 124);
+ border-bottom: 3px solid rgb(60, 133, 124);
+ font-size: 1em;
+ text-indent: 0px;
+ font-weight: bold;
+ padding-left: 1em;
+ }
+ #home.navhide a {
+ color: white;
+ text-decoration: none;
+ }
+ #home.navhide a:hover {
+ color: rgb(255, 230, 0);
+ }
+ #jumplinks.navhide {
+ position: fixed;
+ text-align: right;
+ top: 0px;
+ z-index: 9000;
+ background: rgb(0, 95, 97);
+ }
+ #jumplinks.navhide ul {
+ z-index: 9001;
+ }
+ #body {
+ margin-top: 180px;
+ }
+ div.panel {
+ width: 80%;
+ float: none;
+ margin-bottom: 2em;
+ }
+}
diff --git a/docs/page.xsl b/docs/page.xsl
index 7ca4e7bf4..0f762be7d 100644
--- a/docs/page.xsl
+++ b/docs/page.xsl
@@ -88,6 +88,7 @@
</xsl:comment>
<head>
<meta charset="UTF-8"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" type="text/css" href="{$href_base}main.css"/>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"/>
@@ -97,6 +98,39 @@
<title>libvirt: <xsl:value-of select="html:html/html:body/html:h1"/></title>
<meta name="description" content="libvirt, virtualization, virtualization API"/>
<xsl:apply-templates select="/html:html/html:head/*" mode="content"/>
+
+ <script type="text/javascript">
+ <xsl:comment>
+ <![CDATA[
+ function init() {
+ window.addEventListener('scroll', function(e){
+ var distanceY = window.pageYOffset || document.documentElement.scrollTop,
+ shrinkOn = 94
+ home = document.getElementById("home");
+ links = document.getElementById("jumplinks");
+ search = document.getElementById("search");
+ body = document.getElementById("body");
+ if (distanceY > shrinkOn) {
+ if (home.className != "navhide") {
+ body.className = "navhide"
+ home.className = "navhide"
+ links.className = "navhide"
+ search.className = "navhide"
+ }
+ } else {
+ if (home.className == "navhide") {
+ body.className = ""
+ home.className = ""
+ links.className = ""
+ search.className = ""
+ }
+ }
+ });
+ }
+ window.onload = init();
+ ]]>
+ </xsl:comment>
+ </script>
</head>
<body>
<xsl:if test="html:html/html:body/@class">
--
2.13.3
7 years, 4 months
[libvirt] [PATCH v2 0/4] Add setting CPU features (CPUID) with libxenlight driver.
by Marek Marczykowski-Górecki
Tests (patches 3 and 4) depends on libxl_domain_config test suite:
https://www.redhat.com/archives/libvir-list/2017-February/msg01477.html
But first two patches can be applied independently.
Marek Marczykowski-Górecki (4):
cpu: define sub-leaf 0 for leaf 7 in cpu_map.xml
libxl: add support for CPUID features policy
tests: switch libxlxml2domconfig test to use testXLInintCaps
tests: check CPU features handling in libxl driver
src/cpu/cpu_map.xml | 58 ++++++-------
src/libxl/libxl_conf.c | 77 ++++++++++++++++-
src/libxl/libxl_conf.h | 1 +-
tests/libxlxml2domconfigdata/basic-pv.xml | 2 +-
tests/libxlxml2domconfigdata/fullvirt-cpuid.json | 64 ++++++++++++++-
tests/libxlxml2domconfigdata/fullvirt-cpuid.xml | 37 ++++++++-
tests/libxlxml2domconfigtest.c | 3 +-
7 files changed, 207 insertions(+), 35 deletions(-)
create mode 100644 tests/libxlxml2domconfigdata/fullvirt-cpuid.json
create mode 100644 tests/libxlxml2domconfigdata/fullvirt-cpuid.xml
base-commit: fbcc08b245bb7d5502633d9cb4048281cc9d8532
--
git-series 0.9.1
7 years, 4 months
[libvirt] [PATCH RESEND] Interface: return appropriate status for bridge device
by Lin Ma
In function udevInterfaceIsActive, The current design relies on the sys
attribute 'operstate' to determine whether the interface is active.
For the device node of virtual network(say virbr0), There is already a
dummy tap device to maintain a fixed mac on it, So it's available and
its status should be considered as active. But if no anyelse tap device
connects to it, The value of operstate of virbr0 in sysfs is 'down', So
udevInterfaceIsActive returns 0, It causes 'virsh iface-list --all' to
report the status of virbr0 as 'inactive'.
This patch fixes the issue by counting slave devices for bridge device.
Signed-off-by: Lin Ma <lma(a)suse.com>
---
src/interface/interface_backend_udev.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 5d0fc64..9ac4674 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -1127,6 +1127,11 @@ udevInterfaceIsActive(virInterfacePtr ifinfo)
struct udev_device *dev;
virInterfaceDefPtr def = NULL;
int status = -1;
+ struct dirent **member_list = NULL;
+ const char *devtype;
+ int member_count = 0;
+ char *member_path;
+ size_t i;
dev = udev_device_new_from_subsystem_sysname(udev, "net",
ifinfo->name);
@@ -1146,6 +1151,23 @@ udevInterfaceIsActive(virInterfacePtr ifinfo)
/* Check if it's active or not */
status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
+ if (!status) {
+ devtype = udev_device_get_devtype(dev);
+ if (STREQ_NULLABLE(devtype, "bridge")) {
+ if (virAsprintf(&member_path, "%s/%s",
+ udev_device_get_syspath(dev), "brif") < 0)
+ goto cleanup;
+ member_count = scandir(member_path, &member_list,
+ udevBridgeScanDirFilter, alphasort);
+ if (member_count > 0)
+ status = 1;
+ for (i = 0; i < member_count; i++)
+ VIR_FREE(member_list[i]);
+ VIR_FREE(member_list);
+ VIR_FREE(member_path);
+ }
+ }
+
udev_device_unref(dev);
cleanup:
--
2.9.2
7 years, 4 months
[libvirt] [PATCH 0/3] qemu: command: clean up default cpu formatting
by Cole Robinson
Just some minor patches to do with encoding a default CPU on the
qemu command line.
Patch 1 adds a test case
Patch 2 simplifies the code
Patch 3 throws an explicit error for a confusing situation
Cole Robinson (3):
tests: add qemu x86 kvm 32-on-64 test
qemu: command: rework adding of default cpu model
qemu: command: explicitly error for non-x86 default CPU
src/qemu/qemu_command.c | 95 +++++++++-------------
.../qemuxml2argvdata/qemuxml2argv-hyperv-off.args | 1 -
.../qemuxml2argv-kvm-features-off.args | 1 -
.../qemuxml2argv-x86-kvm-32-on-64.args | 21 +++++
.../qemuxml2argv-x86-kvm-32-on-64.xml | 13 +++
tests/qemuxml2argvtest.c | 1 +
tests/testutilsqemu.c | 18 +++-
7 files changed, 90 insertions(+), 60 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-x86-kvm-32-on-64.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-x86-kvm-32-on-64.xml
--
2.13.3
7 years, 4 months
[libvirt] [PATCH v2 0/8] Some virObjectRW* adjustments
by John Ferlan
v1: https://www.redhat.com/archives/libvir-list/2017-July/msg01313.html
Differences from v1:
* Use the names virObjectRWLockRead, virObjectRWLockWrite and
virObjectRWUnlock
* Instead of an 'int' return, make the virObjectRWLock{Read|Write} be
void returns just like virObject{Lock|Unlock}
* Separate out the magic number check for the virObjectIsClass consumers
into its own patch and describe the reasons for usage.
* Apply the same magic number check to virObject{Ref|Unref} separately.
BTW: This looks and works eally nice with what I have for common objects...
John Ferlan (8):
util: Rename virObjectLockRead to virObjectRWLockRead
util: Introduce and use virObjectRWLockWrite
util: Only have virObjectLock handle virObjectLockable
util: Introduce virObjectGetRWLockableObj
util: Introduce and use virObjectRWUnlock
util: Create common error path for invalid object
util: Add magic number check for object validity
util: Add object checking for virObject{Ref|Unref}
src/conf/virdomainobjlist.c | 62 ++++++++--------
src/libvirt_private.syms | 4 +-
src/util/virobject.c | 169 +++++++++++++++++++++++++++++++++-----------
src/util/virobject.h | 10 ++-
4 files changed, 169 insertions(+), 76 deletions(-)
--
2.9.4
7 years, 4 months
[libvirt] [PATCH v3 0/2] Restrict usage of unsupported clock timers
by Kothapally Madhu Pavan
hpet and kvm.pit clock timers are specific to x86 architecture and
are not to be used by unsuported architectures. Similarly sPAPR
guests only allow RTC timer. This patchset will restrict the usage
of unsupported clock timers.
Kothapally Madhu Pavan (2):
qemu: Restrict usage of hpet and kvm.pit timers by unsupported
architectures
qemu: Default hwclock source for sPAPR to RTC
src/qemu/qemu_domain.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
--
1.8.3.1
7 years, 4 months
[libvirt] [PATCH 0/2] Fix smartcard formatting regression
by Ján Tomko
*** BLURB HERE ***
Ján Tomko (2):
tests: add smartcard test cases to qemuxml2xmltest
conf: fix formatting of smartcard devices
src/conf/domain_conf.c | 43 ++++++++++++++--------
.../qemuxml2xmlout-smartcard-controller.xml | 31 ++++++++++++++++
.../qemuxml2xmlout-smartcard-host-certificates.xml | 34 +++++++++++++++++
.../qemuxml2xmlout-smartcard-host.xml | 31 ++++++++++++++++
...muxml2xmlout-smartcard-passthrough-spicevmc.xml | 31 ++++++++++++++++
.../qemuxml2xmlout-smartcard-passthrough-tcp.xml | 33 +++++++++++++++++
tests/qemuxml2xmltest.c | 6 +++
7 files changed, 194 insertions(+), 15 deletions(-)
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-smartcard-controller.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-smartcard-host-certificates.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-smartcard-host.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-smartcard-passthrough-spicevmc.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-smartcard-passthrough-tcp.xml
--
2.13.0
7 years, 4 months
[libvirt] [PATCH] conf: Fix printing of 'type' and 'tty_compat' for Chr devices
by John Ferlan
Commit id '0c1d8632' caused a regression in the virt-manager
test suite when formatting the <smartcard mode='passthrough'
type='spicevmc'/>.
Adust the code to print the type in it's own new helper called
virDomainChrTypeFormat and have the virDomainChrSourceDefFormat
manage just formatting the source and change to a void type since
only 0 could be returned. Adjust the callers to handle properly.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
Although technically a CI build breaker since virt-manager test is
failing, I figured I'd let this one go through the formal review just
in case someone has agita over new function name or would like to see
things done in a different manner.
src/conf/domain_conf.c | 39 ++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index eb70523..878c15d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -22804,10 +22804,9 @@ virDomainNetDefFormat(virBufferPtr buf,
/* Assumes that "<device" has already been generated, and starts
* output at " type='type'>". */
static int
-virDomainChrSourceDefFormat(virBufferPtr buf,
- virDomainChrSourceDefPtr def,
- bool tty_compat,
- unsigned int flags)
+virDomainChrTypeFormat(virBufferPtr buf,
+ virDomainChrSourceDefPtr def,
+ bool tty_compat)
{
const char *type = virDomainChrTypeToString(def->type);
@@ -22825,6 +22824,15 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
}
virBufferAddLit(buf, ">\n");
+ return 0;
+}
+
+
+static void
+virDomainChrSourceDefFormat(virBufferPtr buf,
+ virDomainChrSourceDefPtr def,
+ unsigned int flags)
+{
switch ((virDomainChrType)def->type) {
case VIR_DOMAIN_CHR_TYPE_NULL:
case VIR_DOMAIN_CHR_TYPE_VC:
@@ -22923,8 +22931,6 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
}
virBufferAddLit(buf, "/>\n");
}
-
- return 0;
}
static int
@@ -22953,8 +22959,9 @@ virDomainChrDefFormat(virBufferPtr buf,
def->source->type == VIR_DOMAIN_CHR_TYPE_PTY &&
!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
def->source->data.file.path);
- if (virDomainChrSourceDefFormat(buf, def->source, tty_compat, flags) < 0)
+ if (virDomainChrTypeFormat(buf, def->source, tty_compat) < 0)
return -1;
+ virDomainChrSourceDefFormat(buf, def->source, flags);
/* Format <target> block */
switch (def->deviceType) {
@@ -23053,6 +23060,8 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
return -1;
}
+ virBufferAsprintf(buf, "<smartcard mode='%s'", mode);
+
switch (def->type) {
case VIR_DOMAIN_SMARTCARD_TYPE_HOST:
break;
@@ -23067,9 +23076,9 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
break;
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
- if (virDomainChrSourceDefFormat(&childBuf, def->data.passthru, false,
- flags) < 0)
+ if (virDomainChrTypeFormat(buf, def->data.passthru, false) < 0)
return -1;
+ virDomainChrSourceDefFormat(&childBuf, def->data.passthru, flags);
break;
default:
@@ -23082,7 +23091,6 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
if (virBufferCheckError(&childBuf) < 0)
return -1;
- virBufferAsprintf(buf, "<smartcard mode='%s'", mode);
if (virBufferUse(&childBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childBuf);
@@ -23390,10 +23398,10 @@ virDomainRNGDefFormat(virBufferPtr buf,
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
- virBufferAdjustIndent(buf, 2);
- if (virDomainChrSourceDefFormat(buf, def->source.chardev,
- false, flags) < 0)
+ if (virDomainChrTypeFormat(buf, def->source.chardev, false) < 0)
return -1;
+ virBufferAdjustIndent(buf, 2);
+ virDomainChrSourceDefFormat(buf, def->source.chardev, flags);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</backend>\n");
@@ -24234,9 +24242,10 @@ virDomainRedirdevDefFormat(virBufferPtr buf,
bus = virDomainRedirdevBusTypeToString(def->bus);
virBufferAsprintf(buf, "<redirdev bus='%s'", bus);
- virBufferAdjustIndent(buf, 2);
- if (virDomainChrSourceDefFormat(buf, def->source, false, flags) < 0)
+ if (virDomainChrTypeFormat(buf, def->source, false) < 0)
return -1;
+ virBufferAdjustIndent(buf, 2);
+ virDomainChrSourceDefFormat(buf, def->source, flags);
virDomainDeviceInfoFormat(buf, &def->info,
flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);
virBufferAdjustIndent(buf, -2);
--
2.9.4
7 years, 4 months
[libvirt] [PATCH 0/8] Delete a function
by Ján Tomko
*** BLURB HERE ***
Ján Tomko (8):
Remove superfluous usage of virDomainDeviceInfoNeedsFormat
virDomainDeviceInfoFormat: delete outdated comments
Use a separate buffer for <smartcard> subelements
Use a separate buffer for <sound> subelements
Use a separate buffer for <watchdog> subelements
Use a separate buffer for <hub> subelements
conf: check for buffer errors before virBufferUse
Turn virDomainDeviceInfoFormat into void
src/conf/capabilities.c | 5 +
src/conf/cpu_conf.c | 4 +
src/conf/domain_conf.c | 237 +++++++++++++++++++++---------------------------
3 files changed, 114 insertions(+), 132 deletions(-)
--
2.13.0
7 years, 4 months