From nobody Wed May 14 10:49:39 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 1524669768048682.5376305248192; Wed, 25 Apr 2018 08:22:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6773585543; Wed, 25 Apr 2018 15:22:46 +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 EDE272010CA1; Wed, 25 Apr 2018 15:22:45 +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 F11754CAB4; Wed, 25 Apr 2018 15:22:44 +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 w3PFGJWn020619 for ; Wed, 25 Apr 2018 11:16:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E101202323A; Wed, 25 Apr 2018 15:16:19 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05FF42023430; Wed, 25 Apr 2018 15:16:18 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 25 Apr 2018 17:15:38 +0200 Message-Id: <168ab335312906ebc10d297875db5002e310f07e.1524668969.git.pkrempa@redhat.com> 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 30/35] tests: qemublock: Add test for raw luks disk format 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 25 Apr 2018 15:22:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Apart from adding test data add a function which sets up fake secrets for the test. The top level disk image would generate the following '-drive' cmdline: -drive file=3D/path/luks.img,key-secret=3Dtest1-encalias,format=3Dluks,if= =3Dnone,id=3Ddrive-dummy -device virtio-blk-pci,scsi=3Doff,drive=3Ddrive-dummy,id=3Ddummy Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- tests/qemublocktest.c | 42 ++++++++++++++++++= ++++ .../qemublocktestdata/xml2json/file-raw-luks.json | 13 +++++++ tests/qemublocktestdata/xml2json/file-raw-luks.xml | 15 ++++++++ 3 files changed, 70 insertions(+) create mode 100644 tests/qemublocktestdata/xml2json/file-raw-luks.json create mode 100644 tests/qemublocktestdata/xml2json/file-raw-luks.xml diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index a79ffa90d8..55d028e9fb 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -145,6 +145,44 @@ testQemuDiskXMLToPropsClear(struct testQemuDiskXMLToJS= ONData *data) } +static int +testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src) +{ + qemuDomainStorageSourcePrivatePtr srcpriv; + + if (!src->privateData && + !(src->privateData =3D qemuDomainStorageSourcePrivateNew())) + return -1; + + srcpriv =3D QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); + + if (src->auth) { + if (VIR_ALLOC(srcpriv->secinfo) < 0) + return -1; + + srcpriv->secinfo->type =3D VIR_DOMAIN_SECRET_INFO_TYPE_AES; + if (VIR_STRDUP(srcpriv->secinfo->s.aes.username, src->auth->userna= me) < 0) + return -1; + + if (virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias", + NULLSTR(src->nodestorage)) < 0) + return -1; + } + + if (src->encryption) { + if (VIR_ALLOC(srcpriv->encinfo) < 0) + return -1; + + srcpriv->encinfo->type =3D VIR_DOMAIN_SECRET_INFO_TYPE_AES; + if (virAsprintf(&srcpriv->encinfo->s.aes.alias, "%s-encalias", + NULLSTR(src->nodeformat)) < 0) + return -1; + } + + return 0; +} + + static const char *testQemuDiskXMLToJSONPath =3D abs_srcdir "/qemublocktes= tdata/xml2json/"; static int @@ -180,6 +218,9 @@ testQemuDiskXMLToProps(const void *opaque) goto cleanup; for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backingSt= ore) { + if (testQemuDiskXMLToJSONFakeSecrets(n) < 0) + goto cleanup; + if (!(props =3D qemuBlockStorageSourceGetBlockdevProps(n))) { if (!data->fail) { VIR_TEST_VERBOSE("failed to generate qemu blockdev props\n= "); @@ -418,6 +459,7 @@ mymain(void) TEST_DISK_TO_JSON("dir-fat-floppy"); TEST_DISK_TO_JSON("file-raw-aio_native"); TEST_DISK_TO_JSON("file-backing_basic-aio_threads"); + TEST_DISK_TO_JSON("file-raw-luks"); cleanup: virHashFree(diskxmljsondata.schema); diff --git a/tests/qemublocktestdata/xml2json/file-raw-luks.json b/tests/qe= mublocktestdata/xml2json/file-raw-luks.json new file mode 100644 index 0000000000..e3d9c4c26b --- /dev/null +++ b/tests/qemublocktestdata/xml2json/file-raw-luks.json @@ -0,0 +1,13 @@ +{ + "node-name": "test1", + "read-only": false, + "driver": "luks", + "key-secret": "test1-encalias", + "file": { + "driver": "file", + "filename": "/path/luks.img", + "node-name": "test2", + "read-only": false, + "discard": "unmap" + } +} diff --git a/tests/qemublocktestdata/xml2json/file-raw-luks.xml b/tests/qem= ublocktestdata/xml2json/file-raw-luks.xml new file mode 100644 index 0000000000..f446b03bdb --- /dev/null +++ b/tests/qemublocktestdata/xml2json/file-raw-luks.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list