Skip to content

Commit

Permalink
storage status add DEGRADED status (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjiangyu-ghca authored Dec 24, 2021
1 parent 9162c7d commit 320b7fe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
31 changes: 23 additions & 8 deletions delfin/drivers/dell_emc/unity/unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
class UnityStorDriver(driver.StorageDriver):
"""UnityStorDriver implement the DELL EMC Storage driver"""
HEALTH_OK = (5, 7)

STORAGE_STATUS_MAP = {5: constants.StorageStatus.NORMAL,
7: constants.StorageStatus.NORMAL,
15: constants.StorageStatus.NORMAL,
20: constants.StorageStatus.NORMAL,
10: constants.StorageStatus.DEGRADED
}
FILESYSTEM_FLR_MAP = {0: constants.WORMType.NON_WORM,
1: constants.WORMType.ENTERPRISE,
2: constants.WORMType.COMPLIANCE
Expand Down Expand Up @@ -62,23 +67,31 @@ def reset_connection(self, context, **kwargs):
def close_connection(self):
self.rest_handler.logout()

def get_disk_capacity(self, context):
raw_capacity = 0
try:
disk_info = self.list_disks(context)
if disk_info:
for disk in disk_info:
raw_capacity += disk.get('capacity')
except Exception:
LOG.info("get disk info fail in get_disk_capacity")
return raw_capacity

def get_storage(self, context):
system_info = self.rest_handler.get_storage()
capacity = self.rest_handler.get_capacity()
version_info = self.rest_handler.get_soft_version()
status = constants.StorageStatus.OFFLINE
if system_info is not None and capacity is not None:
system_entries = system_info.get('entries')
for system in system_entries:
content = system.get('content', {})
name = content.get('name')
model = content.get('model')
serial_number = content.get('serialNumber')
health_value = content.get('health').get('value')
if health_value in UnityStorDriver.HEALTH_OK:
status = constants.StorageStatus.NORMAL
else:
status = constants.StorageStatus.ABNORMAL
health_value = content.get('health', {}).get('value')
status = UnityStorDriver.STORAGE_STATUS_MAP.get(
health_value, constants.StorageStatus.ABNORMAL)
break
capacity_info = capacity.get('entries')
for per_capacity in capacity_info:
Expand All @@ -95,6 +108,8 @@ def get_storage(self, context):
if content:
version = content.get('id')
break
raw_capacity = self.get_disk_capacity(context)
raw_capacity = raw_capacity if raw_capacity else int(total)
system_result = {
'name': name,
'vendor': 'DELL EMC',
Expand All @@ -105,7 +120,7 @@ def get_storage(self, context):
'location': '',
'subscribed_capacity': int(subs),
'total_capacity': int(total),
'raw_capacity': int(total),
'raw_capacity': raw_capacity,
'used_capacity': int(used),
'free_capacity': int(free)
}
Expand Down
24 changes: 13 additions & 11 deletions delfin/tests/unit/drivers/dell_emc/unity/test_emc_unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@
'status': 'normal',
'name': 'CETV3182000026',
'model': 'Unity 350F',
'raw_capacity': 8838774259712,
'raw_capacity': 12121212,
'firmware_version': '4.7.1'
}
storage_abnormal_result = {
'free_capacity': 2311766147072,
'serial_number': 'CETV3182000026',
'subscribed_capacity': 307567976775680,
'used_capacity': 6527008112640,
'name': 'CETV3182000026',
'vendor': 'DELL EMC',
'model': 'Unity 350F',
'status': 'normal',
'serial_number': 'CETV3182000026',
'firmware_version': '4.7.1',
'location': '',
'subscribed_capacity': 307567976775680,
'total_capacity': 8838774259712,
'status': 'abnormal',
'name': 'CETV3182000026',
'model': 'Unity 350F',
'raw_capacity': 8838774259712,
'firmware_version': '4.7.1'
'raw_capacity': 12121212,
'used_capacity': 6527008112640,
'free_capacity': 2311766147072
}
GET_ALL_POOLS = {
"entries": [
Expand Down Expand Up @@ -1337,14 +1337,16 @@ def test_list_storage_pools(self, mock_pool):
pool = UnityStorDriver(**ACCESS_INFO).list_storage_pools(context)
self.assertDictEqual(pool[0], pool_abnormal_result[0])

@mock.patch.object(RestHandler, 'get_all_disks')
@mock.patch.object(RestHandler, 'get_storage')
@mock.patch.object(RestHandler, 'get_capacity')
@mock.patch.object(RestHandler, 'get_soft_version')
def test_get_storage(self, mock_version, mock_capa, mock_base):
def test_get_storage(self, mock_version, mock_capa, mock_base, mock_disk):
RestHandler.login = mock.Mock(return_value=None)
mock_version.return_value = GET_SOFT_VERSION
mock_capa.return_value = GET_CAPACITY
mock_base.return_value = GET_STORAGE_ABNORMAL
mock_disk.return_value = GET_ALL_DISKS
storage = UnityStorDriver(**ACCESS_INFO).get_storage(context)
self.assertDictEqual(storage, storage_abnormal_result)
mock_base.return_value = GET_STORAGE_NORMAL
Expand Down

0 comments on commit 320b7fe

Please sign in to comment.