Change in vdsm[master]: storage: support new dd output

fromani at redhat.com fromani at redhat.com
Wed Apr 13 15:50:12 UTC 2016


Francesco Romani has uploaded a new change for review.

Change subject: storage: support new dd output
......................................................................

storage: support new dd output

In Fedora 24 we can find the new dd from coreutils 8.25.5
which has a new fancier output format:

Example #1:
1+0 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 0.00887814 s, 461 kB/s
           ^^^^^^^^^^^^^^^^^

Example #2:
0+1 records in
0+1 records out
30 bytes copied, 0.00156704 s, 19.1 kB/s
             ^^^^

Compare with the old dd output found in Fedora 23:

Example #1:
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.00135703 s, 3.0 MB/s
           ^^^^^^^^

Example #2:
0+1 records in
0+1 records out
30 bytes (30 B) copied, 0.0033204 s, 9.0 kB/s
         ^^^^^^

After a quick glance at the dd manpage, I couldn't find a way to
disable the new output, which breaks the storage regex to
parse the read speed results.

This patch adds compatibility with the new format, without breaking
support for older versions.

Change-Id: I632d99cdc2b41e96a75bdce12e86710241fa0939
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/Makefile.am
A tests/storage_misc_test.py
M vdsm/storage/misc.py
3 files changed, 79 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/56091/1

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5cebb3f..e5b8b51 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -139,6 +139,7 @@
 	storageMonitorTests.py \
 	storageServerTests.py \
 	storagetestlibTests.py \
+	storage_misc_test.py \
 	storage_sdm_api_test.py \
 	storage_sdm_create_volume_test.py \
 	storage_volume_artifacts_test.py \
diff --git a/tests/storage_misc_test.py b/tests/storage_misc_test.py
new file mode 100644
index 0000000..e27798c
--- /dev/null
+++ b/tests/storage_misc_test.py
@@ -0,0 +1,76 @@
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from storage import misc
+from testlib import VdsmTestCase
+
+from monkeypatch import MonkeyPatchScope
+
+
+class TestReadSpeed(VdsmTestCase):
+
+    def test_zero_size(self):
+        output = (
+            "0+0 records in",
+            "0+0 records out",
+            "0 bytes copied, 1.8436e-05 s, 0.0 kB/s")
+        self.assertNotRaises(self._speed_from_output, output)
+
+    def test_very_fast(self):
+        output = (
+            "0+1 records in",
+            "0+1 records out",
+            "164 bytes copied, 0.000674613 s, 243 kB/s")
+        self.assertNotRaises(self._speed_from_output, output)
+
+    def test_read_4096_human_readable(self):
+        output = (
+            "1+0 records in",
+            "1+0 records out",
+            "4096 bytes (4.1 kB, 4.0 KiB) copied, 0.00887814 s, 461 kB/s")
+        self.assertNotRaises(self._speed_from_output, output)
+
+    def test_read_30_bytes_human_readable(self):
+        output = (
+            "0+1 records in",
+            "0+1 records out",
+            "30 bytes copied, 0.00156704 s, 19.1 kB/s")
+        self.assertNotRaises(self._speed_from_output, output)
+
+    def test_read_4096_legacy_output(self):
+        output = (
+            "1+0 records in",
+            "1+0 records out",
+            "4096 bytes (4.1 kB) copied, 0.00135703 s, 3.0 MB/s")
+        self.assertNotRaises(self._speed_from_output, output)
+
+    def test_read_30_bytes_legacy_output(self):
+        output = (
+            "0+1 records in",
+            "0+1 records out",
+            "30 bytes (30 B) copied, 0.0033204 s, 9.0 kB/s")
+        self.assertNotRaises(self._speed_from_output, output)
+
+    def _speed_from_output(self, output):
+        def _fake_exec_cmd(*args):
+            return 0, None, output
+
+        with MonkeyPatchScope([(misc, 'execCmd', _fake_exec_cmd)]):
+            return misc.readspeed('useless')
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index 074169e..05d8183 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -188,7 +188,8 @@
     return str(ctime)
 
 _readspeed_regex = re.compile(
-    "(?P<bytes>\d+) bytes? \([\de\-.]+ [kMGT]*B\) copied, "
+    "(?P<bytes>\d+) bytes?"
+    "(|( \([\de\-.]+ [kMGT]*B(|, [\de\-.]+ [KMGT]*iB)\))) copied, "
     "(?P<seconds>[\de\-.]+) s, "
     "([\de\-.]+|Infinity) [kMGT]*B/s"
 )


-- 
To view, visit https://gerrit.ovirt.org/56091
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I632d99cdc2b41e96a75bdce12e86710241fa0939
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list