[PATCH v2 13/13] tests: add qcow2 data-file basic tests to qemublocktest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nikolai Barybin <nikolai.barybin@xxxxxxxxxxxxx>
---
 tests/qemublocktest.c                         | 78 +++++++++++--------
 ...backing-with-data-file-noopts-srconly.json | 27 +++++++
 ...e-qcow2-backing-with-data-file-noopts.json | 41 ++++++++++
 ...le-qcow2-backing-with-data-file-noopts.xml | 35 +++++++++
 .../file-qcow2-data-file-noopts-srconly.json  | 18 +++++
 .../xml2json/file-qcow2-data-file-noopts.json | 27 +++++++
 .../xml2json/file-qcow2-data-file-noopts.xml  | 24 ++++++
 7 files changed, 219 insertions(+), 31 deletions(-)
 create mode 100644 tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts-srconly.json
 create mode 100644 tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.json
 create mode 100644 tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.xml
 create mode 100644 tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts-srconly.json
 create mode 100644 tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.json
 create mode 100644 tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.xml

diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index c581bd1748..46c080fb3b 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -247,6 +247,48 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSource *src)
 
 static const char *testQemuDiskXMLToJSONPath = abs_srcdir "/qemublocktestdata/xml2json/";
 
+static int
+testQemuDiskXMLToPropsCollectDataOne(virStorageSource *src,
+                                     virDomainDiskDef *disk,
+                                     struct testQemuDiskXMLToJSONData *data)
+{
+    g_autofree char *backingstore = NULL;
+    g_autoptr(virJSONValue) formatProps = NULL;
+    g_autoptr(virJSONValue) storageProps = NULL;
+    g_autoptr(virJSONValue) storageSrcOnlyProps = NULL;
+
+    if (testQemuDiskXMLToJSONFakeSecrets(src) < 0)
+        return -1;
+
+    if (qemuDomainValidateStorageSource(src, data->qemuCaps) < 0)
+        return -1;
+
+    qemuDomainPrepareDiskSourceData(disk, src);
+
+    if (!(formatProps = qemuBlockStorageSourceGetFormatProps(src, src->backingStore)) ||
+        !(storageSrcOnlyProps = qemuBlockStorageSourceGetBackendProps(src, QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY)) ||
+        !(storageProps = qemuBlockStorageSourceGetBackendProps(src, 0)) ||
+        !(backingstore = qemuBlockGetBackingStoreString(src, true))) {
+        if (!data->fail) {
+            VIR_TEST_VERBOSE("failed to generate qemu blockdev props");
+            return -1;
+        }
+    } else if (data->fail) {
+        VIR_TEST_VERBOSE("qemu blockdev props should have failed");
+        return -1;
+    }
+
+    VIR_REALLOC_N(data->images, data->nimages + 1);
+
+    data->images[data->nimages].formatprops = g_steal_pointer(&formatProps);
+    data->images[data->nimages].storageprops = g_steal_pointer(&storageProps);
+    data->images[data->nimages].storagepropssrc = g_steal_pointer(&storageSrcOnlyProps);
+    data->images[data->nimages].backingstore = g_steal_pointer(&backingstore);
+
+    data->nimages++;
+    return 0;
+}
+
 static int
 testQemuDiskXMLToProps(const void *opaque)
 {
@@ -254,9 +296,6 @@ testQemuDiskXMLToProps(const void *opaque)
     g_autoptr(virDomainDef) vmdef = NULL;
     virDomainDiskDef *disk = NULL;
     virStorageSource *n;
-    g_autoptr(virJSONValue) formatProps = NULL;
-    g_autoptr(virJSONValue) storageProps = NULL;
-    g_autoptr(virJSONValue) storageSrcOnlyProps = NULL;
     g_autofree char *xmlpath = NULL;
     g_autofree char *xmlstr = NULL;
 
@@ -284,37 +323,12 @@ testQemuDiskXMLToProps(const void *opaque)
     }
 
     for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
-        g_autofree char *backingstore = NULL;
-
-        if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
-            return -1;
-
-        if (qemuDomainValidateStorageSource(n, data->qemuCaps) < 0)
+        if (testQemuDiskXMLToPropsCollectDataOne(n, disk, data) < 0)
             return -1;
 
-        qemuDomainPrepareDiskSourceData(disk, n);
-
-        if (!(formatProps = qemuBlockStorageSourceGetFormatProps(n, n->backingStore)) ||
-            !(storageSrcOnlyProps = qemuBlockStorageSourceGetBackendProps(n, QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY)) ||
-            !(storageProps = qemuBlockStorageSourceGetBackendProps(n, 0)) ||
-            !(backingstore = qemuBlockGetBackingStoreString(n, true))) {
-            if (!data->fail) {
-                VIR_TEST_VERBOSE("failed to generate qemu blockdev props");
-                return -1;
-            }
-        } else if (data->fail) {
-            VIR_TEST_VERBOSE("qemu blockdev props should have failed");
+        if (n->dataFileStore &&
+            testQemuDiskXMLToPropsCollectDataOne(n->dataFileStore, disk, data) < 0)
             return -1;
-        }
-
-        VIR_REALLOC_N(data->images, data->nimages + 1);
-
-        data->images[data->nimages].formatprops = g_steal_pointer(&formatProps);
-        data->images[data->nimages].storageprops = g_steal_pointer(&storageProps);
-        data->images[data->nimages].storagepropssrc = g_steal_pointer(&storageSrcOnlyProps);
-        data->images[data->nimages].backingstore = g_steal_pointer(&backingstore);
-
-        data->nimages++;
     }
 
     return 0;
@@ -1123,6 +1137,8 @@ mymain(void)
     TEST_DISK_TO_JSON("file-qcow2-backing-chain-unterminated");
     TEST_DISK_TO_JSON("file-qcow2-backing-chain-encryption");
     TEST_DISK_TO_JSON("network-qcow2-backing-chain-encryption_auth");
+    TEST_DISK_TO_JSON("file-qcow2-data-file-noopts");
+    TEST_DISK_TO_JSON("file-qcow2-backing-with-data-file-noopts");
 
     TEST_DISK_TO_JSON("file-backing_basic-unmap");
     TEST_DISK_TO_JSON("file-backing_basic-unmap-detect");
diff --git a/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts-srconly.json b/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts-srconly.json
new file mode 100644
index 0000000000..1621b4b0fc
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts-srconly.json
@@ -0,0 +1,27 @@
+(
+  source only properties:
+  {
+    "driver": "file",
+    "filename": "/var/lib/libvirt/images/rhel7.3.1507297895"
+  }
+  backing store string:
+  /var/lib/libvirt/images/rhel7.3.1507297895
+)
+(
+  source only properties:
+  {
+    "driver": "file",
+    "filename": "/var/lib/libvirt/images/rhel7.3.1484071872"
+  }
+  backing store string:
+  /var/lib/libvirt/images/rhel7.3.1484071872
+)
+(
+  source only properties:
+  {
+    "driver": "file",
+    "filename": "/var/lib/libvirt/images/rhel7.3.1483615252"
+  }
+  backing store string:
+  /var/lib/libvirt/images/rhel7.3.1483615252
+)
diff --git a/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.json b/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.json
new file mode 100644
index 0000000000..b78848ddea
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.json
@@ -0,0 +1,41 @@
+{
+  "node-name": "#block126",
+  "read-only": false,
+  "driver": "qcow2",
+  "file": "#block004",
+  "backing": "#block313"
+}
+{
+  "driver": "file",
+  "filename": "/var/lib/libvirt/images/rhel7.3.1507297895",
+  "node-name": "#block004",
+  "auto-read-only": true,
+  "discard": "unmap"
+}
+{
+  "node-name": "#block313",
+  "read-only": true,
+  "driver": "qcow2",
+  "data-file": "#block556",
+  "file": "#block256"
+}
+{
+  "driver": "file",
+  "filename": "/var/lib/libvirt/images/rhel7.3.1484071872",
+  "node-name": "#block256",
+  "auto-read-only": true,
+  "discard": "unmap"
+}
+{
+  "node-name": "#block556",
+  "read-only": true,
+  "driver": "raw",
+  "file": "#block418"
+}
+{
+  "driver": "file",
+  "filename": "/var/lib/libvirt/images/rhel7.3.1483615252",
+  "node-name": "#block418",
+  "auto-read-only": true,
+  "discard": "unmap"
+}
diff --git a/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.xml b/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.xml
new file mode 100644
index 0000000000..4fd561b8bf
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-qcow2-backing-with-data-file-noopts.xml
@@ -0,0 +1,35 @@
+<disk type='file' device='disk'>
+  <driver name='qemu' type='qcow2'/>
+  <source file='/var/lib/libvirt/images/rhel7.3.1507297895'>
+    <privateData>
+      <nodenames>
+        <nodename type='storage' name='#block004'/>
+        <nodename type='format' name='#block126'/>
+      </nodenames>
+    </privateData>
+  </source>
+  <backingStore type='file' index='1'>
+    <format type='qcow2'/>
+    <source file='/var/lib/libvirt/images/rhel7.3.1484071872'>
+      <privateData>
+        <nodenames>
+          <nodename type='storage' name='#block256'/>
+          <nodename type='format' name='#block313'/>
+        </nodenames>
+      </privateData>
+    </source>
+    <dataFileStore type='file'>
+      <format type='raw'/>
+      <source file='/var/lib/libvirt/images/rhel7.3.1483615252'>
+        <privateData>
+          <nodenames>
+            <nodename type='storage' name='#block418'/>
+            <nodename type='format' name='#block556'/>
+          </nodenames>
+        </privateData>
+      </source>
+    </dataFileStore>
+  </backingStore>
+  <target dev='vda' bus='virtio'/>
+  <alias name='virtio-disk0'/>
+</disk>
diff --git a/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts-srconly.json b/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts-srconly.json
new file mode 100644
index 0000000000..f2fd81184b
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts-srconly.json
@@ -0,0 +1,18 @@
+(
+  source only properties:
+  {
+    "driver": "file",
+    "filename": "/var/lib/libvirt/images/rhel7.3.1507297895"
+  }
+  backing store string:
+  /var/lib/libvirt/images/rhel7.3.1507297895
+)
+(
+  source only properties:
+  {
+    "driver": "file",
+    "filename": "/var/lib/libvirt/images/rhel7.3.1484071872"
+  }
+  backing store string:
+  /var/lib/libvirt/images/rhel7.3.1484071872
+)
diff --git a/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.json b/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.json
new file mode 100644
index 0000000000..ed7782b4f6
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.json
@@ -0,0 +1,27 @@
+{
+  "node-name": "#block126",
+  "read-only": false,
+  "driver": "qcow2",
+  "data-file": "#block313",
+  "file": "#block004"
+}
+{
+  "driver": "file",
+  "filename": "/var/lib/libvirt/images/rhel7.3.1507297895",
+  "node-name": "#block004",
+  "auto-read-only": true,
+  "discard": "unmap"
+}
+{
+  "node-name": "#block313",
+  "read-only": false,
+  "driver": "raw",
+  "file": "#block256"
+}
+{
+  "driver": "file",
+  "filename": "/var/lib/libvirt/images/rhel7.3.1484071872",
+  "node-name": "#block256",
+  "auto-read-only": true,
+  "discard": "unmap"
+}
diff --git a/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.xml b/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.xml
new file mode 100644
index 0000000000..6d4c9fd174
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-qcow2-data-file-noopts.xml
@@ -0,0 +1,24 @@
+<disk type='file' device='disk'>
+  <driver name='qemu' type='qcow2'/>
+  <source file='/var/lib/libvirt/images/rhel7.3.1507297895'>
+    <privateData>
+      <nodenames>
+        <nodename type='storage' name='#block004'/>
+        <nodename type='format' name='#block126'/>
+      </nodenames>
+    </privateData>
+  </source>
+  <dataFileStore type='file'>
+    <format type='raw'/>
+    <source file='/var/lib/libvirt/images/rhel7.3.1484071872'>
+      <privateData>
+        <nodenames>
+          <nodename type='storage' name='#block256'/>
+          <nodename type='format' name='#block313'/>
+        </nodenames>
+      </privateData>
+    </source>
+  </dataFileStore>
+  <target dev='vda' bus='virtio'/>
+  <alias name='virtio-disk0'/>
+</disk>
\ No newline at end of file
-- 
2.43.5



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux