catch OSError to prevent breaking request /recon/diskusage

swift.common.utils.ismount maybe raise some OSError in some special
cases; and the request against /recon/diskusage doesn't handle it
before. This patch let output of mounted keyword is the error's message.

Change-Id: I5d9018f580181e618a3fa072b7a760d41795d8eb
Closes-Bug: #1249181
This commit is contained in:
Kun Huang 2013-11-13 19:20:16 +08:00 committed by Kun Huang
parent 44e2e5ee43
commit fd4843f8e7
2 changed files with 20 additions and 1 deletions

View File

@ -201,7 +201,14 @@ class ReconMiddleware(object):
"""get disk utilization statistics"""
devices = []
for entry in os.listdir(self.devices):
if check_mount(self.devices, entry):
try:
mounted = check_mount(self.devices, entry)
except OSError as err:
devices.append({'device': entry, 'mounted': str(err),
'size': '', 'used': '', 'avail': ''})
continue
if mounted:
path = os.path.join(self.devices, entry)
disk = os.statvfs(path)
capacity = disk.f_bsize * disk.f_blocks

View File

@ -27,6 +27,10 @@ from swift.common.middleware import recon
from swift.common.utils import json
def fake_check_mount(a, b):
raise OSError('Input/Output Error')
class FakeApp(object):
def __call__(self, env, start_response):
return "FAKE APP"
@ -606,6 +610,14 @@ class TestReconSuccess(TestCase):
[(('/srv/node/canhazdrive1',), {})])
self.assertEquals(rv, du_resp)
@mock.patch("swift.common.middleware.recon.check_mount", fake_check_mount)
def test_get_diskusage_oserror(self):
du_resp = [{'device': 'canhazdrive1', 'avail': '',
'mounted': 'Input/Output Error', 'used': '', 'size': ''}]
self.mockos.ls_output = ['canhazdrive1']
rv = self.app.get_diskusage()
self.assertEquals(rv, du_resp)
def test_get_quarantine_count(self):
self.mockos.ls_output = ['sda']
self.mockos.ismount_output = True