Example #1
0
    def map_volume(self, volume_id, host_name):
        logger.debug("mapping volume : {0} to host : "
                     "{1}".format(volume_id, host_name))
        vol_name = self._get_volume_name_by_wwn(volume_id)
        cli_kwargs = {'host': host_name, 'object_id': vol_name, 'force': True}

        try:
            lun = self.get_first_free_lun(host_name)
            cli_kwargs.update({'scsi': lun})
            self.client.svctask.mkvdiskhostmap(**cli_kwargs)
        except (svc_errors.CommandExecutionError, CLIFailureError) as ex:
            if not is_warning_message(ex.my_message):
                logger.error(msg="Map volume {0} to host {1} failed. Reason "
                             "is: {2}".format(vol_name, host_name, ex))
                if NAME_NOT_EXIST_OR_MEET_RULES in ex.my_message:
                    raise array_errors.HostNotFoundError(host_name)
                if SPECIFIED_OBJ_NOT_EXIST in ex.my_message:
                    raise array_errors.ObjectNotFoundError(vol_name)
                if LUN_ALREADY_IN_USE in ex.my_message:
                    raise array_errors.LunAlreadyInUseError(lun, host_name)
                raise array_errors.MappingError(vol_name, host_name, ex)
        except Exception as ex:
            logger.exception(ex)
            raise ex

        return str(lun)
    def map_volume(self, volume_id, host_name):
        logger.debug("mapping volume : {0} to host : {1}".format(
            volume_id, host_name))
        vol_name = self._get_object_name_by_wwn(volume_id)
        lun = self._get_next_available_lun(host_name)

        try:
            self.client.cmd.map_vol(host=host_name, vol=vol_name, lun=lun)
        except xcli_errors.OperationForbiddenForUserCategoryError as ex:
            logger.exception(ex)
            raise controller_errors.PermissionDeniedError(
                "map volume : {0} to host : {1}".format(volume_id, host_name))
        except xcli_errors.VolumeBadNameError as ex:
            logger.exception(ex)
            raise controller_errors.ObjectNotFoundError(vol_name)
        except xcli_errors.HostBadNameError as ex:
            logger.exception(ex)
            raise controller_errors.HostNotFoundError(host_name)
        except xcli_errors.CommandFailedRuntimeError as ex:
            logger.exception(ex)
            if LUN_IS_ALREADY_IN_USE_ERROR in ex.status:
                raise controller_errors.LunAlreadyInUseError(lun, host_name)
            else:
                raise controller_errors.MappingError(vol_name, host_name, ex)

        return str(lun)
    def test_publish_volume_map_volume_lun_already_in_use(self, enter):
        context = utils.FakeContext()

        self.mediator.map_volume.side_effect = [
            array_errors.LunAlreadyInUseError("", ""), 2
        ]
        self.mediator.map_volume.get_array_iqns.return_value = "array-iqn"
        enter.return_value = self.mediator
        res = self.servicer.ControllerPublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.OK)
        self.assertEqual(res.publish_context["PUBLISH_CONTEXT_LUN"], '2')
        self.assertEqual(res.publish_context["PUBLISH_CONTEXT_CONNECTIVITY"],
                         "iscsi")

        self.mediator.map_volume.side_effect = [
            array_errors.LunAlreadyInUseError("", ""), 2
        ]
        self.mediator.get_host_by_host_identifiers = Mock()
        self.mediator.get_host_by_host_identifiers.return_value = self.hostname, [
            "fc"
        ]
        self.mediator.get_array_fc_wwns = Mock()
        self.mediator.get_array_fc_wwns.return_value = ["500143802426baf4"]
        enter.return_value = self.mediator
        res = self.servicer.ControllerPublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.OK)
        self.assertEqual(res.publish_context["PUBLISH_CONTEXT_LUN"], '2')
        self.assertEqual(res.publish_context["PUBLISH_CONTEXT_CONNECTIVITY"],
                         "fc")

        self.mediator.map_volume.side_effect = [
            array_errors.LunAlreadyInUseError("", ""),
            array_errors.LunAlreadyInUseError("", ""), 2
        ]
        enter.return_value = self.mediator
        self.servicer.ControllerPublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.OK)
        self.assertEqual(res.publish_context["PUBLISH_CONTEXT_LUN"], '2')
        self.assertEqual(res.publish_context["PUBLISH_CONTEXT_CONNECTIVITY"],
                         "fc")

        self.mediator.map_volume.side_effect = [
            array_errors.LunAlreadyInUseError("", "")
        ] * (self.mediator.max_lun_retries + 1)
        enter.return_value = self.mediator
        self.servicer.ControllerPublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.RESOURCE_EXHAUSTED)