Skip to content

Commit 1d5aa2c

Browse files
committed
CA-412336: treat inaccessible device as a soft failure
Signed-off-by: Mark Syms <mark.syms@cloud.com>
1 parent 6cdd23c commit 1d5aa2c

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

libs/sm/core/scsiutil.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,31 @@ def getdev(path):
222222

223223

224224
def get_devices_by_SCSIid(SCSIid):
225-
devices = os.listdir(os.path.join('/dev/disk/by-scsid', SCSIid))
225+
id_path = os.path.join('/dev/disk/by-scsid', SCSIid)
226+
if not os.path.exists(id_path):
227+
util.SMlog(f'SCSId Path not found for {id_path}')
228+
return []
229+
230+
devices = os.listdir(id_path)
226231
if 'mapper' in devices:
227232
devices.remove('mapper')
228233
return devices
229234

230235

231236
def get_device_provisioning_mode(SCSIid):
232-
device = get_devices_by_SCSIid(SCSIid)[0]
237+
devices = get_devices_by_SCSIid(SCSIid)
238+
if not devices:
239+
# Device can't be found so assume full
240+
return 'full'
241+
242+
device = devices[0]
233243
glob_pattern = os.path.join('/sys', 'block', device, 'device', 'scsi_disk', '*', 'provisioning_mode')
244+
mode = 'full'
234245
for file in glob.glob(glob_pattern):
235246
with open(file, 'r') as device_mode:
236247
mode = device_mode.readline().strip()
237-
return mode
248+
249+
return mode
238250

239251

240252
def device_is_thin_provisioned(SCSIid):

tests/test_scsiutil.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def setUp(self):
4949
exists_patcher = mock.patch(
5050
'sm.core.scsiutil.os.path.exists', autospece=True)
5151
self.mock_exists = exists_patcher.start()
52+
self.mock_exists.side_effect = self.exists
5253
self.path_map = {}
5354
realpath_patcher = mock.patch(
5455
'sm.core.scsiutil.os.path.realpath', autospec=True)
@@ -91,8 +92,13 @@ def open(self, file_name, mode):
9192
self.mock_files[file_name] = mock_file
9293
return mock_file
9394

95+
def exists(self, path):
96+
return path in self.path_map
97+
9498
def test_get_size_exists_success(self):
95-
self.mock_exists.return_value = True
99+
self.path_map = {
100+
'/sys/block/sda/size': True
101+
}
96102

97103
with mock.patch("builtins.open",
98104
new_callable=mock.mock_open, read_data='976773168') as m:
@@ -104,11 +110,9 @@ def test_get_size_exists_success(self):
104110
m.assert_called_with("/sys/block/sda/size", "r")
105111

106112
def test_get_size_mapper_exists_success(self):
107-
self.mock_exists.return_value = True
108-
109-
self.path_map[
110-
"/dev/disk/by-id/scsi-360a98000534b4f4e46704c76692d6d33"] = \
111-
"/dev/sde"
113+
self.path_map = {
114+
'/sys/block/sde/size': True,
115+
"/dev/disk/by-id/scsi-360a98000534b4f4e46704c76692d6d33": "/dev/sde"}
112116

113117
with mock.patch("builtins.open",
114118
new_callable=mock.mock_open, read_data='976773168') as m:
@@ -120,8 +124,6 @@ def test_get_size_mapper_exists_success(self):
120124
m.assert_called_with("/sys/block/sde/size", "r")
121125

122126
def test_get_size_not_exists_0(self):
123-
self.mock_exists.return_value = False
124-
125127
with mock.patch("builtins.open",
126128
new_callable=mock.mock_open, read_data='976773168') as m:
127129
# Nastiness due to python2 mock_open not supporting readline
@@ -159,3 +161,12 @@ def test_lun_is_thin_provisioned(self):
159161

160162
# Assert
161163
self.assertTrue(thin_provisioned)
164+
165+
def test_lun_is_thin_provisioned_not_found(self):
166+
self.path_map = {}
167+
168+
# Act
169+
thin_provisioned = scsiutil.device_is_thin_provisioned('360a98000534b4f4e46704c76692d6d33')
170+
171+
# Assert
172+
self.assertFalse(thin_provisioned)

0 commit comments

Comments
 (0)