Fixes the storage capabilities
This patch fixes the storage code which fails in certain cases while fetching certain storage related capabilities. Change-Id: If7e3e0cfd8342f1d5c0deccca528fd9d23451a55
This commit is contained in:
		@@ -312,6 +312,9 @@ class RISOperations(rest.RestConnectorBase, operations.IloOperations):
 | 
			
		||||
        :returns the tuple of SmartStorage URI, Headers and settings.
 | 
			
		||||
        """
 | 
			
		||||
        headers, storage_uri, storage_settings = self._get_storage_resource()
 | 
			
		||||
        # Do not raise exception if there is no ArrayControllers
 | 
			
		||||
        # as Storage can be zero at any point and if we raise
 | 
			
		||||
        # exception it might fail get_server_capabilities().
 | 
			
		||||
        if ('links' in storage_settings and
 | 
			
		||||
                'ArrayControllers' in storage_settings['links']):
 | 
			
		||||
            # Get the ArrayCOntrollers URI and Settings
 | 
			
		||||
@@ -323,28 +326,21 @@ class RISOperations(rest.RestConnectorBase, operations.IloOperations):
 | 
			
		||||
                raise exception.IloError(msg)
 | 
			
		||||
 | 
			
		||||
            return headers, array_uri, array_settings
 | 
			
		||||
        else:
 | 
			
		||||
            msg = ('"links/ArrayControllers" section in SmartStorage'
 | 
			
		||||
                   ' does not exist')
 | 
			
		||||
            raise exception.IloCommandNotSupportedError(msg)
 | 
			
		||||
 | 
			
		||||
    def _create_list_of_array_controllers(self):
 | 
			
		||||
        """Creates the list of Array Controller URIs.
 | 
			
		||||
 | 
			
		||||
        :raises: IloCommandNotSupportedError if the ArrayControllers
 | 
			
		||||
            doesnt have member "Member".
 | 
			
		||||
        :returns list of ArrayControllers.
 | 
			
		||||
        """
 | 
			
		||||
        headers, array_uri, array_settings = (
 | 
			
		||||
            self._get_array_controller_resource())
 | 
			
		||||
        array_uri_links = []
 | 
			
		||||
        # Do not raise exception if there is no ArrayControllers
 | 
			
		||||
        # as Storage can be zero at any point and if we raise
 | 
			
		||||
        # exception it might fail get_server_capabilities().
 | 
			
		||||
        if ('links' in array_settings and
 | 
			
		||||
                'Member' in array_settings['links']):
 | 
			
		||||
            array_uri_links = array_settings['links']['Member']
 | 
			
		||||
        else:
 | 
			
		||||
            msg = ('"links/Member" section in ArrayControllers'
 | 
			
		||||
                   ' does not exist')
 | 
			
		||||
            raise exception.IloCommandNotSupportedError(msg)
 | 
			
		||||
        return array_uri_links
 | 
			
		||||
 | 
			
		||||
    def _get_drive_type_and_speed(self):
 | 
			
		||||
@@ -396,6 +392,9 @@ class RISOperations(rest.RestConnectorBase, operations.IloOperations):
 | 
			
		||||
        """
 | 
			
		||||
        disk_details_list = []
 | 
			
		||||
        array_uri_links = self._create_list_of_array_controllers()
 | 
			
		||||
        # Do not raise exception if there is no disk/logical drive
 | 
			
		||||
        # as Storage can be zero at any point and if we raise
 | 
			
		||||
        # exception it might fail get_server_capabilities().
 | 
			
		||||
        for array_link in array_uri_links:
 | 
			
		||||
            _, _, member_settings = (
 | 
			
		||||
                self._rest_get(array_link['href']))
 | 
			
		||||
@@ -412,15 +411,6 @@ class RISOperations(rest.RestConnectorBase, operations.IloOperations):
 | 
			
		||||
                        _, _, disk_details = (
 | 
			
		||||
                            self._rest_get(diskdrive_uri))
 | 
			
		||||
                        disk_details_list.append(disk_details)
 | 
			
		||||
                else:
 | 
			
		||||
                    msg = ('"links/Member" section in %s'
 | 
			
		||||
                           ' does not exist', drive_name)
 | 
			
		||||
                    raise exception.IloCommandNotSupportedError(msg)
 | 
			
		||||
            else:
 | 
			
		||||
                msg = ('"links/%s" section in '
 | 
			
		||||
                       ' ArrayController/links/Member does not exist',
 | 
			
		||||
                       drive_name)
 | 
			
		||||
                raise exception.IloCommandNotSupportedError(msg)
 | 
			
		||||
        if disk_details_list:
 | 
			
		||||
            return disk_details_list
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4714,6 +4714,30 @@ ArrayControllers/0/DiskDrives"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
DISK_COLLECTION_NO_DISK = """
 | 
			
		||||
{
 | 
			
		||||
    "@odata.context": "/redfish/v1/$metadata#Systems/Members/1\
 | 
			
		||||
/SmartStorage/ArrayControllers/Members/2/DiskDrives",
 | 
			
		||||
    "@odata.id": "/redfish/v1/Systems/1/SmartStorage/ArrayControllers\
 | 
			
		||||
/2/DiskDrives/",
 | 
			
		||||
    "@odata.type": "\
 | 
			
		||||
#HpSmartStorageDiskDriveCollection.HpSmartStorageDiskDriveCollection",
 | 
			
		||||
    "Description": "HP Smart Storage Disk Drives View",
 | 
			
		||||
    "MemberType": "HpSmartStorageDiskDrive.1",
 | 
			
		||||
    "Members@odata.count": 0,
 | 
			
		||||
    "Name": "HpSmartStorageDiskDrives",
 | 
			
		||||
    "Total": 0,
 | 
			
		||||
    "Type": "Collection.1.0.0",
 | 
			
		||||
    "links": {
 | 
			
		||||
        "self": {
 | 
			
		||||
            "href": "/rest/v1/Systems/1/SmartStorage/ArrayControllers/0\
 | 
			
		||||
/DiskDrives"
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
DISK_DETAILS_LIST = """
 | 
			
		||||
[{
 | 
			
		||||
    "@odata.context": "/redfish/v1/$metadata#Systems/Members/1\
 | 
			
		||||
@@ -4784,6 +4808,29 @@ ArrayControllers/Members/0/LogicalDrives",
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
"""
 | 
			
		||||
LOGICAL_COLLECTION_NO_DRIVE = """
 | 
			
		||||
{
 | 
			
		||||
    "@odata.context": "/redfish/v1/$metadata#Systems/Members/1/SmartStorage/\
 | 
			
		||||
ArrayControllers/Members/0/LogicalDrives",
 | 
			
		||||
    "@odata.id": "/redfish/v1/Systems/1/SmartStorage/ArrayControllers/\
 | 
			
		||||
0/LogicalDrives/",
 | 
			
		||||
    "@odata.type": "\
 | 
			
		||||
#HpSmartStorageLogicalDriveCollection.HpSmartStorageLogicalDriveCollection",
 | 
			
		||||
    "Description": "HP Smart Storage Logical Drives View",
 | 
			
		||||
    "MemberType": "HpSmartStorageLogicalDrive.1",
 | 
			
		||||
    "Members@odata.count": 0,
 | 
			
		||||
    "Name": "HpSmartStorageLogicalDrives",
 | 
			
		||||
    "Total": 0,
 | 
			
		||||
    "Type": "Collection.1.0.0",
 | 
			
		||||
    "links": {
 | 
			
		||||
        "self": {
 | 
			
		||||
            "href": "/rest/v1/Systems/1/SmartStorage/ArrayControllers/0\
 | 
			
		||||
/LogicalDrives"
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
LOGICAL_DETAILS = """
 | 
			
		||||
[{
 | 
			
		||||
 
 | 
			
		||||
@@ -2323,19 +2323,6 @@ class TestRISOperationsPrivateMethods(testtools.TestCase):
 | 
			
		||||
                          self.client._get_array_controller_resource)
 | 
			
		||||
        get_mock.assert_called_once_with(array_uri)
 | 
			
		||||
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_get_storage_resource')
 | 
			
		||||
    def test__get_array_controller_resource_not_supported(self,
 | 
			
		||||
                                                          storage_mock):
 | 
			
		||||
        storage_data = json.loads(ris_outputs.STORAGE_SETTINGS)
 | 
			
		||||
        storage_uri = '/rest/v1/Systems/1/SmartStorage'
 | 
			
		||||
        del storage_data['links']['ArrayControllers']
 | 
			
		||||
        storage_mock.return_value = (ris_outputs.GET_HEADERS,
 | 
			
		||||
                                     storage_uri,
 | 
			
		||||
                                     storage_data)
 | 
			
		||||
        self.assertRaises(exception.IloCommandNotSupportedError,
 | 
			
		||||
                          self.client._get_array_controller_resource)
 | 
			
		||||
        storage_mock.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_get_array_controller_resource')
 | 
			
		||||
    def test__create_list_of_array_controllers(self, array_mock):
 | 
			
		||||
        array_data = json.loads(ris_outputs.ARRAY_SETTINGS)
 | 
			
		||||
@@ -2349,18 +2336,6 @@ class TestRISOperationsPrivateMethods(testtools.TestCase):
 | 
			
		||||
        self.assertEqual(expected_uri_links, uri_links)
 | 
			
		||||
        array_mock.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_get_array_controller_resource')
 | 
			
		||||
    def test__create_list_of_array_controllers_fail(self, array_mock):
 | 
			
		||||
        array_data = json.loads(ris_outputs.ARRAY_SETTINGS)
 | 
			
		||||
        array_uri = '/rest/v1/Systems/1/SmartStorage/ArrayControllers'
 | 
			
		||||
        del array_data['links']['Member']
 | 
			
		||||
        array_mock.return_value = (ris_outputs.GET_HEADERS,
 | 
			
		||||
                                   array_uri,
 | 
			
		||||
                                   array_data)
 | 
			
		||||
        self.assertRaises(exception.IloCommandNotSupportedError,
 | 
			
		||||
                          self.client._create_list_of_array_controllers)
 | 
			
		||||
        array_mock.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_get_physical_drive_resource')
 | 
			
		||||
    def test__get_drive_type_and_speed(self, disk_details_mock):
 | 
			
		||||
        disk_details_mock.return_value = (
 | 
			
		||||
@@ -2405,6 +2380,34 @@ class TestRISOperationsPrivateMethods(testtools.TestCase):
 | 
			
		||||
        self.assertEqual(expected_out, out)
 | 
			
		||||
        array_mock.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_create_list_of_array_controllers')
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_rest_get')
 | 
			
		||||
    def test__get_drive_resource_no_physical_disk(self, get_mock, array_mock):
 | 
			
		||||
        array_mock.return_value = (
 | 
			
		||||
            [{u'href': u'/rest/v1/Systems/1/SmartStorage/ArrayControllers/0'}])
 | 
			
		||||
        disk_col_no_disk = json.loads(ris_outputs.DISK_COLLECTION_NO_DISK)
 | 
			
		||||
        get_mock.side_effect = [(ris_outputs.GET_HEADERS, 'xyz',
 | 
			
		||||
                                 json.loads(ris_outputs.ARRAY_MEM_SETTINGS)),
 | 
			
		||||
                                (ris_outputs.GET_HEADERS, 'xyz',
 | 
			
		||||
                                 disk_col_no_disk)]
 | 
			
		||||
        out = self.client._get_physical_drive_resource()
 | 
			
		||||
        self.assertIsNone(out)
 | 
			
		||||
        array_mock.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_create_list_of_array_controllers')
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_rest_get')
 | 
			
		||||
    def test__get_drive_resource_no_logical_drive(self, get_mock, array_mock):
 | 
			
		||||
        array_mock.return_value = (
 | 
			
		||||
            [{u'href': u'/rest/v1/Systems/1/SmartStorage/ArrayControllers/0'}])
 | 
			
		||||
        log_col_no_drive = json.loads(ris_outputs.LOGICAL_COLLECTION_NO_DRIVE)
 | 
			
		||||
        get_mock.side_effect = [(ris_outputs.GET_HEADERS, 'xyz',
 | 
			
		||||
                                 json.loads(ris_outputs.ARRAY_MEM_SETTINGS)),
 | 
			
		||||
                                (ris_outputs.GET_HEADERS, 'xyz',
 | 
			
		||||
                                 log_col_no_drive)]
 | 
			
		||||
        out = self.client._get_physical_drive_resource()
 | 
			
		||||
        self.assertIsNone(out)
 | 
			
		||||
        array_mock.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
    @mock.patch.object(ris.RISOperations, '_get_pci_devices')
 | 
			
		||||
    def test__get_gpu_pci_devices(self, pci_mock):
 | 
			
		||||
        pci_mock.return_value = json.loads(ris_outputs.PCI_DEVICE_DETAILS)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user