def get_storage_drive_details(resource_block_uuid, storage_id, drive_id):
    """Get the Redfish Drive details of a Storage of a Storage Resource Block

        Return Drive redfish JSON for a given ID.
        Logs exception of any error and return Internal Server
        Error or Not Found.

        Returns:
            JSON: Redfish json with Drive detail information.
    """

    drive = g.oneview_client.index_resources.get('/rest/drives/' +
                                                 resource_block_uuid)

    if str(storage_id) != FROZEN_ID:
        abort(
            status.HTTP_404_NOT_FOUND,
            "Storage {} not found for ResourceBlock {}".format(
                storage_id, resource_block_uuid))

    if str(drive_id) != FROZEN_ID:
        abort(
            status.HTTP_404_NOT_FOUND,
            "Drive {} not found for Storage {} of ResourceBlock {}".format(
                drive_id, storage_id, resource_block_uuid))

    drive_encl_uri = drive["attributes"]["driveEnclosureUri"].split('/')[-1]
    drive_enclosure = g.oneview_client.drive_enclosures.get(drive_encl_uri)
    result = Drive.build_for_resource_block(drive, drive_enclosure)

    return ResponseBuilder.success(result)
    def test_build_for_resource_block(self):
        with open('oneview_redfish_toolkit/mockups/redfish'
                  '/DriveForResourceBlock.json') as f:
            expected_result = json.load(f)

        target = Drive.build_for_resource_block(self.drive,
                                                self.drive_enclosure)
        result = json.loads(target.serialize())

        self.assertEqualMockup(expected_result, result)
    def test_build_for_computer_system(self):
        with open('oneview_redfish_toolkit/mockups/redfish/Drive.json') as f:
            expected_result = json.load(f)

        target = Drive.build_for_computer_system(4, self.server_profile,
                                                 self.sas_logical_jbods[1])

        result = json.loads(target.serialize())

        self.assertEqualMockup(expected_result, result)
    def test_build_for_resource_block_with_unknown_mediaType(self):

        drive = copy.deepcopy(self.drive)

        drive["attributes"]["mediaType"] = "Unknown"

        drive = Drive.build_for_resource_block(drive, self.drive_enclosure)

        result = json.loads(drive.serialize())

        self.assertEqualMockup(self.drive_with_mediaType_null_rb, result)
    def test_build_for_composed_system_with_unknown_mediaType(self):

        sas_logical_jbods = copy.deepcopy(self.sas_logical_jbods[1])

        sas_logical_jbods["driveTechnology"]["driveMedia"] = "Unknown"

        drive = Drive.build_for_computer_system("4", self.server_profile,
                                                sas_logical_jbods)

        result = json.loads(drive.serialize())

        self.assertEqualMockup(self.drive_with_mediaType_null, result)
Пример #6
0
def get_drive(profile_id, drive_id):
    """Get the Redfish Storage for a given UUID.

        Return Drive Redfish JSON for a given server profile UUID and Drive ID.
        Logs exception of any error and return abort(500)
        Internal Server Error.

        Returns:
            JSON: Redfish json with Storage
            When server profile is not found calls abort(404)

        Exceptions:
            Logs the exception and call abort(500)

    """

    drive_id_int = None
    logical_jbod = None
    try:
        drive_id_int = int(drive_id)
    except ValueError:
        abort(status.HTTP_400_BAD_REQUEST, "Drive id should be a integer")

    server_profile = g.oneview_client.server_profiles.get_by_id(
        profile_id).data
    sas_logical_jbods = _find_sas_logical_jbods_by(server_profile)

    logical_jbod = _get_logical_jbod(drive_id_int, logical_jbod,
                                     sas_logical_jbods)

    if logical_jbod is None:
        abort(status.HTTP_404_NOT_FOUND, "Drive {} not found"
              .format(drive_id))

    drive_details = Drive.build_for_computer_system(drive_id_int,
                                                    server_profile,
                                                    logical_jbod)

    return ResponseBuilder.success(drive_details)