Change in vdsm[master]: storage: readspeed: drop useless return value

fromani at redhat.com fromani at redhat.com
Thu Apr 14 15:05:52 UTC 2016


Francesco Romani has uploaded a new change for review.

Change subject: storage: readspeed: drop useless return value
......................................................................

storage: readspeed: drop useless return value

storage.misc.readspeed used to return a two-item
dictionary, with both bytes read and the time in seconds
the read took.

The code never uses the bytes attribute, so this patch
simplifies the return value to just one float, the
elapsed time.

The function was also rename 'read_delay' to make
it more descriptive.

Change-Id: I22cc27a04603e8f53c5103283c3b4d64a4fabcec
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/miscTests.py
M vdsm/storage/blockSD.py
M vdsm/storage/fileSD.py
M vdsm/storage/misc.py
4 files changed, 19 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/60/56160/1

diff --git a/tests/miscTests.py b/tests/miscTests.py
index 638326a..2a24e6c 100644
--- a/tests/miscTests.py
+++ b/tests/miscTests.py
@@ -841,32 +841,22 @@
 
 
 @expandPermutations
-class ReadSpeed(TestCaseBase):
+class TestReadDelay(TestCaseBase):
 
     @permutations([
-        # output line, bytes read, seconds
-        ("1 byte (1 B) copied, 1 s, 1 B/s",
-         "1", "1"),
-        ("1024 bytes (1 kB) copied, 1 s, 1 kB/s",
-         "1024", "1"),
-        ("1572864 bytes (1.5 MB) copied, 1.5 s, 1 MB/s",
-         "1572864", "1.5"),
-        ("1610612736 bytes (1.5 GB) copied, 1000.5 s, 1.53 MB/s",
-         "1610612736", "1000.5"),
-        ("479 bytes (479 B) copied, 5.6832e-05 s, 8.4 MB/s",
-         "479", "5.6832e-05"),
-        ("512 bytes (512e-3 MB) copied, 1 s, 512e-3 MB/s",
-         "512", "1"),
-        ("524288 bytes (512e3 B) copied, 1 s, 512e3 B/s",
-         "524288", "1"),
-        ("517 bytes (517 B) copied, 0 s, Infinity B/s",
-         "517", "0"),
-        ("4096 bytes (4.1 kB) copied, 0.00135703 s, 3.0 MB/s",
-         "4096", "0.00135703"),
-        ("30 bytes (30 B) copied, 0.0033204 s, 9.0 kB/s",
-         "30", "0.0033204"),
+        # output line, seconds
+        ("1 byte (1 B) copied, 1 s, 1 B/s", "1"),
+        ("1024 bytes (1 kB) copied, 1 s, 1 kB/s", "1"),
+        ("1572864 bytes (1.5 MB) copied, 1.5 s, 1 MB/s", "1.5"),
+        ("1610612736 bytes (1.5 GB) copied, 1000.5 s, 1.53 MB/s", "1000.5"),
+        ("479 bytes (479 B) copied, 5.6832e-05 s, 8.4 MB/s", "5.6832e-05"),
+        ("512 bytes (512e-3 MB) copied, 1 s, 512e-3 MB/s", "1"),
+        ("524288 bytes (512e3 B) copied, 1 s, 512e3 B/s", "1"),
+        ("517 bytes (517 B) copied, 0 s, Infinity B/s", "0"),
+        ("4096 bytes (4.1 kB) copied, 0.00135703 s, 3.0 MB/s", "0.00135703"),
+        ("30 bytes (30 B) copied, 0.0033204 s, 9.0 kB/s", "0.0033204"),
     ])
-    def test_readspeed(self, output_line, bytes_read, seconds):
+    def test_read_delay(self, output_line, seconds):
         output = (
             "0+1 records in",
             "0+1 records out",
@@ -877,10 +867,9 @@
             return 0, None, output
 
         with MonkeyPatchScope([(misc, 'execCmd', _fake_exec_cmd)]):
-            speed = misc.readspeed('useless')
+            delay = misc.read_delay('useless')
 
-        self.assertEquals(speed["bytes"], int(bytes_read))
-        self.assertAlmostEqual(speed["seconds"], float(seconds))
+        self.assertAlmostEqual(delay, float(seconds))
 
 
 class PidExists(TestCaseBase):
diff --git a/vdsm/storage/blockSD.py b/vdsm/storage/blockSD.py
index e2d413a..4fd52bb 100644
--- a/vdsm/storage/blockSD.py
+++ b/vdsm/storage/blockSD.py
@@ -433,8 +433,7 @@
         return meta
 
     def getReadDelay(self):
-        stats = misc.readspeed(lvm.lvPath(self.sdUUID, sd.METADATA), 4096)
-        return stats['seconds']
+        return misc.read_delay(lvm.lvPath(self.sdUUID, sd.METADATA), 4096)
 
     def getVSize(self, imgUUUID, volUUID):
         """ Return the block volume size in bytes. """
diff --git a/vdsm/storage/fileSD.py b/vdsm/storage/fileSD.py
index dac383d..887eee2 100644
--- a/vdsm/storage/fileSD.py
+++ b/vdsm/storage/fileSD.py
@@ -171,8 +171,7 @@
             raise se.StorageDomainMetadataNotFound(self.sdUUID, self.metafile)
 
     def getReadDelay(self):
-        stats = misc.readspeed(self.metafile, 4096)
-        return stats['seconds']
+        return misc.read_delay(self.metafile, 4096)
 
     def getVSize(self, imgUUID, volUUID):
         """ Returns file volume size in bytes. """
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index 75a43d3..c8247f6 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -194,7 +194,7 @@
 )
 
 
-def readspeed(path, buffersize=None):
+def read_delay(path, buffersize=None):
     """
     Measures the amount of bytes transferred and the time elapsed
     reading the content of the file/device
@@ -221,10 +221,7 @@
         log.error("Unable to parse dd output: '%s'", err[-1])
         raise se.MiscFileReadException(path)
 
-    return {
-        'bytes': int(m.group('bytes')),
-        'seconds': float(m.group('seconds')),
-    }
+    return float(m.group('seconds'))
 
 
 def readblock(name, offset, size):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I22cc27a04603e8f53c5103283c3b4d64a4fabcec
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