From nobody Wed May 14 10:50:32 2025 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524669754092812.9681892346314; Wed, 25 Apr 2018 08:22:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39EBF81E04; Wed, 25 Apr 2018 15:22:32 +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 C626E5D75E; Wed, 25 Apr 2018 15:22:31 +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 05A54180BADB; Wed, 25 Apr 2018 15:22:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3PFGEq6020306 for ; Wed, 25 Apr 2018 11:16:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6ADFE2023239; Wed, 25 Apr 2018 15:16:14 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7990202342F; Wed, 25 Apr 2018 15:16:13 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 25 Apr 2018 17:15:32 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Peter Krempa Subject: [libvirt] [PATCH 24/35] tests: qemublock: Add testing of blockdev JSON property 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 25 Apr 2018 15:22:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a test infrastructure that will allow testing the JSON object generator used for generating data to use with blockdev-add. The resulting disk including the backing chain is validated to conform to the QAPI schema and the expected output files. The first test cases make sure that libvirt will not allow nodenames exceeding 31 chars. Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- tests/Makefile.am | 3 + tests/qemublocktest.c | 227 +++++++++++++++++= ++++ .../xml2json/nodename-long-format.xml | 12 ++ .../xml2json/nodename-long-protocol.xml | 12 ++ 4 files changed, 254 insertions(+) create mode 100644 tests/qemublocktestdata/xml2json/nodename-long-format.x= ml create mode 100644 tests/qemublocktestdata/xml2json/nodename-long-protocol= .xml diff --git a/tests/Makefile.am b/tests/Makefile.am index 67850349de..6a61296c44 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -119,6 +119,7 @@ EXTRA_DIST =3D \ oomtrace.pl \ qemuagentdata \ qemuargv2xmldata \ + qemublocktestdata \ qemucapabilitiesdata \ qemucaps2xmldata \ qemuhotplugtestcpus \ @@ -657,8 +658,10 @@ qemuhotplugtest_LDADD =3D libqemumonitortestutils.la $= (qemu_LDADDS) $(LDADDS) qemublocktest_SOURCES =3D \ qemublocktest.c \ testutils.h testutils.c \ + testutilsqemu.h testutilsqemu.c \ $(NULL) qemublocktest_LDADD =3D \ + libqemumonitortestutils.la \ ../src/libvirt_conf.la \ ../src/libvirt_util.la \ $(qemu_LDADDS) \ diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 7eef9f286a..161053a717 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -19,10 +19,15 @@ #include #include "testutils.h" +#include "testutilsqemu.h" +#include "testutilsqemuschema.h" #include "virstoragefile.h" #include "virstring.h" #include "virlog.h" #include "qemu/qemu_block.h" +#include "qemu/qemu_qapi.h" + +#include "qemu/qemu_command.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -113,11 +118,190 @@ testBackingXMLjsonXML(const void *args) } +struct testQemuDiskXMLToJSONData { + virQEMUDriverPtr driver; + virHashTablePtr schema; + virJSONValuePtr schemaroot; + const char *name; + bool fail; + + virJSONValuePtr *props; + size_t nprops; + + virQEMUCapsPtr qemuCaps; +}; + + +static void +testQemuDiskXMLToPropsClear(struct testQemuDiskXMLToJSONData *data) +{ + size_t i; + + for (i =3D 0; i < data->nprops; i++) + virJSONValueFree(data->props[i]); + + data->nprops =3D 0; + VIR_FREE(data->props); +} + + +static const char *testQemuDiskXMLToJSONPath =3D abs_srcdir "/qemublocktes= tdata/xml2json/"; + +static int +testQemuDiskXMLToProps(const void *opaque) +{ + struct testQemuDiskXMLToJSONData *data =3D (void *) opaque; + virDomainDiskDefPtr disk =3D NULL; + virStorageSourcePtr n; + virJSONValuePtr props =3D NULL; + char *xmlpath =3D NULL; + char *xmlstr =3D NULL; + int ret =3D -1; + + if (virAsprintf(&xmlpath, "%s%s.xml", + testQemuDiskXMLToJSONPath, data->name) < 0) + goto cleanup; + + if (virTestLoadFile(xmlpath, &xmlstr) < 0) + goto cleanup; + + /* qemu stores node names in the status XML portion */ + if (!(disk =3D virDomainDiskDefParse(xmlstr, NULL, data->driver->xmlop= t, + VIR_DOMAIN_DEF_PARSE_STATUS))) + goto cleanup; + + if (qemuCheckDiskConfig(disk, data->qemuCaps) < 0 || + qemuDomainDeviceDefValidateDisk(disk, data->qemuCaps) < 0) { + VIR_TEST_VERBOSE("invalid configuration for disk\n"); + goto cleanup; + } + + if (qemuDomainPrepareDiskSourceChain(disk, NULL, NULL, data->qemuCaps)= < 0) + goto cleanup; + + for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backingSt= ore) { + if (!(props =3D qemuBlockStorageSourceGetBlockdevProps(n))) { + if (!data->fail) { + VIR_TEST_VERBOSE("failed to generate qemu blockdev props\n= "); + goto cleanup; + } + } else if (data->fail) { + VIR_TEST_VERBOSE("qemu blockdev props should have failed\n"); + goto cleanup; + } + + if (VIR_APPEND_ELEMENT(data->props, data->nprops, props) < 0) + goto cleanup; + } + + ret =3D 0; + + cleanup: + virDomainDiskDefFree(disk); + VIR_FREE(xmlpath); + VIR_FREE(xmlstr); + return ret; +} + + +static int +testQemuDiskXMLToPropsValidateSchema(const void *opaque) +{ + struct testQemuDiskXMLToJSONData *data =3D (void *) opaque; + virBuffer debug =3D VIR_BUFFER_INITIALIZER; + char *propsstr =3D NULL; + char *debugmsg =3D NULL; + int ret =3D 0; + size_t i; + + if (data->fail) + return EXIT_AM_SKIP; + + for (i =3D 0; i < data->nprops; i++) { + if (testQEMUSchemaValidate(data->props[i], data->schemaroot, + data->schema, &debug) < 0) { + debugmsg =3D virBufferContentAndReset(&debug); + propsstr =3D virJSONValueToString(data->props[i], true); + VIR_TEST_VERBOSE("json does not conform to QAPI schema"); + VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output= :\n %s", + propsstr, NULLSTR(debugmsg)); + VIR_FREE(debugmsg); + VIR_FREE(propsstr); + ret =3D -1; + } + + virBufferFreeAndReset(&debug); + } + return ret; +} + + +static int +testQemuDiskXMLToPropsValidateFile(const void *opaque) +{ + struct testQemuDiskXMLToJSONData *data =3D (void *) opaque; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *jsonpath =3D NULL; + char *jsonstr =3D NULL; + char *actual =3D NULL; + int ret =3D -1; + size_t i; + + if (data->fail) + return EXIT_AM_SKIP; + + if (virAsprintf(&jsonpath, "%s%s.json", + testQemuDiskXMLToJSONPath, data->name) < 0) + goto cleanup; + + for (i =3D 0; i < data->nprops; i++) { + if (!(jsonstr =3D virJSONValueToString(data->props[i], true))) + goto cleanup; + + virBufferAdd(&buf, jsonstr, -1); + } + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + actual =3D virBufferContentAndReset(&buf); + + ret =3D virTestCompareToFile(actual, jsonpath); + + cleanup: + VIR_FREE(jsonpath); + VIR_FREE(jsonstr); + VIR_FREE(actual); + return ret; +} + + static int mymain(void) { int ret =3D 0; + virQEMUDriver driver; struct testBackingXMLjsonXMLdata xmljsonxmldata; + struct testQemuDiskXMLToJSONData diskxmljsondata; + char *capslatest_x86_64 =3D NULL; + virQEMUCapsPtr caps_x86_64 =3D NULL; + + if (qemuTestDriverInit(&driver) < 0) + return EXIT_FAILURE; + + diskxmljsondata.driver =3D &driver; + + if (!(capslatest_x86_64 =3D testQemuGetLatestCapsForArch(abs_srcdir "/= qemucapabilitiesdata", + "x86_64", "xml"= ))) + return EXIT_FAILURE; + + VIR_TEST_VERBOSE("\nlatest caps x86_64: %s\n", capslatest_x86_64); + + if (!(caps_x86_64 =3D qemuTestParseCapabilitiesArch(virArchFromString(= "x86_64"), + capslatest_x86_64))) + return EXIT_FAILURE; + + diskxmljsondata.qemuCaps =3D caps_x86_64; virTestCounterReset("qemu storage source xml->json->xml "); @@ -183,6 +367,49 @@ mymain(void) " \n" "\n"); +#define TEST_DISK_TO_JSON_FULL(nme, fl) \ + do { \ + diskxmljsondata.name =3D nme; \ + diskxmljsondata.props =3D NULL; \ + diskxmljsondata.nprops =3D 0; \ + diskxmljsondata.fail =3D fl; \ + if (virTestRun("disk xml to props " nme, testQemuDiskXMLToProps, \ + &diskxmljsondata) < 0) \ + ret =3D -1; \ + if (virTestRun("disk xml to props validate schema " nme, \ + testQemuDiskXMLToPropsValidateSchema, &diskxmljsond= ata) < 0) \ + ret =3D -1; \ + if (virTestRun("disk xml to props validate file " nme, \ + testQemuDiskXMLToPropsValidateFile, &diskxmljsonda= ta) < 0) \ + ret =3D -1; \ + testQemuDiskXMLToPropsClear(&diskxmljsondata); \ + } while (0) + +#define TEST_DISK_TO_JSON(nme) TEST_DISK_TO_JSON_FULL(nme, false) + + if (!(diskxmljsondata.schema =3D testQEMUSchemaLoad())) { + ret =3D -1; + goto cleanup; + } + + if (virQEMUQAPISchemaPathGet("blockdev-add/arg-type", + diskxmljsondata.schema, + &diskxmljsondata.schemaroot) < 0 || + !diskxmljsondata.schemaroot) { + VIR_TEST_VERBOSE("failed to find schema entry for blockdev-add\n"); + ret =3D -1; + goto cleanup; + } + + TEST_DISK_TO_JSON_FULL("nodename-long-format", true); + TEST_DISK_TO_JSON_FULL("nodename-long-protocol", true); + + cleanup: + virHashFree(diskxmljsondata.schema); + qemuTestDriverFree(&driver); + VIR_FREE(capslatest_x86_64); + virObjectUnref(caps_x86_64); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/qemublocktestdata/xml2json/nodename-long-format.xml b/te= sts/qemublocktestdata/xml2json/nodename-long-format.xml new file mode 100644 index 0000000000..8fccf850db --- /dev/null +++ b/tests/qemublocktestdata/xml2json/nodename-long-format.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/tests/qemublocktestdata/xml2json/nodename-long-protocol.xml b/= tests/qemublocktestdata/xml2json/nodename-long-protocol.xml new file mode 100644 index 0000000000..e60d988325 --- /dev/null +++ b/tests/qemublocktestdata/xml2json/nodename-long-protocol.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list