]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Use virHashForEachSorted in tested code
authorPeter Krempa <pkrempa@redhat.com>
Fri, 23 Oct 2020 07:07:02 +0000 (09:07 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 6 Nov 2020 09:31:57 +0000 (10:31 +0100)
The simplest way to write tests is to check the output against expected
output, but we must ensure that the output is stable. We can use
virHashForEachSorted as a hash iterator to ensure stable ordering.

This patch fixes 3 instances of hash iteration which is tested in
various parts, including test output changes in appropriate places.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Matt Coleman <matt@datto.com>
src/qemu/qemu_domain.c
src/util/virmacmap.c
tests/qemumonitorjsontest.c
tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml

index d7dbca487a5a1a55f03759912f7b7c039a28d895..e770940acae8a1c4fac6bdb692eba4b0c11dad69 100644 (file)
@@ -2223,9 +2223,9 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf,
                       virTristateBoolTypeToString(virTristateBoolFromBool(bj)));
 
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
-        virHashForEach(priv->blockjobs,
-                       qemuDomainObjPrivateXMLFormatBlockjobIterator,
-                       &iterdata) < 0)
+        virHashForEachSorted(priv->blockjobs,
+                             qemuDomainObjPrivateXMLFormatBlockjobIterator,
+                             &iterdata) < 0)
         return -1;
 
     virXMLFormatElement(buf, "blockjobs", &attrBuf, &childBuf);
index 2d203e72afe72aa1e6097a4175d633e91f8abd38..fe71b06dd75a6580dd2456be1aaffc7576d5f563 100644 (file)
@@ -244,7 +244,7 @@ virMacMapDumpStrLocked(virMacMapPtr mgr,
 
     arr = virJSONValueNewArray();
 
-    if (virHashForEach(mgr->macs, virMACMapHashDumper, arr) < 0)
+    if (virHashForEachSorted(mgr->macs, virMACMapHashDumper, arr) < 0)
         goto cleanup;
 
     if (!(*str = virJSONValueToString(arr, true)))
index 2a0377bae3f6e071fe835278b4e18bdd0b011b92..9231fa835ad1d02ae577a17a3891765cf2b557a2 100644 (file)
@@ -2792,7 +2792,7 @@ testBlockNodeNameDetect(const void *opaque)
                                                       blockstatsJson)))
         goto cleanup;
 
-    virHashForEach(nodedata, testBlockNodeNameDetectFormat, &buf);
+    virHashForEachSorted(nodedata, testBlockNodeNameDetectFormat, &buf);
 
     virBufferTrim(&buf, "\n");
 
index 8ffc91bdcbb6a43e0088563cbe5ad0e4f99983e1..c70742418b1071f55b7f453537fc65065c02e41f 100644 (file)
   <allowReboot value='yes'/>
   <nodename index='0'/>
   <blockjobs active='yes'>
-    <blockjob name='pull-vdb-libvirt-3-format' type='pull' state='running'>
-      <disk dst='vdb'/>
-      <base node='libvirt-14-format'/>
+    <blockjob name='broken-test' type='broken' state='ready' brokentype='commit'/>
+    <blockjob name='commit-vdc-libvirt-9-format' type='commit' state='running' jobflags='0x0'>
+      <disk dst='vdc'/>
+      <base node='libvirt-11-format'/>
+      <top node='libvirt-9-format'/>
+      <topparent node='libvirt-2-format'/>
     </blockjob>
     <blockjob name='commit-vde-libvirt-17-format' type='active-commit' state='ready'>
       <disk dst='vde'/>
       <top node='libvirt-17-format'/>
       <deleteCommittedImages/>
     </blockjob>
+    <blockjob name='copy-vdd-libvirt-4321-format' type='copy' state='ready' jobflags='0x0' shallownew='yes'>
+      <disk dst='vdd'/>
+    </blockjob>
+    <blockjob name='create-libvirt-1337-storage' type='create' state='running'>
+      <create mode='storage'/>
+      <src type='network' format='qcow2'>
+        <source protocol='rbd' name='pool/volname.qcow2' tlsFromConfig='0' index='1337'>
+          <host name='example.org'/>
+          <privateData>
+            <nodenames>
+              <nodename type='storage' name='libvirt-1337-storage'/>
+              <nodename type='format' name='libvirt-1337-format'/>
+            </nodenames>
+            <objects>
+              <secret type='auth' alias='libvirt-1337-storage-secret0'/>
+            </objects>
+          </privateData>
+        </source>
+      </src>
+    </blockjob>
+    <blockjob name='create-libvirt-1338-format' type='create' state='running' jobflags='0xabcd'>
+      <chains>
+        <disk type='file' format='qcow2'>
+          <source file='/create/src1.qcow2' index='1339'>
+            <privateData>
+              <nodenames>
+                <nodename type='storage' name='libvirt-1339-storage'/>
+                <nodename type='format' name='libvirt-1339-format'/>
+              </nodenames>
+            </privateData>
+          </source>
+          <backingStore/>
+        </disk>
+      </chains>
+      <src type='file' format='qcow2'>
+        <source file='/tmp/create/overlay.qcow2' index='1338'>
+          <privateData>
+            <nodenames>
+              <nodename type='storage' name='libvirt-1338-storage'/>
+              <nodename type='format' name='libvirt-1338-format'/>
+            </nodenames>
+            <objects>
+              <secret type='encryption' alias='libvirt-1338-storage-secret0'/>
+            </objects>
+          </privateData>
+        </source>
+      </src>
+    </blockjob>
     <blockjob name='drive-virtio-disk0' type='copy' state='ready' jobflags='0x0'>
       <disk dst='vda' mirror='yes'/>
     </blockjob>
+    <blockjob name='pull-vdb-libvirt-3-format' type='pull' state='running'>
+      <disk dst='vdb'/>
+      <base node='libvirt-14-format'/>
+    </blockjob>
     <blockjob name='test-orphan-job0' type='copy' state='ready'>
       <chains>
         <disk type='file' format='qcow2'>
         </mirror>
       </chains>
     </blockjob>
-    <blockjob name='broken-test' type='broken' state='ready' brokentype='commit'/>
-    <blockjob name='create-libvirt-1338-format' type='create' state='running' jobflags='0xabcd'>
-      <chains>
-        <disk type='file' format='qcow2'>
-          <source file='/create/src1.qcow2' index='1339'>
-            <privateData>
-              <nodenames>
-                <nodename type='storage' name='libvirt-1339-storage'/>
-                <nodename type='format' name='libvirt-1339-format'/>
-              </nodenames>
-            </privateData>
-          </source>
-          <backingStore/>
-        </disk>
-      </chains>
-      <src type='file' format='qcow2'>
-        <source file='/tmp/create/overlay.qcow2' index='1338'>
-          <privateData>
-            <nodenames>
-              <nodename type='storage' name='libvirt-1338-storage'/>
-              <nodename type='format' name='libvirt-1338-format'/>
-            </nodenames>
-            <objects>
-              <secret type='encryption' alias='libvirt-1338-storage-secret0'/>
-            </objects>
-          </privateData>
-        </source>
-      </src>
-    </blockjob>
-    <blockjob name='commit-vdc-libvirt-9-format' type='commit' state='running' jobflags='0x0'>
-      <disk dst='vdc'/>
-      <base node='libvirt-11-format'/>
-      <top node='libvirt-9-format'/>
-      <topparent node='libvirt-2-format'/>
-    </blockjob>
-    <blockjob name='create-libvirt-1337-storage' type='create' state='running'>
-      <create mode='storage'/>
-      <src type='network' format='qcow2'>
-        <source protocol='rbd' name='pool/volname.qcow2' tlsFromConfig='0' index='1337'>
-          <host name='example.org'/>
-          <privateData>
-            <nodenames>
-              <nodename type='storage' name='libvirt-1337-storage'/>
-              <nodename type='format' name='libvirt-1337-format'/>
-            </nodenames>
-            <objects>
-              <secret type='auth' alias='libvirt-1337-storage-secret0'/>
-            </objects>
-          </privateData>
-        </source>
-      </src>
-    </blockjob>
-    <blockjob name='copy-vdd-libvirt-4321-format' type='copy' state='ready' jobflags='0x0' shallownew='yes'>
-      <disk dst='vdd'/>
-    </blockjob>
   </blockjobs>
   <agentTimeout>-2</agentTimeout>
   <domain type='kvm' id='4'>