From 5ed022d287b47eb83f05a1ef76ac02fdb1f2a689 Mon Sep 17 00:00:00 2001 From: jiangyutan <69443713+jiangyutan@users.noreply.github.com> Date: Tue, 30 Mar 2021 17:43:27 +0800 Subject: [PATCH] Improve storage status checking (#541) --- .../drivers/hpe/hpe_3par/component_handler.py | 7 +-- .../drivers/hpe/hpe_3par/test_hpe_3parstor.py | 52 ++++++++++++++++++- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/delfin/drivers/hpe/hpe_3par/component_handler.py b/delfin/drivers/hpe/hpe_3par/component_handler.py index 7f50e05e8..281e14675 100644 --- a/delfin/drivers/hpe/hpe_3par/component_handler.py +++ b/delfin/drivers/hpe/hpe_3par/component_handler.py @@ -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 diff --git a/delfin/tests/unit/drivers/hpe/hpe_3par/test_hpe_3parstor.py b/delfin/tests/unit/drivers/hpe/hpe_3par/test_hpe_3parstor.py index c155f9576..bf0288742 100644 --- a/delfin/tests/unit/drivers/hpe/hpe_3par/test_hpe_3parstor.py +++ b/delfin/tests/unit/drivers/hpe/hpe_3par/test_hpe_3parstor.py @@ -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 @@ -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()