Nir Soffer has uploaded a new change for review.
Change subject: storageServer: Drop unnecessary list comprehension ......................................................................
storageServer: Drop unnecessary list comprehension
For formating list of mismatches, we can implement __repr__ on the Mismatch class instead of explicit formating. This is generaly better since we pay for formatting only when logging level requires formatting.
This also eliminate, pyflakes-0.8.1-3.el6 warning:
vdsm/storage/storageServer.py:427: list comprehension redefines 'e' from line 421
Change-Id: I337893db5fd6a52b644798e8414037286eb2d93a Signed-off-by: Nir Soffer nsoffer@redhat.com --- M tests/storageServerTests.py M vdsm/storage/storageServer.py 2 files changed, 10 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/06/36606/1
diff --git a/tests/storageServerTests.py b/tests/storageServerTests.py index 83099f5..d178d42 100644 --- a/tests/storageServerTests.py +++ b/tests/storageServerTests.py @@ -31,3 +31,9 @@ def test_format(self): s = str(IscsiConnection.Mismatch("error %d with %r", 1, "text")) self.assertEqual(s, "error 1 with 'text'") + + def test_format_mismatches_list(self): + errors = [IscsiConnection.Mismatch("error 1"), + IscsiConnection.Mismatch("error 2")] + expected = "%s" % ["error 1", "error 2"] + self.assertEqual(str(errors), expected) diff --git a/vdsm/storage/storageServer.py b/vdsm/storage/storageServer.py index eb38fb3..09acffd 100644 --- a/vdsm/storage/storageServer.py +++ b/vdsm/storage/storageServer.py @@ -354,6 +354,10 @@ def __str__(self): return self.fmt % self.args
+ def __repr__(self): + # Required for logging list of errors + return repr(self.__str__()) + @property def target(self): return self._target