[libvirt] [PATCH 30/35] tests: qemublock: Add test for raw luks disk format

Peter Krempa posted 35 patches 7 years ago
[libvirt] [PATCH 30/35] tests: qemublock: Add test for raw luks disk format
Posted by Peter Krempa 7 years ago
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=/path/luks.img,key-secret=test1-encalias,format=luks,if=none,id=drive-dummy
-device virtio-blk-pci,scsi=off,drive=drive-dummy,id=dummy

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 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 testQemuDiskXMLToJSONData *data)
 }


+static int
+testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src)
+{
+    qemuDomainStorageSourcePrivatePtr srcpriv;
+
+    if (!src->privateData &&
+        !(src->privateData = qemuDomainStorageSourcePrivateNew()))
+        return -1;
+
+    srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
+
+    if (src->auth) {
+        if (VIR_ALLOC(srcpriv->secinfo) < 0)
+            return -1;
+
+        srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
+        if (VIR_STRDUP(srcpriv->secinfo->s.aes.username, src->auth->username) < 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 = 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 = abs_srcdir "/qemublocktestdata/xml2json/";

 static int
@@ -180,6 +218,9 @@ testQemuDiskXMLToProps(const void *opaque)
         goto cleanup;

     for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
+        if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
+            goto cleanup;
+
         if (!(props = 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/qemublocktestdata/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/qemublocktestdata/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 @@
+<disk device='disk'>
+  <driver name='qemu' type='raw'/>
+  <source file='/path/luks.img'>
+    <encryption format='luks'>
+      <secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f'/>
+    </encryption>
+    <privateData>
+      <nodenames>
+        <nodename type='storage' name='test2'/>
+        <nodename type='format' name='test1'/>
+      </nodenames>
+    </privateData>
+  </source>
+  <target dev='vda'/>
+</disk>
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 30/35] tests: qemublock: Add test for raw luks disk format
Posted by John Ferlan 7 years ago

On 04/25/2018 11:15 AM, Peter Krempa wrote:
> 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=/path/luks.img,key-secret=test1-encalias,format=luks,if=none,id=drive-dummy
> -device virtio-blk-pci,scsi=off,drive=drive-dummy,id=dummy
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  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
> 

Later on auth gets tested, so that's fine. Unless you want to make a
"simple" auth test to partner with this simple luks encryption one.

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 30/35] tests: qemublock: Add test for raw luks disk format
Posted by Peter Krempa 7 years ago
On Wed, May 02, 2018 at 19:07:27 -0400, John Ferlan wrote:
> 
> 
> On 04/25/2018 11:15 AM, Peter Krempa wrote:
> > 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=/path/luks.img,key-secret=test1-encalias,format=luks,if=none,id=drive-dummy
> > -device virtio-blk-pci,scsi=off,drive=drive-dummy,id=dummy
> > 
> > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> > ---
> >  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
> > 
> 
> Later on auth gets tested, so that's fine. Unless you want to make a
> "simple" auth test to partner with this simple luks encryption one.

My motivation here was to add a simple case along with the code faking
the authentication/encryption data, so that it can be seen and then add
the cases separately.

Also this is an artifact of approach I took while implementing it. I
originally added this case to test the implementation of encryption I've
done. Later when I implemented everything I've added the full test.

> 
> Reviewed-by: John Ferlan <jferlan@redhat.com>
> 
> John
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list