Skip to content

Commit

Permalink
CA-332806 - Fix type mismatch when processing speed file
Browse files Browse the repository at this point in the history
Signed-off-by: ben sims <ben.sims@citrix.com>
  • Loading branch information
BenSimsCitrix authored and MarkSymsCtx committed Dec 12, 2019
1 parent b43525c commit 25481c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,13 @@ def getStorageSpeed(self):
if os.path.isfile(path):
speedFile = open(path)
content = speedFile.readlines()
content = [float(i) for i in content]
try:
content = [float(i) for i in content]
except exceptions.ValueError:
Util.log("Something bad in the speed log:{log}".
format(log=speedFile.readlines()))
return speed

if len(content):
speed = sum(content)/float(len(content))
if speed <= 0:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,10 @@ def test_getStorageSpeed(self, mock_chmod, mock_isFile, mock_open):
self.getStorageSpeed(mock_isFile, sr, fakeFile, True, 3.0, 1,
lines=[1.0, 2.0, 6.0])

# File exists contains, a string
self.getStorageSpeed(mock_isFile, sr, fakeFile, True, None, 1,
lines=[1.0, 2.0, "Hello"])

def speedFileSetup(self, sr, FakeFile, mock_isFile, isFile):
expectedPath = cleanup.SPEED_LOG_ROOT.format(uuid=sr.uuid)
mock_isFile.return_value = isFile
Expand Down

0 comments on commit 25481c2

Please sign in to comment.