From nobody Sun May 5 08:26:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501283296527827.862655946331; Fri, 28 Jul 2017 16:08:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA43D3389D7; Fri, 28 Jul 2017 23:08:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 985FF5C8A3; Fri, 28 Jul 2017 23:08:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AE68C1805977; Fri, 28 Jul 2017 23:08:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6SN870T007068 for ; Fri, 28 Jul 2017 19:08:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6242E173D3; Fri, 28 Jul 2017 23:08:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B1335D6A6 for ; Fri, 28 Jul 2017 23:08:04 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7ECBD41A17 for ; Fri, 28 Jul 2017 23:08:02 +0000 (UTC) Received: from linux-tbji.Home (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Fri, 28 Jul 2017 17:07:57 -0600 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA43D3389D7 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CA43D3389D7 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7ECBD41A17 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfehlig@suse.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7ECBD41A17 From: Jim Fehlig To: libvir-list@redhat.com Date: Fri, 28 Jul 2017 17:07:33 -0600 Message-Id: <20170728230734.11001-2-jfehlig@suse.com> In-Reply-To: <20170728230734.11001-1-jfehlig@suse.com> References: <20170728230734.11001-1-jfehlig@suse.com> X-Greylist: Delayed for 25:43:20 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Jul 2017 23:08:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Jul 2017 23:08:04 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: joao.m.martins@oracle.com Subject: [libvirt] [PATCH V2 1/2] libxl: make emulator checks mockable X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 28 Jul 2017 23:08:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Export the libxl emulator checks with ATTRIBUTE_NOINLINE so they can be mocked in the test suite. While add it, change the function names to conform to naming standards. Signed-off-by: Jim Fehlig --- src/libxl/libxl_capabilities.c | 30 +++++++++++++++++++++++++++++- src/libxl/libxl_capabilities.h | 5 ++++- src/libxl/libxl_conf.c | 17 +++-------------- src/libxl/libxl_domain.c | 2 +- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index e0959202b..501ebf477 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -743,7 +743,7 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps, #define LIBXL_QEMU_DM_STR "Options specific to the Xen version:" =20 int -libxlDomainGetEmulatorType(const virDomainDef *def) +libxlCapsGetEmulatorType(const virDomainDef *def) { int ret =3D LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; virCommandPtr cmd =3D NULL; @@ -772,3 +772,31 @@ libxlDomainGetEmulatorType(const virDomainDef *def) virCommandFree(cmd); return ret; } + + +/* + * Returns 0 if an is defined, exists, and is executable. + * Returns -1 otherwise. + */ +int +libxlCapsCheckEmulator(const virDomainDef *def) +{ + if (def->emulator =3D=3D NULL) + return 0; + + if (!virFileExists(def->emulator)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("emulator '%s' not found"), + def->emulator); + return -1; + } + + if (!virFileIsExecutable(def->emulator)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("emulator '%s' is not executable"), + def->emulator); + return -1; + } + + return 0; +} diff --git a/src/libxl/libxl_capabilities.h b/src/libxl/libxl_capabilities.h index 992b78077..28a58d36b 100644 --- a/src/libxl/libxl_capabilities.h +++ b/src/libxl/libxl_capabilities.h @@ -52,6 +52,9 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps, size_t nfirmwares); =20 int -libxlDomainGetEmulatorType(const virDomainDef *def); +libxlCapsGetEmulatorType(const virDomainDef *def) ATTRIBUTE_NOINLINE; + +int +libxlCapsCheckEmulator(const virDomainDef *def) ATTRIBUTE_NOINLINE; =20 #endif /* LIBXL_CAPABILITIES_H */ diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 4416a09dd..f8ebd88e0 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -472,25 +472,14 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, b_info->u.hvm.bios =3D LIBXL_BIOS_TYPE_OVMF; =20 if (def->emulator) { - if (!virFileExists(def->emulator)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("emulator '%s' not found"), - def->emulator); + if (libxlCapsCheckEmulator(def) < 0) return -1; - } - - if (!virFileIsExecutable(def->emulator)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("emulator '%s' is not executable"), - def->emulator); - return -1; - } =20 VIR_FREE(b_info->device_model); if (VIR_STRDUP(b_info->device_model, def->emulator) < 0) return -1; =20 - b_info->device_model_version =3D libxlDomainGetEmulatorType(de= f); + b_info->device_model_version =3D libxlCapsGetEmulatorType(def); } =20 if (def->nserials) { @@ -2082,7 +2071,7 @@ libxlMakeVideo(virDomainDefPtr def, libxl_domain_conf= ig *d_config) =20 { libxl_domain_build_info *b_info =3D &d_config->b_info; - int dm_type =3D libxlDomainGetEmulatorType(def); + int dm_type =3D libxlCapsGetEmulatorType(def); =20 if (d_config->c_info.type !=3D LIBXL_DOMAIN_TYPE_HVM) return 0; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 7caa67474..1bc9045bf 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -335,7 +335,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, } =20 if (dev->type =3D=3D VIR_DOMAIN_DEVICE_VIDEO && def->os.type =3D=3D VI= R_DOMAIN_OSTYPE_HVM) { - int dm_type =3D libxlDomainGetEmulatorType(def); + int dm_type =3D libxlCapsGetEmulatorType(def); =20 switch (dev->data.video->type) { case VIR_DOMAIN_VIDEO_TYPE_VGA: --=20 2.13.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:26:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501283312578650.58403059956; Fri, 28 Jul 2017 16:08:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B22AF734D8; Fri, 28 Jul 2017 23:08:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FF0960F8A; Fri, 28 Jul 2017 23:08:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 10A1A4BB79; Fri, 28 Jul 2017 23:08:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6SN8CGt007079 for ; Fri, 28 Jul 2017 19:08:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED99018B54; Fri, 28 Jul 2017 23:08:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E805760317 for ; Fri, 28 Jul 2017 23:08:11 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4920233887A for ; Fri, 28 Jul 2017 23:08:03 +0000 (UTC) Received: from linux-tbji.Home (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Fri, 28 Jul 2017 17:07:58 -0600 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B22AF734D8 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B22AF734D8 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4920233887A Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfehlig@suse.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4920233887A From: Jim Fehlig To: libvir-list@redhat.com Date: Fri, 28 Jul 2017 17:07:34 -0600 Message-Id: <20170728230734.11001-3-jfehlig@suse.com> In-Reply-To: <20170728230734.11001-1-jfehlig@suse.com> References: <20170728230734.11001-1-jfehlig@suse.com> X-Greylist: Delayed for 25:43:21 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 28 Jul 2017 23:08:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 28 Jul 2017 23:08:04 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: joao.m.martins@oracle.com Subject: [libvirt] [PATCH V2 2/2] libxl: Add a test suite for libxl_domain_config generator X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Jul 2017 23:08:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- m4/virt-driver-libxl.m4 | 4 + 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 | 209 +++++++++++++++++++++= ++++ tests/virmocklibxl.c | 106 +++++++++++++ 10 files changed, 727 insertions(+), 2 deletions(-) diff --git a/m4/virt-driver-libxl.m4 b/m4/virt-driver-libxl.m4 index 96a9d4736..e6dbfef68 100644 --- a/m4/virt-driver-libxl.m4 +++ b/m4/virt-driver-libxl.m4 @@ -80,6 +80,10 @@ AC_DEFUN([LIBVIRT_DRIVER_CHECK_LIBXL], [ LIBXL_LIBS=3D"$LIBXL_LIBS -lxenctrl" ]) =20 + dnl Check if libxl_domain_config_from_json is available for domXML to + dnl libxl_domain_config tests + LIBS=3D"$LIBS -lxenlight -lxenctrl" + AC_CHECK_FUNCS([libxl_domain_config_from_json]) CFLAGS=3D"$old_CFLAGS" LIBS=3D"$old_LIBS" fi diff --git a/tests/Makefile.am b/tests/Makefile.am index 3e3d58071..1f8c4cd42 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -99,6 +99,7 @@ EXTRA_DIST =3D \ genericxml2xmlindata \ genericxml2xmloutdata \ interfaceschemadata \ + libxlxml2domconfigdata \ lxcconf2xmldata \ lxcxml2xmldata \ lxcxml2xmloutdata \ @@ -271,7 +272,8 @@ test_programs +=3D xml2sexprtest sexpr2xmltest \ endif WITH_XEN =20 if WITH_LIBXL -test_programs +=3D xlconfigtest +test_programs +=3D xlconfigtest libxlxml2domconfigtest +test_libraries +=3D virmocklibxl.la endif WITH_LIBXL =20 if WITH_QEMU @@ -528,8 +530,20 @@ xlconfigtest_SOURCES =3D \ xlconfigtest.c testutilsxen.c testutilsxen.h \ testutils.c testutils.h xlconfigtest_LDADD =3D$(libxl_LDADDS) + +libxlxml2domconfigtest_SOURCES =3D \ + libxlxml2domconfigtest.c testutilsxen.c testutilsxen.h \ + testutils.c testutils.h +libxlxml2domconfigtest_LDADD =3D $(libxl_LDADDS) $(LIBXML_LIBS) + +virmocklibxl_la_SOURCES =3D \ + virmocklibxl.c +virmocklibxl_la_CFLAGS =3D $(AM_CFLAGS) +virmocklibxl_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) +virmocklibxl_la_LIBADD =3D $(MOCKLIBS_LIBS) + else ! WITH_LIBXL -EXTRA_DIST +=3D xlconfigtest.c +EXTRA_DIST +=3D xlconfigtest.c libxlxml2domconfigtest.c endif ! WITH_LIBXL =20 QEMUMONITORTESTUTILS_SOURCES =3D \ diff --git a/tests/libxlxml2domconfigdata/basic-hvm.json b/tests/libxlxml2d= omconfigdata/basic-hvm.json new file mode 100644 index 000000000..e4771920e --- /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": "/usr/lib/xen/bin/qemu-system-i386", + "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/libxlxml2do= mconfigdata/basic-hvm.xml new file mode 100644 index 000000000..9dedf1729 --- /dev/null +++ b/tests/libxlxml2domconfigdata/basic-hvm.xml @@ -0,0 +1,36 @@ + + test-hvm + None + 2147d599-9cc6-c0dc-92ab-4064b5446e9b + 1048576 + 1048576 + 4 + destroy + restart + destroy + + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + /usr/lib/xen/bin/qemu-system-i386 + + + + + + + + +