From nobody Mon Apr 29 08:35:54 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.zoho.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 1498568106994425.9545145950991; Tue, 27 Jun 2017 05:55:06 -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 91F58C04D294; Tue, 27 Jun 2017 12:55:04 +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 EA4158A78C; Tue, 27 Jun 2017 12:55:03 +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 EACCE41F76; Tue, 27 Jun 2017 12:55:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RCkvGt023745 for ; Tue, 27 Jun 2017 08:46:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7CBC8A472; Tue, 27 Jun 2017 12:46:57 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 824E68A77F; Tue, 27 Jun 2017 12:46:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91F58C04D294 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 91F58C04D294 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:42 +0200 Message-Id: <34e20032dce8159520e47f721cae63f76ff0b617.1498567512.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/9] tests: Rename jsontest to virjsontest 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.31]); Tue, 27 Jun 2017 12:55:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Reviewed-by: John Ferlan --- tests/Makefile.am | 8 ++++---- tests/{jsontest.c =3D> virjsontest.c} | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename tests/{jsontest.c =3D> virjsontest.c} (100%) diff --git a/tests/Makefile.am b/tests/Makefile.am index 19986dc99..3596b5ff1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -328,7 +328,7 @@ test_programs +=3D objectlocking endif WITH_CIL if WITH_YAJL -test_programs +=3D jsontest +test_programs +=3D virjsontest endif WITH_YAJL test_programs +=3D \ @@ -1375,9 +1375,9 @@ virfirewalltest_SOURCES =3D \ virfirewalltest_LDADD =3D $(LDADDS) $(DBUS_LIBS) virfirewalltest_CFLAGS =3D $(AM_CFLAGS) $(DBUS_CFLAGS) -jsontest_SOURCES =3D \ - jsontest.c testutils.h testutils.c -jsontest_LDADD =3D $(LDADDS) +virjsontest_SOURCES =3D \ + virjsontest.c testutils.h testutils.c +virjsontest_LDADD =3D $(LDADDS) utiltest_SOURCES =3D \ utiltest.c testutils.h testutils.c diff --git a/tests/jsontest.c b/tests/virjsontest.c similarity index 100% rename from tests/jsontest.c rename to tests/virjsontest.c --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 1498567869807270.6425092353138; Tue, 27 Jun 2017 05:51:09 -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 CDF507F409; Tue, 27 Jun 2017 12:51:06 +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 79EEB87108; Tue, 27 Jun 2017 12:51:06 +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 F32B93FADE; Tue, 27 Jun 2017 12:51:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RCl0dq023761 for ; Tue, 27 Jun 2017 08:47:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2269B8A781; Tue, 27 Jun 2017 12:47:00 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93D068A472; Tue, 27 Jun 2017 12:46:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CDF507F409 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CDF507F409 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:43 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/9] util: json: Add virJSONValueIsObject 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]); Tue, 27 Jun 2017 12:51:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Allows testing whether a virJSONValue is an object. Reviewed-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virjson.c | 10 ++++++++++ src/util/virjson.h | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c1e9471c5..d487b1f43 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1905,6 +1905,7 @@ virJSONValueGetString; virJSONValueHashFree; virJSONValueIsArray; virJSONValueIsNull; +virJSONValueIsObject; virJSONValueNewArray; virJSONValueNewArrayFromBitmap; virJSONValueNewBoolean; diff --git a/src/util/virjson.c b/src/util/virjson.c index b49b29b0f..efd6c3a0e 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -905,6 +905,16 @@ virJSONValueObjectGetValue(virJSONValuePtr object, bool +virJSONValueIsObject(virJSONValuePtr object) +{ + if (object) + return object->type =3D=3D VIR_JSON_TYPE_OBJECT; + else + return NULL; +} + + +bool virJSONValueIsArray(virJSONValuePtr array) { return array->type =3D=3D VIR_JSON_TYPE_ARRAY; diff --git a/src/util/virjson.h b/src/util/virjson.h index 14b74c061..c9d9752de 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -114,6 +114,8 @@ virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr o= bject, const char *key); virJSONValuePtr virJSONValueObjectGetByType(virJSONValuePtr object, const char *key, virJSONType t= ype); +bool virJSONValueIsObject(virJSONValuePtr object); + bool virJSONValueIsArray(virJSONValuePtr array); ssize_t virJSONValueArraySize(const virJSONValue *array); virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int = element); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 149856763786828.387499675549293; Tue, 27 Jun 2017 05:47:17 -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 466F680481; Tue, 27 Jun 2017 12:47:13 +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 EE08C7F367; Tue, 27 Jun 2017 12:47:12 +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 435D41853E33; Tue, 27 Jun 2017 12:47:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RCl2TU023776 for ; Tue, 27 Jun 2017 08:47:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 441478A765; Tue, 27 Jun 2017 12:47:02 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69ADF8A785; Tue, 27 Jun 2017 12:47:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 466F680481 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 466F680481 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:44 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/9] util: Move JSON object deflattening code to json utility file 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.28]); Tue, 27 Jun 2017 12:47:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The code will become more universal so it makes more sense for it to live with the rest of the JSON functions. Reviewed-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virjson.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ src/util/virjson.h | 2 ++ src/util/virstoragefile.c | 65 +------------------------------------------= ---- 4 files changed, 65 insertions(+), 64 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d487b1f43..9f64b8d93 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1931,6 +1931,7 @@ virJSONValueObjectAppendNumberUlong; virJSONValueObjectAppendString; virJSONValueObjectCreate; virJSONValueObjectCreateVArgs; +virJSONValueObjectDeflatten; virJSONValueObjectForeachKeyValue; virJSONValueObjectGet; virJSONValueObjectGetArray; diff --git a/src/util/virjson.c b/src/util/virjson.c index efd6c3a0e..8ab542432 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1965,3 +1965,64 @@ virJSONStringReformat(const char *jsonstr, virJSONValueFree(json); return ret; } + + +static int +virJSONValueObjectDeflattenWorker(const char *key, + virJSONValuePtr value, + void *opaque) +{ + virJSONValuePtr retobj =3D opaque; + virJSONValuePtr newval =3D NULL; + const char *newkey; + + if (!(newkey =3D STRSKIP(key, "file."))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("JSON object is neither nested nor flattened")); + return -1; + } + + if (!(newval =3D virJSONValueCopy(value))) + return -1; + + if (virJSONValueObjectAppend(retobj, newkey, newval) < 0) { + virJSONValueFree(newval); + return -1; + } + + return 0; +} + + +/** + * virJSONValueObjectDeflatten: + * + * In some cases it's possible to nest JSON objects by prefixing object me= mbers + * with the parent object name followed by the dot and then the attribute = name + * rather than directly using a nested value object (e.g qemu's JSON + * pseudo-protocol in backing file definition). + * + * This function will attempt to reverse the process and provide a nested = json + * hierarchy so that the parsers can be kept simple and we still can use t= he + * weird syntax some users might use. + * + * Currently this function will flatten out just the 'file.' prefix into a= new + * tree. Any other syntax will be rejected. + */ +virJSONValuePtr +virJSONValueObjectDeflatten(virJSONValuePtr json) +{ + virJSONValuePtr ret; + + if (!(ret =3D virJSONValueNewObject())) + return NULL; + + if (virJSONValueObjectForeachKeyValue(json, + virJSONValueObjectDeflattenWorke= r, + ret) < 0) { + virJSONValueFree(ret); + return NULL; + } + + return ret; +} diff --git a/src/util/virjson.h b/src/util/virjson.h index c9d9752de..e89a776ab 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -186,4 +186,6 @@ virJSONValuePtr virJSONValueCopy(const virJSONValue *in= ); char *virJSONStringReformat(const char *jsonstr, bool pretty); +virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json); + #endif /* __VIR_JSON_H_ */ diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index f0ed5c6bd..52c5301ff 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3244,69 +3244,6 @@ static const struct virStorageSourceJSONDriverParser= jsonParsers[] =3D { }; -static int -virStorageSourceParseBackingJSONDeflattenWorker(const char *key, - virJSONValuePtr value, - void *opaque) -{ - virJSONValuePtr retobj =3D opaque; - virJSONValuePtr newval =3D NULL; - const char *newkey; - - if (!(newkey =3D STRSKIP(key, "file."))) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("JSON backing file syntax is neither nested nor " - "flattened")); - return -1; - } - - if (!(newval =3D virJSONValueCopy(value))) - return -1; - - if (virJSONValueObjectAppend(retobj, newkey, newval) < 0) { - virJSONValueFree(newval); - return -1; - } - - return 0; -} - - -/** - * virStorageSourceParseBackingJSONDeflatten: - * - * The json: pseudo-protocol syntax in qemu allows multiple approaches to - * describe nesting of the values. This is due to the lax handling of the = string - * in qemu and the fact that internally qemu is flattening the values usin= g '.'. - * - * This allows to specify nested json strings either using nested json obj= ects - * or prefixing object members with the parent object name followed by the= dot. - * - * This function will attempt to reverse the process and provide a nested = json - * hierarchy so that the parsers can be kept simple and we still can use t= he - * weird syntax some users might use. - * - * Currently this function will flatten out just the 'file.' prefix into a= new - * tree. Any other syntax will be rejected. - */ -static virJSONValuePtr -virStorageSourceParseBackingJSONDeflatten(virJSONValuePtr json) -{ - virJSONValuePtr ret; - - if (!(ret =3D virJSONValueNewObject())) - return NULL; - - if (virJSONValueObjectForeachKeyValue(json, - virStorageSourceParseBackingJSON= DeflattenWorker, - ret) < 0) { - virJSONValueFree(ret); - return NULL; - } - - return ret; -} - static int virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, @@ -3320,7 +3257,7 @@ virStorageSourceParseBackingJSONInternal(virStorageSo= urcePtr src, int ret =3D -1; if (!(file =3D virJSONValueObjectGetObject(json, "file"))) { - if (!(fixedroot =3D virStorageSourceParseBackingJSONDeflatten(json= ))) + if (!(fixedroot =3D virJSONValueObjectDeflatten(json))) goto cleanup; file =3D fixedroot; --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 1498567874077180.83342739234945; Tue, 27 Jun 2017 05:51:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10828624B1; Tue, 27 Jun 2017 12:51: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 D8D2483FD7; Tue, 27 Jun 2017 12:51: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 86F7E1853E30; Tue, 27 Jun 2017 12:51:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RCl40I023810 for ; Tue, 27 Jun 2017 08:47:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18EFA8A765; Tue, 27 Jun 2017 12:47:04 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id E72D68A77E; Tue, 27 Jun 2017 12:47:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 10828624B1 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 10828624B1 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:45 +0200 Message-Id: <88eaa9daf840a0362acc69a5192d7b36c5accf79.1498567512.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 4/9] util: json: Don't remove the 'file' subobject when deflattening 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 27 Jun 2017 12:51:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently the function would deflatten the object by dropping the 'file' prefix from the attributes. This does not really scale well or adhere to the documentation. Until we refactor the worker to properly deflatten everything we at least simulate it by adding the "file" wrapper object back. Reviewed-by: John Ferlan --- src/util/virjson.c | 19 +++++++++++++------ src/util/virstoragefile.c | 8 +++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 8ab542432..a8e28cd1b 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -2012,17 +2012,24 @@ virJSONValueObjectDeflattenWorker(const char *key, virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json) { - virJSONValuePtr ret; + virJSONValuePtr deflattened; + virJSONValuePtr ret =3D NULL; - if (!(ret =3D virJSONValueNewObject())) + if (!(deflattened =3D virJSONValueNewObject())) return NULL; if (virJSONValueObjectForeachKeyValue(json, virJSONValueObjectDeflattenWorke= r, - ret) < 0) { - virJSONValueFree(ret); - return NULL; - } + deflattened) < 0) + goto cleanup; + + if (virJSONValueObjectCreate(&ret, "a:file", deflattened, NULL) < 0) + goto cleanup; + + deflattened =3D NULL; + + cleanup: + virJSONValueFree(deflattened); return ret; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 52c5301ff..d24502fbf 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3260,7 +3260,13 @@ virStorageSourceParseBackingJSONInternal(virStorageS= ourcePtr src, if (!(fixedroot =3D virJSONValueObjectDeflatten(json))) goto cleanup; - file =3D fixedroot; + if (!(file =3D virJSONValueObjectGetObject(fixedroot, "file"))) { + str =3D virJSONValueToString(json, false); + virReportError(VIR_ERR_INVALID_ARG, + _("JSON backing volume defintion '%s' lacks 'file' object"= ), + str); + goto cleanup; + } } if (!(drvname =3D virJSONValueObjectGetString(file, "driver"))) { --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 1498567879150658.0742699641681; Tue, 27 Jun 2017 05:51:19 -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 2BEC6C04B92C; Tue, 27 Jun 2017 12:51:16 +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 D7A2387FAF; Tue, 27 Jun 2017 12:51:15 +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 88D491853E33; Tue, 27 Jun 2017 12:51:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RCl6XK023817 for ; Tue, 27 Jun 2017 08:47:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C8608A765; Tue, 27 Jun 2017 12:47:06 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 115A28A784; Tue, 27 Jun 2017 12:47:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2BEC6C04B92C Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2BEC6C04B92C From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:46 +0200 Message-Id: <6fd024b6ffba75503bb8853d659fa83a5fc142de.1498567512.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/9] tests: json: Add test for the deflattening function 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.31]); Tue, 27 Jun 2017 12:51:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a few test cases to verify that the old behaviour does not break and that new one behaves sanely. Reviewed-by: John Ferlan --- tests/virjsondata/deflatten-basic-file-in.json | 8 +++ tests/virjsondata/deflatten-basic-file-out.json | 10 +++ tests/virjsondata/deflatten-basic-generic-in.json | 14 ++++ .../deflatten-concat-double-key-in.json | 7 ++ .../deflatten-concat-double-key-out.json | 9 +++ tests/virjsondata/deflatten-concat-in.json | 5 ++ tests/virjsondata/deflatten-concat-out.json | 9 +++ tests/virjsondata/deflatten-deep-file-in.json | 9 +++ tests/virjsondata/deflatten-deep-file-out.json | 11 ++++ tests/virjsondata/deflatten-deep-generic-in.json | 9 +++ tests/virjsondata/deflatten-double-key-in.json | 4 ++ tests/virjsondata/deflatten-double-key-out.json | 6 ++ tests/virjsondata/deflatten-nested-in.json | 16 +++++ tests/virjsondata/deflatten-nested-out.json | 18 ++++++ tests/virjsondata/deflatten-unflattened-in.json | 12 ++++ tests/virjsondata/deflatten-unflattened-out.json | 14 ++++ tests/virjsontest.c | 74 ++++++++++++++++++= ++++ 17 files changed, 235 insertions(+) create mode 100644 tests/virjsondata/deflatten-basic-file-in.json create mode 100644 tests/virjsondata/deflatten-basic-file-out.json create mode 100644 tests/virjsondata/deflatten-basic-generic-in.json create mode 100644 tests/virjsondata/deflatten-concat-double-key-in.json create mode 100644 tests/virjsondata/deflatten-concat-double-key-out.json create mode 100644 tests/virjsondata/deflatten-concat-in.json create mode 100644 tests/virjsondata/deflatten-concat-out.json create mode 100644 tests/virjsondata/deflatten-deep-file-in.json create mode 100644 tests/virjsondata/deflatten-deep-file-out.json create mode 100644 tests/virjsondata/deflatten-deep-generic-in.json create mode 100644 tests/virjsondata/deflatten-double-key-in.json create mode 100644 tests/virjsondata/deflatten-double-key-out.json create mode 100644 tests/virjsondata/deflatten-nested-in.json create mode 100644 tests/virjsondata/deflatten-nested-out.json create mode 100644 tests/virjsondata/deflatten-unflattened-in.json create mode 100644 tests/virjsondata/deflatten-unflattened-out.json diff --git a/tests/virjsondata/deflatten-basic-file-in.json b/tests/virjson= data/deflatten-basic-file-in.json new file mode 100644 index 000000000..54f8bcd88 --- /dev/null +++ b/tests/virjsondata/deflatten-basic-file-in.json @@ -0,0 +1,8 @@ +{ + "file.int": 1, + "file.string": "string", + "file.object": { + "data":"value", + "foo":"bar" + } +} diff --git a/tests/virjsondata/deflatten-basic-file-out.json b/tests/virjso= ndata/deflatten-basic-file-out.json new file mode 100644 index 000000000..1a48eda54 --- /dev/null +++ b/tests/virjsondata/deflatten-basic-file-out.json @@ -0,0 +1,10 @@ +{ + "file": { + "int": 1, + "string": "string", + "object": { + "data": "value", + "foo": "bar" + } + } +} diff --git a/tests/virjsondata/deflatten-basic-generic-in.json b/tests/virj= sondata/deflatten-basic-generic-in.json new file mode 100644 index 000000000..08304287d --- /dev/null +++ b/tests/virjsondata/deflatten-basic-generic-in.json @@ -0,0 +1,14 @@ +{ + "foo.int": 1, + "bar.int": 1, + "foo.string": "string", + "foo.object": { + "data":"value", + "foo":"bar" + }, + "blurb.string": "string", + "blurb.object": { + "data":"value", + "foo":"bar" + } +} diff --git a/tests/virjsondata/deflatten-concat-double-key-in.json b/tests/= virjsondata/deflatten-concat-double-key-in.json new file mode 100644 index 000000000..5bb020ca9 --- /dev/null +++ b/tests/virjsondata/deflatten-concat-double-key-in.json @@ -0,0 +1,7 @@ +{ + "file.nest":{ + "into":"is already here" + }, + "file.nest.into":2, + "file.nest.there":"too" +} diff --git a/tests/virjsondata/deflatten-concat-double-key-out.json b/tests= /virjsondata/deflatten-concat-double-key-out.json new file mode 100644 index 000000000..5624ef123 --- /dev/null +++ b/tests/virjsondata/deflatten-concat-double-key-out.json @@ -0,0 +1,9 @@ +{ + "file": { + "nest": { + "into": "is already here" + }, + "nest.into": 2, + "nest.there": "too" + } +} diff --git a/tests/virjsondata/deflatten-concat-in.json b/tests/virjsondata= /deflatten-concat-in.json new file mode 100644 index 000000000..91a824375 --- /dev/null +++ b/tests/virjsondata/deflatten-concat-in.json @@ -0,0 +1,5 @@ +{ + "file.nest":{}, + "file.nest.into":2, + "file.nest.there":"too" +} diff --git a/tests/virjsondata/deflatten-concat-out.json b/tests/virjsondat= a/deflatten-concat-out.json new file mode 100644 index 000000000..539d2cc30 --- /dev/null +++ b/tests/virjsondata/deflatten-concat-out.json @@ -0,0 +1,9 @@ +{ + "file": { + "nest": { + + }, + "nest.into": 2, + "nest.there": "too" + } +} diff --git a/tests/virjsondata/deflatten-deep-file-in.json b/tests/virjsond= ata/deflatten-deep-file-in.json new file mode 100644 index 000000000..f1b1586c0 --- /dev/null +++ b/tests/virjsondata/deflatten-deep-file-in.json @@ -0,0 +1,9 @@ +{ + "file.double.nest1":"some", + "file.double.nest2":"more", + "file.double.nest3": { + "even":"objects" + }, + "file.very.deeply.nested.object.chains.nest1":"some", + "file.very.deeply.nested.object.chains.nest2":"stuff" +} diff --git a/tests/virjsondata/deflatten-deep-file-out.json b/tests/virjson= data/deflatten-deep-file-out.json new file mode 100644 index 000000000..a5910c9f7 --- /dev/null +++ b/tests/virjsondata/deflatten-deep-file-out.json @@ -0,0 +1,11 @@ +{ + "file": { + "double.nest1": "some", + "double.nest2": "more", + "double.nest3": { + "even": "objects" + }, + "very.deeply.nested.object.chains.nest1": "some", + "very.deeply.nested.object.chains.nest2": "stuff" + } +} diff --git a/tests/virjsondata/deflatten-deep-generic-in.json b/tests/virjs= ondata/deflatten-deep-generic-in.json new file mode 100644 index 000000000..6a4edfb9b --- /dev/null +++ b/tests/virjsondata/deflatten-deep-generic-in.json @@ -0,0 +1,9 @@ +{ + "foo.double.nest1":"some", + "foo.double.nest2":"more", + "bar.double.nest3": { + "even":"objects" + }, + "foo.very.deeply.nested.object.chains.nest1":"some", + "foo.very.deeply.nested.object.chains.nest2":"stuff" +} diff --git a/tests/virjsondata/deflatten-double-key-in.json b/tests/virjson= data/deflatten-double-key-in.json new file mode 100644 index 000000000..7bca2921b --- /dev/null +++ b/tests/virjsondata/deflatten-double-key-in.json @@ -0,0 +1,4 @@ +{ + "file.nest":1, + "file.nest.into":2 +} diff --git a/tests/virjsondata/deflatten-double-key-out.json b/tests/virjso= ndata/deflatten-double-key-out.json new file mode 100644 index 000000000..ca6766e5b --- /dev/null +++ b/tests/virjsondata/deflatten-double-key-out.json @@ -0,0 +1,6 @@ +{ + "file": { + "nest": 1, + "nest.into": 2 + } +} diff --git a/tests/virjsondata/deflatten-nested-in.json b/tests/virjsondata= /deflatten-nested-in.json new file mode 100644 index 000000000..38e69683e --- /dev/null +++ b/tests/virjsondata/deflatten-nested-in.json @@ -0,0 +1,16 @@ +{ + "file.nest": { + "even.objects":"can", + "even.contain":"some", + "even.more":{ + "deeply.nested":"objects", + "deeply.needing":"deflattening", + "deeply.some.even":"more", + "deeply.some.than":{ + "others.thought.was":"even", + "others.thought.completely":"necessary" + }, + "perhaps":"flat value" + } + } +} diff --git a/tests/virjsondata/deflatten-nested-out.json b/tests/virjsondat= a/deflatten-nested-out.json new file mode 100644 index 000000000..acdcd1fc8 --- /dev/null +++ b/tests/virjsondata/deflatten-nested-out.json @@ -0,0 +1,18 @@ +{ + "file": { + "nest": { + "even.objects": "can", + "even.contain": "some", + "even.more": { + "deeply.nested": "objects", + "deeply.needing": "deflattening", + "deeply.some.even": "more", + "deeply.some.than": { + "others.thought.was": "even", + "others.thought.completely": "necessary" + }, + "perhaps": "flat value" + } + } + } +} diff --git a/tests/virjsondata/deflatten-unflattened-in.json b/tests/virjso= ndata/deflatten-unflattened-in.json new file mode 100644 index 000000000..e8a68fe17 --- /dev/null +++ b/tests/virjsondata/deflatten-unflattened-in.json @@ -0,0 +1,12 @@ +{ + "file.blah": { + "any":"possible", + "combination":{ + "of":"json", + "nested":{ + "objects":"should", + "be":"possible" + } + } + } +} diff --git a/tests/virjsondata/deflatten-unflattened-out.json b/tests/virjs= ondata/deflatten-unflattened-out.json new file mode 100644 index 000000000..c02cb4864 --- /dev/null +++ b/tests/virjsondata/deflatten-unflattened-out.json @@ -0,0 +1,14 @@ +{ + "file": { + "blah": { + "any": "possible", + "combination": { + "of": "json", + "nested": { + "objects": "should", + "be": "possible" + } + } + } + } +} diff --git a/tests/virjsontest.c b/tests/virjsontest.c index b67f68ccb..d69b22bf3 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -9,6 +9,8 @@ #include "virjson.h" #include "testutils.h" +#define VIR_FROM_THIS VIR_FROM_NONE + struct testInfo { const char *doc; const char *expect; @@ -312,6 +314,65 @@ testJSONCopy(const void *data) static int +testJSONDeflatten(const void *data) +{ + const struct testInfo *info =3D data; + virJSONValuePtr injson =3D NULL; + virJSONValuePtr deflattened =3D NULL; + char *infile =3D NULL; + char *indata =3D NULL; + char *outfile =3D NULL; + char *actual =3D NULL; + int ret =3D -1; + + if (virAsprintf(&infile, "%s/virjsondata/deflatten-%s-in.json", + abs_srcdir, info->doc) < 0 || + virAsprintf(&outfile, "%s/virjsondata/deflatten-%s-out.json", + abs_srcdir, info->doc) < 0) + goto cleanup; + + if (virTestLoadFile(infile, &indata) < 0) + goto cleanup; + + if (!(injson =3D virJSONValueFromString(indata))) + goto cleanup; + + if ((deflattened =3D virJSONValueObjectDeflatten(injson))) { + if (!info->pass) { + if (virTestGetVerbose()) + fprintf(stderr, "deflattening should have failed\n"); + + goto cleanup; + } + } else { + if (!info->pass) + ret =3D 0; + + goto cleanup; + } + + if (!(actual =3D virJSONValueToString(deflattened, true))) + goto cleanup; + + if (virTestCompareToFile(actual, outfile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virJSONValueFree(injson); + virJSONValueFree(deflattened); + VIR_FREE(infile); + VIR_FREE(outfile); + VIR_FREE(outfile); + VIR_FREE(actual); + + return ret; + +} + + +static int mymain(void) { int ret =3D 0; @@ -448,6 +509,19 @@ mymain(void) "{ \"a\": {}, \"b\": 1, \"c\": \"str\", \"d\": [] }", NULL, true); +#define DO_TEST_DEFLATTEN(name, pass) \ + DO_TEST_FULL(name, Deflatten, name, NULL, pass) + + DO_TEST_DEFLATTEN("unflattened", true); + DO_TEST_DEFLATTEN("basic-file", true); + DO_TEST_DEFLATTEN("basic-generic", false); + DO_TEST_DEFLATTEN("deep-file", true); + DO_TEST_DEFLATTEN("deep-generic", false); + DO_TEST_DEFLATTEN("nested", true); + DO_TEST_DEFLATTEN("double-key", true); + DO_TEST_DEFLATTEN("concat", true); + DO_TEST_DEFLATTEN("concat-double-key", true); + return (ret =3D=3D 0) ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 1498568134949245.25711086651836; Tue, 27 Jun 2017 05:55:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CB003DBE9; Tue, 27 Jun 2017 12:55:30 +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 62976843A9; Tue, 27 Jun 2017 12:55: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 131361853E31; Tue, 27 Jun 2017 12:55:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RClEaJ023835 for ; Tue, 27 Jun 2017 08:47:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 362AD8A784; Tue, 27 Jun 2017 12:47:14 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id B87338A788; Tue, 27 Jun 2017 12:47:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8CB003DBE9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8CB003DBE9 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:47 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 6/9] util: json: Properly implement JSON deflattening 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 27 Jun 2017 12:55:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As it turns out sometimes users pass in an arbitrarily nested structure e.g. for the qemu backing chains JSON pseudo protocol. This new implementation deflatens now a single object fully even with nested keys. Additionally it's not necessary now to stick with the "file." prefix for the properties. Reviewed-by: John Ferlan --- src/util/virjson.c | 67 ++++++++++++++++--= ---- tests/virjsondata/deflatten-basic-generic-out.json | 20 +++++++ .../deflatten-concat-double-key-out.json | 9 --- tests/virjsondata/deflatten-concat-out.json | 7 +-- tests/virjsondata/deflatten-deep-file-out.json | 24 ++++++-- tests/virjsondata/deflatten-deep-generic-out.json | 27 +++++++++ tests/virjsondata/deflatten-double-key-out.json | 6 -- tests/virjsontest.c | 8 +-- 8 files changed, 121 insertions(+), 47 deletions(-) create mode 100644 tests/virjsondata/deflatten-basic-generic-out.json delete mode 100644 tests/virjsondata/deflatten-concat-double-key-out.json create mode 100644 tests/virjsondata/deflatten-deep-generic-out.json delete mode 100644 tests/virjsondata/deflatten-double-key-out.json diff --git a/src/util/virjson.c b/src/util/virjson.c index a8e28cd1b..635b78e3a 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1974,23 +1974,60 @@ virJSONValueObjectDeflattenWorker(const char *key, { virJSONValuePtr retobj =3D opaque; virJSONValuePtr newval =3D NULL; - const char *newkey; + virJSONValuePtr existobj; + char **tokens =3D NULL; + size_t ntokens =3D 0; + int ret =3D -1; - if (!(newkey =3D STRSKIP(key, "file."))) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("JSON object is neither nested nor flattened")); - return -1; + /* non-nested keys only need to be copied */ + if (!strchr(key, '.')) { + if (!(newval =3D virJSONValueCopy(value))) + return -1; + + if (virJSONValueObjectHasKey(retobj, key)) { + virReportError(VIR_ERR_INVALID_ARG, + _("can't deflatten colliding key '%s'"), key); + goto cleanup; + } + + if (virJSONValueObjectAppend(retobj, key, newval) < 0) + goto cleanup; + + return 0; } - if (!(newval =3D virJSONValueCopy(value))) - return -1; + if (!(tokens =3D virStringSplitCount(key, ".", 2, &ntokens))) + goto cleanup; - if (virJSONValueObjectAppend(retobj, newkey, newval) < 0) { - virJSONValueFree(newval); - return -1; + if (ntokens !=3D 2) { + virReportError(VIR_ERR_INVALID_ARG, + _("invalid nested value key '%s'"), key); + goto cleanup; } - return 0; + if (!(existobj =3D virJSONValueObjectGet(retobj, tokens[0]))) { + if (!(existobj =3D virJSONValueNewObject())) + goto cleanup; + + if (virJSONValueObjectAppend(retobj, tokens[0], existobj) < 0) + goto cleanup; + + } else { + if (!virJSONValueIsObject(existobj)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("mixing nested objects and values is forbidde= n in " + "JSON deflattening")); + goto cleanup; + } + } + + ret =3D virJSONValueObjectDeflattenWorker(tokens[1], value, existobj); + + cleanup: + virStringListFreeCount(tokens, ntokens); + virJSONValueFree(newval); + + return ret; } @@ -2005,9 +2042,6 @@ virJSONValueObjectDeflattenWorker(const char *key, * This function will attempt to reverse the process and provide a nested = json * hierarchy so that the parsers can be kept simple and we still can use t= he * weird syntax some users might use. - * - * Currently this function will flatten out just the 'file.' prefix into a= new - * tree. Any other syntax will be rejected. */ virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json) @@ -2023,10 +2057,7 @@ virJSONValueObjectDeflatten(virJSONValuePtr json) deflattened) < 0) goto cleanup; - if (virJSONValueObjectCreate(&ret, "a:file", deflattened, NULL) < 0) - goto cleanup; - - deflattened =3D NULL; + VIR_STEAL_PTR(ret, deflattened); cleanup: virJSONValueFree(deflattened); diff --git a/tests/virjsondata/deflatten-basic-generic-out.json b/tests/vir= jsondata/deflatten-basic-generic-out.json new file mode 100644 index 000000000..ab639aa48 --- /dev/null +++ b/tests/virjsondata/deflatten-basic-generic-out.json @@ -0,0 +1,20 @@ +{ + "foo": { + "int": 1, + "string": "string", + "object": { + "data": "value", + "foo": "bar" + } + }, + "bar": { + "int": 1 + }, + "blurb": { + "string": "string", + "object": { + "data": "value", + "foo": "bar" + } + } +} diff --git a/tests/virjsondata/deflatten-concat-double-key-out.json b/tests= /virjsondata/deflatten-concat-double-key-out.json deleted file mode 100644 index 5624ef123..000000000 --- a/tests/virjsondata/deflatten-concat-double-key-out.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "file": { - "nest": { - "into": "is already here" - }, - "nest.into": 2, - "nest.there": "too" - } -} diff --git a/tests/virjsondata/deflatten-concat-out.json b/tests/virjsondat= a/deflatten-concat-out.json index 539d2cc30..be417e53a 100644 --- a/tests/virjsondata/deflatten-concat-out.json +++ b/tests/virjsondata/deflatten-concat-out.json @@ -1,9 +1,8 @@ { "file": { "nest": { - - }, - "nest.into": 2, - "nest.there": "too" + "into": 2, + "there": "too" + } } } diff --git a/tests/virjsondata/deflatten-deep-file-out.json b/tests/virjson= data/deflatten-deep-file-out.json index a5910c9f7..d4614eeaf 100644 --- a/tests/virjsondata/deflatten-deep-file-out.json +++ b/tests/virjsondata/deflatten-deep-file-out.json @@ -1,11 +1,23 @@ { "file": { - "double.nest1": "some", - "double.nest2": "more", - "double.nest3": { - "even": "objects" + "double": { + "nest1": "some", + "nest2": "more", + "nest3": { + "even": "objects" + } }, - "very.deeply.nested.object.chains.nest1": "some", - "very.deeply.nested.object.chains.nest2": "stuff" + "very": { + "deeply": { + "nested": { + "object": { + "chains": { + "nest1": "some", + "nest2": "stuff" + } + } + } + } + } } } diff --git a/tests/virjsondata/deflatten-deep-generic-out.json b/tests/virj= sondata/deflatten-deep-generic-out.json new file mode 100644 index 000000000..7ea521a8f --- /dev/null +++ b/tests/virjsondata/deflatten-deep-generic-out.json @@ -0,0 +1,27 @@ +{ + "foo": { + "double": { + "nest1": "some", + "nest2": "more" + }, + "very": { + "deeply": { + "nested": { + "object": { + "chains": { + "nest1": "some", + "nest2": "stuff" + } + } + } + } + } + }, + "bar": { + "double": { + "nest3": { + "even": "objects" + } + } + } +} diff --git a/tests/virjsondata/deflatten-double-key-out.json b/tests/virjso= ndata/deflatten-double-key-out.json deleted file mode 100644 index ca6766e5b..000000000 --- a/tests/virjsondata/deflatten-double-key-out.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "file": { - "nest": 1, - "nest.into": 2 - } -} diff --git a/tests/virjsontest.c b/tests/virjsontest.c index d69b22bf3..b3ce6591a 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -514,13 +514,13 @@ mymain(void) DO_TEST_DEFLATTEN("unflattened", true); DO_TEST_DEFLATTEN("basic-file", true); - DO_TEST_DEFLATTEN("basic-generic", false); + DO_TEST_DEFLATTEN("basic-generic", true); DO_TEST_DEFLATTEN("deep-file", true); - DO_TEST_DEFLATTEN("deep-generic", false); + DO_TEST_DEFLATTEN("deep-generic", true); DO_TEST_DEFLATTEN("nested", true); - DO_TEST_DEFLATTEN("double-key", true); + DO_TEST_DEFLATTEN("double-key", false); DO_TEST_DEFLATTEN("concat", true); - DO_TEST_DEFLATTEN("concat-double-key", true); + DO_TEST_DEFLATTEN("concat-double-key", false); return (ret =3D=3D 0) ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 149856764789582.33977213214985; Tue, 27 Jun 2017 05:47:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91E29104D5; Tue, 27 Jun 2017 12:47:24 +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 5B66F83FDB; Tue, 27 Jun 2017 12:47:24 +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 064F33FAE1; Tue, 27 Jun 2017 12:47:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RClJqH023845 for ; Tue, 27 Jun 2017 08:47:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B8648A78C; Tue, 27 Jun 2017 12:47:19 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 795738A78F; Tue, 27 Jun 2017 12:47:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91E29104D5 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 91E29104D5 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:48 +0200 Message-Id: <1f59c9bbf21a89a3850db1cef96c036ec53ff980.1498567512.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 7/9] util: json: Recursively deflatten objects virJSONValueObjectDeflatten 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 27 Jun 2017 12:47:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If a value of the first level object contains more objects needing deflattening which would be wrapped in an actual object the function would not recurse into them. By this simple addition we can fully deflatten the objects. Reviewed-by: John Ferlan --- src/util/virjson.c | 8 +++++++- tests/virjsondata/deflatten-nested-out.json | 32 +++++++++++++++++++------= ---- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 635b78e3a..0c7beafab 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1981,7 +1981,13 @@ virJSONValueObjectDeflattenWorker(const char *key, /* non-nested keys only need to be copied */ if (!strchr(key, '.')) { - if (!(newval =3D virJSONValueCopy(value))) + + if (virJSONValueIsObject(value)) + newval =3D virJSONValueObjectDeflatten(value); + else + newval =3D virJSONValueCopy(value); + + if (!newval) return -1; if (virJSONValueObjectHasKey(retobj, key)) { diff --git a/tests/virjsondata/deflatten-nested-out.json b/tests/virjsondat= a/deflatten-nested-out.json index acdcd1fc8..f23ed8fd5 100644 --- a/tests/virjsondata/deflatten-nested-out.json +++ b/tests/virjsondata/deflatten-nested-out.json @@ -1,17 +1,27 @@ { "file": { "nest": { - "even.objects": "can", - "even.contain": "some", - "even.more": { - "deeply.nested": "objects", - "deeply.needing": "deflattening", - "deeply.some.even": "more", - "deeply.some.than": { - "others.thought.was": "even", - "others.thought.completely": "necessary" - }, - "perhaps": "flat value" + "even": { + "objects": "can", + "contain": "some", + "more": { + "deeply": { + "nested": "objects", + "needing": "deflattening", + "some": { + "even": "more", + "than": { + "others": { + "thought": { + "was": "even", + "completely": "necessary" + } + } + } + } + }, + "perhaps": "flat value" + } } } } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 1498568137922914.3406291131203; Tue, 27 Jun 2017 05:55:37 -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 E966A7D0FF; Tue, 27 Jun 2017 12:55:35 +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 C312F87F96; Tue, 27 Jun 2017 12:55:35 +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 55C691853E34; Tue, 27 Jun 2017 12:55:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RClVkO023859 for ; Tue, 27 Jun 2017 08:47:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id C60ED8A768; Tue, 27 Jun 2017 12:47:31 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id D05A48A791; Tue, 27 Jun 2017 12:47:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E966A7D0FF Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E966A7D0FF From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:49 +0200 Message-Id: <747b9b83feacd16ce25a099668e799740888c99a.1498567512.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 8/9] util: storage: Always deflatten JSON pseudo-protocol objects 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.27]); Tue, 27 Jun 2017 12:55:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that the JSON deflattener is working sanely we can always attempt the deflattening so that we can then parse the tree as expected. Reviewed-by: John Ferlan --- src/util/virstoragefile.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d24502fbf..f3dc860ae 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3249,24 +3249,22 @@ static int virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, virJSONValuePtr json) { - virJSONValuePtr fixedroot =3D NULL; + virJSONValuePtr deflattened =3D NULL; virJSONValuePtr file; const char *drvname; char *str =3D NULL; size_t i; int ret =3D -1; - if (!(file =3D virJSONValueObjectGetObject(json, "file"))) { - if (!(fixedroot =3D virJSONValueObjectDeflatten(json))) - goto cleanup; + if (!(deflattened =3D virJSONValueObjectDeflatten(json))) + goto cleanup; - if (!(file =3D virJSONValueObjectGetObject(fixedroot, "file"))) { - str =3D virJSONValueToString(json, false); - virReportError(VIR_ERR_INVALID_ARG, - _("JSON backing volume defintion '%s' lacks 'file' object"= ), - str); - goto cleanup; - } + if (!(file =3D virJSONValueObjectGetObject(deflattened, "file"))) { + str =3D virJSONValueToString(json, false); + virReportError(VIR_ERR_INVALID_ARG, + _("JSON backing volume defintion '%s' lacks 'file' object"), + str); + goto cleanup; } if (!(drvname =3D virJSONValueObjectGetString(file, "driver"))) { @@ -3290,7 +3288,7 @@ virStorageSourceParseBackingJSONInternal(virStorageSo= urcePtr src, cleanup: VIR_FREE(str); - virJSONValueFree(fixedroot); + virJSONValueFree(deflattened); return ret; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 08:35:54 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.zoho.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 1498567661638714.2669548813736; Tue, 27 Jun 2017 05:47:41 -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 44E2564D28; Tue, 27 Jun 2017 12:47:36 +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 00CC08A78A; Tue, 27 Jun 2017 12:47:35 +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 9BF771853E30; Tue, 27 Jun 2017 12:47:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RClYKA023870 for ; Tue, 27 Jun 2017 08:47:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C6088A779; Tue, 27 Jun 2017 12:47:34 +0000 (UTC) Received: from andariel.redhat.com (ovpn-204-24.brq.redhat.com [10.40.204.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEC6D8A768; Tue, 27 Jun 2017 12:47:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 44E2564D28 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 44E2564D28 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 14:46:50 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 9/9] tests: Validate that JSON deflattening fixed nested json pseudo-protocol strings 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.39]); Tue, 27 Jun 2017 12:47:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Sheepdog and possibly others use nested objects for network server and thus could be specified in a way that libvirt would not parse. Validates that https://bugzilla.redhat.com/show_bug.cgi?id=3D1464821 is fixed properly. Reviewed-by: John Ferlan --- tests/virjsondata/deflatten-qemu-sheepdog-in.json | 11 +++++++++++ tests/virjsondata/deflatten-qemu-sheepdog-out.json | 13 +++++++++++++ tests/virjsontest.c | 1 + tests/virstoragetest.c | 10 ++++++++++ 4 files changed, 35 insertions(+) create mode 100644 tests/virjsondata/deflatten-qemu-sheepdog-in.json create mode 100644 tests/virjsondata/deflatten-qemu-sheepdog-out.json diff --git a/tests/virjsondata/deflatten-qemu-sheepdog-in.json b/tests/virj= sondata/deflatten-qemu-sheepdog-in.json new file mode 100644 index 000000000..7c0286300 --- /dev/null +++ b/tests/virjsondata/deflatten-qemu-sheepdog-in.json @@ -0,0 +1,11 @@ +{ + "driver": "raw", + "file": { + "server.host": "10.10.10.10", + "server.port": "7000", + "tag": "", + "driver": "sheepdog", + "server.type": "inet", + "vdi": "Alice" + } +} diff --git a/tests/virjsondata/deflatten-qemu-sheepdog-out.json b/tests/vir= jsondata/deflatten-qemu-sheepdog-out.json new file mode 100644 index 000000000..258b44a76 --- /dev/null +++ b/tests/virjsondata/deflatten-qemu-sheepdog-out.json @@ -0,0 +1,13 @@ +{ + "driver": "raw", + "file": { + "server": { + "host": "10.10.10.10", + "port": "7000", + "type": "inet" + }, + "tag": "", + "driver": "sheepdog", + "vdi": "Alice" + } +} diff --git a/tests/virjsontest.c b/tests/virjsontest.c index b3ce6591a..5f89a3e1c 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -521,6 +521,7 @@ mymain(void) DO_TEST_DEFLATTEN("double-key", false); DO_TEST_DEFLATTEN("concat", true); DO_TEST_DEFLATTEN("concat-double-key", false); + DO_TEST_DEFLATTEN("qemu-sheepdog", true); return (ret =3D=3D 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index f34408395..90fcf36ca 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1575,6 +1575,16 @@ mymain(void) "\n" " \n" "\n"); + TEST_BACKING_PARSE("json:{\"driver\": \"raw\"," + "\"file\": {\"server.host\": \"10.10.10.10\"," + "\"server.port\": \"7000\"," + "\"tag\": \"\"," + "\"driver\": \"sheepdog\"," + "\"server.type\": \"inet\"," + "\"vdi\": \"Alice\"}}", + "\n" + " \n" + "\n"); #endif /* WITH_YAJL */ cleanup: --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list