Skip to content

Commit

Permalink
Improve storage status checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyutan committed Mar 30, 2021
1 parent 7f648b2 commit 02269e3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
7 changes: 2 additions & 5 deletions delfin/drivers/hpe/hpe_3par/component_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ def get_storage(self, context):
# get storage info
storage = self.rest_handler.get_storage()
# default state is offline
status = constants.StorageStatus.OFFLINE
status = constants.StorageStatus.NORMAL

if storage:
try:
# Check the hardware and software health
# status of the storage system
re_str = self.ssh_handler.get_health_state()
if ComponentHandler.COMPONENT_HEALTH in re_str \
or ComponentHandler.SYSTEM_HEALTH in re_str:
status = constants.StorageStatus.NORMAL
else:
if 'degraded' in re_str or 'failed' in re_str:
status = constants.StorageStatus.ABNORMAL
except Exception:
status = constants.StorageStatus.ABNORMAL
Expand Down
52 changes: 51 additions & 1 deletion delfin/tests/unit/drivers/hpe/hpe_3par/test_hpe_3parstor.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def test_d_get_storage(self):
}
}
)
SSHHandler.get_health_state = mock.Mock(return_value="")
health_state = 'PDs that are degraded'
SSHHandler.get_health_state = mock.Mock(return_value=health_state)
m = mock.MagicMock(status_code=200)
with mock.patch.object(RestHandler, 'call', return_value=m):
m.raise_for_status.return_value = 200
Expand Down Expand Up @@ -311,6 +312,55 @@ def test_e_list_storage_pools(self):
self.assertIn('An unknown exception occurred',
str(exc.exception))

def test_f_list_volumes(self):
driver = create_driver()
expected = [{
'name': 'admin',
'storage_id': '12345',
'description': None,
'status': 'normal',
'native_volume_id': '0',
'native_storage_pool_id': '',
'wwn': '50002AC000001C9F',
'type': 'thick',
'total_capacity': 10737418240,
'used_capacity': 10737418240,
'free_capacity': 0,
'compressed': True,
'deduplicated': True
}]
ret = [{
"members": [{
"id": 0,
"name": "admin",
"provisioningType": 1,
"copyType": 1,
"baseId": 0,
"readOnly": False,
"state": 1,
"userSpace": {
"reservedMiB": 10240,
"rawReservedMiB": 20480,
"usedMiB": 10240,
"freeMiB": 0
},
"sizeMiB": 10240,
"wwn": "50002AC000001C9F"
}]
}]
pool_ret = {
"members": [{
"id": 0,
"uuid": "aa43f218-d3dd-4626-948f-8a160b0eac1d",
"name": "test"
}]
}
RestHandler.get_all_pools = mock.Mock(return_value=pool_ret)
with mock.patch.object(RestHandler, 'get_resinfo_call',
side_effect=ret):
volumes = driver.list_volumes(context)
self.assertDictEqual(volumes[0], expected[0])

def test_h_parse_alert(self):
""" Success flow with all necessary parameters"""
driver = create_driver()
Expand Down

0 comments on commit 02269e3

Please sign in to comment.