Skip to content

Commit

Permalink
Add VMAX disk resource support
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-v committed Dec 2, 2021
1 parent d67a1de commit 8a1cab1
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
26 changes: 26 additions & 0 deletions delfin/drivers/dell_emc/vmax/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,32 @@ def list_ports(self, storage_id):

return port_list

def list_disks(self, storage_id):
if int(self.uni_version) < 91:
return []
try:
# Get list of Disks
disks = self.rest.get_disk_list(self.array_id,
self.uni_version)
disk_list = []
for disk in disks:
disk_info = self.rest.get_disk(
self.array_id, self.uni_version, disk)

disk_item = {
'name': 'disk_' + disk,
'storage_id': storage_id,
'native_disk_id': disk,
'manufacturer': disk_info['vendor'],
'capacity': int(disk_info['capacity']) * units.Gi,
}
disk_list.append(disk_item)
return disk_list

except Exception:
LOG.error("Failed to get disk details from VMAX")
raise

def list_alerts(self, query_para):
"""Get all alerts from an array."""
return self.rest.get_alerts(query_para, version=self.uni_version,
Expand Down
31 changes: 31 additions & 0 deletions delfin/drivers/dell_emc/vmax/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,37 @@ def get_port_list(self, array, version, director_id, params=None):
list()) if response else list()
return port_ids

def get_disk(self, array, version, device_id):
"""Get a VMax disk from array.
:param array: the array serial number
:param version: the unisphere version -- int
:param device_id: the disk device id
:returns: disk dict
:raises: StorageBackendException
"""
disk_dict = self.get_resource(
array, SYSTEM, 'disk', resource_name=device_id,
version=version)
if not disk_dict:
exception_message = (_("Disk %(deviceID)s not found.")
% {'deviceID': device_id})
LOG.error(exception_message)
raise exception.DiskNotFound(device_id)
return disk_dict

def get_disk_list(self, array, version, params=None):
"""Get a filtered list of VMax disks from array.
Filter parameters are required as the unfiltered disk list could be
very large and could affect performance if called often.
:param array: the array serial number
:param version: the unisphere version
:param params: filter parameters
:returns: disk_ids -- list
"""
disk_dict_list = self.get_resource(
array, SYSTEM, 'disk', version=version, params=params)
return disk_dict_list.get('disk_ids', [])

def post_request(self, target_uri, payload):
"""Generate a POST request.
:param target_uri: the uri to query from unipshere REST API
Expand Down
2 changes: 1 addition & 1 deletion delfin/drivers/dell_emc/vmax/vmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def list_ports(self, context):
return self.client.list_ports(self.storage_id)

def list_disks(self, context):
raise NotImplementedError
return self.client.list_disks(self.storage_id)

def add_trap_config(self, context, trap_config):
pass
Expand Down
75 changes: 75 additions & 0 deletions delfin/tests/unit/drivers/dell_emc/vmax/test_vmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,81 @@ def test_list_ports(self, mock_unisphere_version,
self.assertIn('Exception from Storage Backend:',
str(exc.exception))

@mock.patch.object(VMaxRest, 'get_disk')
@mock.patch.object(VMaxRest, 'get_disk_list')
@mock.patch.object(VMaxRest, 'get_array_detail')
@mock.patch.object(VMaxRest, 'get_uni_version')
@mock.patch.object(VMaxRest, 'get_unisphere_version')
def test_list_disks(self, mock_unisphere_version,
mock_version, mock_array,
mock_disks, mock_disk):
expected = \
[
{
'name': 'disk_1',
'storage_id': '12345',
'native_disk_id': '1',
'manufacturer': 'HGST',
'capacity': 1073741824000
},
{
'name': 'disk_2',
'storage_id': '12345',
'native_disk_id': '2',
'manufacturer': 'WD',
'capacity': 2147483648000
}
]
disks = {
'spindle_id': '1000',
'type': 'HGOMAHA_1',
'vendor': 'HGST',
'capacity': 1000.0
}
disk1 = {
'spindle_id': '1001',
'type': 'HGOMAHA_2',
'vendor': 'WD',
'capacity': 2000.0
}
disk2 = {
'spindle_id': '1002',
'type': 'HGOMAHA_3',
'vendor': 'SUN',
'capacity': 3000.0
}

kwargs = VMAX_STORAGE_CONF
mock_version.return_value = ['V9.2.2.7', '92']
mock_unisphere_version.return_value = ['V9.2.2.7', '92']
mock_array.return_value = {'symmetrixId': ['00112233']}
mock_disks.side_effect = [['1', '2', '3']]
mock_disk.side_effect = [disks, disk1, disk2]

driver = VMAXStorageDriver(**kwargs)
self.assertEqual(driver.storage_id, "12345")
self.assertEqual(driver.client.array_id, "00112233")
ret = driver.list_disks(context)
print("return", ret)
self.assertDictEqual(ret[0], expected[0])
self.assertDictEqual(ret[1], expected[1])

mock_disks.side_effect = [['disk_1']]
mock_disk.side_effect = [exception.StorageBackendException]
with self.assertRaises(Exception) as exc:
driver.list_disks(context)

self.assertIn('Exception from Storage Backend',
str(exc.exception))

mock_disks.side_effect = [exception.StorageBackendException]
mock_disk.side_effect = [disks]
with self.assertRaises(Exception) as exc:
driver.list_disks(context)

self.assertIn('Exception from Storage Backend',
str(exc.exception))

@mock.patch.object(Session, 'request')
@mock.patch.object(VMaxRest, 'get_array_detail')
@mock.patch.object(VMaxRest, 'get_uni_version')
Expand Down

0 comments on commit 8a1cab1

Please sign in to comment.