def unmap_volume(self, volume_id, host_name):
        logger.debug("un-mapping volume : {0} from host : {1}".format(
            volume_id, host_name))

        vol_name = self._get_object_name_by_wwn(volume_id)

        try:
            self.client.cmd.unmap_vol(host=host_name, vol=vol_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.OperationForbiddenForUserCategoryError as ex:
            logger.exception(ex)
            raise controller_errors.PermissionDeniedError(
                "unmap volume : {0} from host : {1}".format(
                    volume_id, host_name))
        except xcli_errors.CommandFailedRuntimeError as ex:
            logger.exception(ex)
            if UNDEFINED_MAPPING_ERROR in ex.status:
                raise controller_errors.VolumeAlreadyUnmappedError(vol_name)
            else:
                raise controller_errors.UnMappingError(vol_name, host_name, ex)
Exemple #2
0
    def unmap_volume(self, volume_id, host_name):
        logger.debug("un-mapping volume : {0} from host : "
                     "{1}".format(volume_id, host_name))
        vol_name = self._get_vol_by_wwn(volume_id)

        cli_kwargs = {
            'host': host_name,
            'vdisk_id': vol_name
        }

        try:
            self.client.svctask.rmvdiskhostmap(**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_MEET in ex.my_message:
                    raise controller_errors.HostNotFoundError(host_name)
                if OBJ_NOT_FOUND in ex.my_message:
                    raise controller_errors.VolumeNotFoundError(vol_name)
                if VOL_ALREADY_UNMAPPED in ex.my_message:
                    raise controller_errors.VolumeAlreadyUnmappedError(
                        vol_name)
                raise controller_errors.UnMappingError(vol_name,
                                                       host_name, ex)
        except Exception as ex:
            logger.exception(ex)
            raise ex
    def test_unpublish_volume_unmap_volume_excpetions(self, enter):
        context = utils.FakeContext()

        self.mediator.unmap_volume.side_effect = [array_errors.PermissionDeniedError("msg")]
        enter.return_value = self.mediator
        self.servicer.ControllerUnpublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.PERMISSION_DENIED)

        context = utils.FakeContext()
        self.mediator.unmap_volume.side_effect = [array_errors.VolumeNotFoundError("vol")]
        enter.return_value = self.mediator
        self.servicer.ControllerUnpublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.NOT_FOUND)

        context = utils.FakeContext()
        self.mediator.unmap_volume.side_effect = [array_errors.HostNotFoundError("host")]
        enter.return_value = self.mediator
        self.servicer.ControllerUnpublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.NOT_FOUND)

        context = utils.FakeContext()
        self.mediator.unmap_volume.side_effect = [array_errors.UnMappingError("", "", "")]
        enter.return_value = self.mediator
        self.servicer.ControllerUnpublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.INTERNAL)

        context = utils.FakeContext()
        self.mediator.unmap_volume.side_effect = [array_errors.VolumeAlreadyUnmappedError("")]
        enter.return_value = self.mediator
        self.servicer.ControllerUnpublishVolume(self.request, context)
        self.assertEqual(context.code, grpc.StatusCode.OK)
 def unmap_volume(self, volume_id, host_name):
     logger.debug("Unmapping volume {} from host {}".format(
         volume_id, host_name))
     try:
         mappings = self.client.get_host_mappings(host_name)
         lunid = None
         for mapping in mappings:
             if mapping.volume == volume_id:
                 lunid = mapping.id
                 break
         if lunid is not None:
             self.client.unmap_volume_from_host(host_name=host_name,
                                                lunid=lunid)
             logger.debug(
                 "Successfully unmapped volume from host with lun {}.".
                 format(lunid))
         else:
             raise array_errors.ObjectNotFoundError(volume_id)
     except exceptions.NotFound:
         raise array_errors.HostNotFoundError(host_name)
     except exceptions.ClientException as ex:
         raise array_errors.UnMappingError(volume_id, host_name, ex.details)