Merge "IBP: accept removable block devices only from vendor list"

This commit is contained in:
Jenkins 2015-06-09 11:19:12 +00:00 committed by Gerrit Code Review
commit 24e20634e7
2 changed files with 49 additions and 2 deletions

View File

@ -379,6 +379,44 @@ E: UDEV_LOG=3""", '')
self.assertEqual(mock_ereport.call_args_list, [mock.call('/dev/fake'), self.assertEqual(mock_ereport.call_args_list, [mock.call('/dev/fake'),
mock.call('/dev/fake1'), mock.call('/dev/sr0')]) mock.call('/dev/fake1'), mock.call('/dev/sr0')])
@mock.patch.object(hu, 'get_block_devices_from_udev_db')
@mock.patch.object(hu, 'is_disk')
@mock.patch.object(hu, 'extrareport')
@mock.patch.object(hu, 'blockdevreport')
@mock.patch.object(hu, 'udevreport')
def test_list_block_devices_removable_vendors(self, mock_ureport,
mock_breport, mock_ereport,
mock_isdisk, mock_get_devs):
mock_get_devs.return_value = ['/dev/no_vendor_id',
'/dev/wrong_vendor_id',
'/dev/right_vendor_id']
mock_isdisk.return_value = True
mock_ureport.side_effect = [
{},
{'ID_VENDOR': 'Cisco'},
{'ID_VENDOR': 'IBM'},
]
mock_ereport.return_value = {'removable': '1'}
mock_breport.return_value = {'key1': 'value1'}
expected = [{
'device': '/dev/right_vendor_id',
'uspec': {'ID_VENDOR': 'IBM'},
'bspec': {'key1': 'value1'},
'espec': {'removable': '1'}
}]
self.assertEqual(hu.list_block_devices(), expected)
self.assertEqual(
mock_ureport.call_args_list,
[mock.call('/dev/no_vendor_id'),
mock.call('/dev/wrong_vendor_id'),
mock.call('/dev/right_vendor_id')])
mock_breport.assert_called_once_with('/dev/right_vendor_id')
self.assertEqual(
mock_ereport.call_args_list,
[mock.call('/dev/no_vendor_id'),
mock.call('/dev/wrong_vendor_id'),
mock.call('/dev/right_vendor_id')])
def test_match_device_devlinks(self): def test_match_device_devlinks(self):
# should return true if at least one by-id link from first uspec # should return true if at least one by-id link from first uspec
# matches by-id link from another uspec # matches by-id link from another uspec

View File

@ -39,7 +39,10 @@ VALID_MAJORS = (3, 8, 65, 66, 67, 68, 69, 70, 71, 104, 105, 106, 107, 108, 109,
# ID_CDROM e.g. 1 for cdrom device (optional) # ID_CDROM e.g. 1 for cdrom device (optional)
UDEV_PROPERTIES = set(['MAJOR', 'MINOR', 'DEVNAME', 'DEVTYPE', 'DEVPATH', UDEV_PROPERTIES = set(['MAJOR', 'MINOR', 'DEVNAME', 'DEVTYPE', 'DEVPATH',
'ID_BUS', 'ID_MODEL', 'ID_SERIAL_SHORT', 'ID_WWN', 'ID_BUS', 'ID_MODEL', 'ID_SERIAL_SHORT', 'ID_WWN',
'ID_CDROM']) 'ID_CDROM', 'ID_VENDOR'])
REMOVABLE_VENDORS = [
"Adaptec", "IBM", "ServeRA",
]
# more details about types you can find in dmidecode's manual # more details about types you can find in dmidecode's manual
SMBIOS_TYPES = {'bios': '0', SMBIOS_TYPES = {'bios': '0',
@ -285,8 +288,14 @@ def list_block_devices(disks=True):
devs = get_block_devices_from_udev_db() devs = get_block_devices_from_udev_db()
for device in devs: for device in devs:
uspec = udevreport(device) uspec = udevreport(device)
bspec = blockdevreport(device)
espec = extrareport(device) espec = extrareport(device)
# NOTE(agordeev): blockdevreport will fail if there's no medium
# inserted into removable device.
# Accept only devices from REMOVABLE_VENDORS list
if (espec.get('removable') == '1' and
uspec.get('ID_VENDOR') not in REMOVABLE_VENDORS):
continue
bspec = blockdevreport(device)
# if device is not disk,skip it # if device is not disk,skip it
if disks and not is_disk(device, bspec=bspec, uspec=uspec): if disks and not is_disk(device, bspec=bspec, uspec=uspec):