diff --git a/swift/common/middleware/recon.py b/swift/common/middleware/recon.py index 3c37e00ce2..ffd289f3d1 100644 --- a/swift/common/middleware/recon.py +++ b/swift/common/middleware/recon.py @@ -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 diff --git a/test/unit/common/middleware/test_recon.py b/test/unit/common/middleware/test_recon.py index ba72f67b98..64afe4e085 100644 --- a/test/unit/common/middleware/test_recon.py +++ b/test/unit/common/middleware/test_recon.py @@ -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