Ignore devices with OSError

This bug handles OSError when trying to read from CDrom devices with no
disc in the is_pristine_disk function which makes the run-action
list-disks to fail.

Change-Id: I951897a699305604821f2c910ee9ea91582c4e40
Closes-Bug: #1833857
Co-authored-by: Stamatis Katsaounis <skatsaounis@admin.grnet.gr>
Signed-off-by: Alexandros Soumplis <soumplis@admin.grnet.gr>
This commit is contained in:
Alexandros Soumplis 2019-12-17 14:26:39 +02:00
parent 1512de6472
commit d393585cfb
2 changed files with 17 additions and 1 deletions

View File

@ -913,7 +913,12 @@ def is_pristine_disk(dev):
"""
want_bytes = 2048
f = open(dev, 'rb')
try:
f = open(dev, 'rb')
except OSError as e:
log(e)
return False
data = f.read(want_bytes)
read_bytes = len(data)
if read_bytes != want_bytes:

View File

@ -1866,6 +1866,17 @@ class CephGetLVSTestCase(unittest.TestCase):
self.assertFalse(_log.called)
self.assertEqual(result, True)
@patch.object(utils, 'log')
def test_is_pristine_disk_oserror(self, _log):
fake_open = mock_open()
oserror_exception = OSError('error')
fake_open.side_effect = oserror_exception
with patch('ceph.utils.open', fake_open):
result = utils.is_pristine_disk('/dev/sr0')
fake_open.assert_called_with('/dev/sr0', 'rb')
_log.assert_called_with(oserror_exception)
self.assertEqual(result, False)
@patch.object(utils, 'log')
def test_is_pristine_disk_short_read(self, _log):
data = b'\0' * 2047