def test_get_node_id_info(self): with self.assertRaises(array_errors.HostNotFoundError) as ex: utils.get_node_id_info("bad-node-format") self.assertTrue("node" in str(ex)) host_name = "host-name" nvme_nqn = "nqn.ibm" fc_wwns = "wwn1:wwn2" iscsi_iqn = "iqn.ibm" node_id_info = NodeIdInfo("{};;;{}".format(host_name, iscsi_iqn)) self._check_node_id_parameters(node_id_info, "", "", iscsi_iqn) node_id_info = NodeIdInfo("{};;{};{}".format(host_name, fc_wwns, iscsi_iqn)) self._check_node_id_parameters(node_id_info, "", fc_wwns, iscsi_iqn) node_id_info = NodeIdInfo("{};{};{}".format(host_name, nvme_nqn, fc_wwns)) self._check_node_id_parameters(node_id_info, nvme_nqn, fc_wwns, "") node_id_info = NodeIdInfo("{};{}".format(host_name, nvme_nqn)) self._check_node_id_parameters(node_id_info, nvme_nqn, "", "") node_id_info = NodeIdInfo("{};;{}".format(host_name, fc_wwns)) self._check_node_id_parameters(node_id_info, "", fc_wwns, "")
def ControllerUnpublishVolume(self, request, context): set_current_thread_name(request.volume_id) logger.info("ControllerUnpublishVolume") try: try: utils.validate_unpublish_volume_request(request) except ValidationException as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) return csi_pb2.ControllerUnpublishVolumeResponse() volume_id_info = utils.get_volume_id_info(request.volume_id) system_id = volume_id_info.system_id array_type = volume_id_info.array_type volume_id = volume_id_info.object_id node_id_info = NodeIdInfo(request.node_id) node_name = node_id_info.node_name initiators = node_id_info.initiators logger.debug( "node name for this unpublish operation is : {0}".format( node_name)) array_connection_info = utils.get_array_connection_info_from_secrets( request.secrets, system_id=system_id) with get_agent(array_connection_info, array_type).get_mediator() as array_mediator: array_mediator.unmap_volume_by_initiators( volume_id, initiators) logger.info("finished ControllerUnpublishVolume") return csi_pb2.ControllerUnpublishVolumeResponse() except array_errors.VolumeAlreadyUnmappedError: logger.debug("Idempotent case. volume is already unmapped.") return csi_pb2.ControllerUnpublishVolumeResponse() except array_errors.ObjectNotFoundError as ex: logger.debug("Idempotent case. volume is already deleted.") return csi_pb2.ControllerUnpublishVolumeResponse() except array_errors.PermissionDeniedError as ex: context.set_code(grpc.StatusCode.PERMISSION_DENIED) context.set_details(ex.message) return csi_pb2.ControllerUnpublishVolumeResponse() except array_errors.HostNotFoundError as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.NOT_FOUND) return csi_pb2.ControllerUnpublishVolumeResponse() except Exception as ex: logger.debug("an internal exception occurred") logger.exception(ex) context.set_code(grpc.StatusCode.INTERNAL) context.set_details( 'an internal exception occurred : {}'.format(ex)) return csi_pb2.ControllerUnpublishVolumeResponse()
def ControllerPublishVolume(self, request, context): set_current_thread_name(request.volume_id) logger.info("ControllerPublishVolume") try: utils.validate_publish_volume_request(request) array_type, vol_id = utils.get_volume_id_info(request.volume_id) node_id_info = NodeIdInfo(request.node_id) node_name = node_id_info.node_name initiators = node_id_info.initiators logger.debug("node name for this publish operation is : {0}".format(node_name)) user, password, array_addresses = utils.get_array_connection_info_from_secret(request.secrets) lun, connectivity_type, array_initiators = map_volume(user, password, array_addresses, array_type, vol_id, initiators) logger.info("finished ControllerPublishVolume") res = utils.generate_csi_publish_volume_response(lun, connectivity_type, self.cfg, array_initiators) return res except controller_errors.VolumeMappedToMultipleHostsError as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.FAILED_PRECONDITION) return csi_pb2.ControllerPublishVolumeResponse() except controller_errors.PermissionDeniedError as ex: context.set_code(grpc.StatusCode.PERMISSION_DENIED) context.set_details(ex) return csi_pb2.ControllerPublishVolumeResponse() except (controller_errors.LunAlreadyInUseError, controller_errors.NoAvailableLunError) as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.RESOURCE_EXHAUSTED) return csi_pb2.ControllerPublishVolumeResponse() except (controller_errors.HostNotFoundError, controller_errors.VolumeNotFoundError, controller_errors.BadNodeIdError) as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.NOT_FOUND) return csi_pb2.ControllerPublishVolumeResponse() except ValidationException as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) return csi_pb2.ControllerPublishVolumeResponse() except Exception as ex: logger.debug("an internal exception occurred") logger.exception(ex) context.set_code(grpc.StatusCode.INTERNAL) context.set_details('an internal exception occurred : {}'.format(ex)) return csi_pb2.ControllerPublishVolumeResponse()
def ControllerUnpublishVolume(self, request, context): set_current_thread_name(request.volume_id) logger.info("ControllerUnpublishVolume") try: try: utils.validate_unpublish_volume_request(request) except ValidationException as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) return csi_pb2.ControllerUnpublishVolumeResponse() array_type, vol_id = utils.get_volume_id_info(request.volume_id) node_id_info = NodeIdInfo(request.node_id) node_name = node_id_info.node_name initiators = node_id_info.initiators logger.debug("node name for this unpublish operation is : {0}".format(node_name)) user, password, array_addresses = utils.get_array_connection_info_from_secret(request.secrets) unmap_volume(user, password, array_addresses, array_type, vol_id, initiators) logger.info("finished ControllerUnpublishVolume") return csi_pb2.ControllerUnpublishVolumeResponse() except controller_errors.VolumeAlreadyUnmappedError as ex: logger.debug("Idempotent case. volume is already unmapped.") return csi_pb2.ControllerUnpublishVolumeResponse() except controller_errors.PermissionDeniedError as ex: context.set_code(grpc.StatusCode.PERMISSION_DENIED) context.set_details(ex) return csi_pb2.ControllerPublishVolumeResponse() except (controller_errors.HostNotFoundError, controller_errors.VolumeNotFoundError) as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.NOT_FOUND) return csi_pb2.ControllerUnpublishVolumeResponse() except Exception as ex: logger.debug("an internal exception occurred") logger.exception(ex) context.set_code(grpc.StatusCode.INTERNAL) context.set_details('an internal exception occurred : {}'.format(ex)) return csi_pb2.ControllerUnpublishVolumeResponse()
def ControllerPublishVolume(self, request, context): set_current_thread_name(request.volume_id) logger.info("ControllerPublishVolume") utils.validate_publish_volume_request(request) try: volume_id_info = utils.get_volume_id_info(request.volume_id) system_id = volume_id_info.system_id array_type = volume_id_info.array_type volume_id = volume_id_info.object_id node_id_info = NodeIdInfo(request.node_id) node_name = node_id_info.node_name initiators = node_id_info.initiators logger.debug( "node name for this publish operation is : {0}".format( node_name)) array_connection_info = utils.get_array_connection_info_from_secrets( request.secrets, system_id=system_id) with get_agent(array_connection_info, array_type).get_mediator() as array_mediator: lun, connectivity_type, array_initiators = array_mediator.map_volume_by_initiators( volume_id, initiators) logger.info("finished ControllerPublishVolume") res = utils.generate_csi_publish_volume_response( lun, connectivity_type, self.cfg, array_initiators) return res except array_errors.VolumeMappedToMultipleHostsError as ex: return handle_exception(ex, context, grpc.StatusCode.FAILED_PRECONDITION, csi_pb2.ControllerPublishVolumeResponse) except (array_errors.LunAlreadyInUseError, array_errors.NoAvailableLunError) as ex: return handle_exception(ex, context, grpc.StatusCode.RESOURCE_EXHAUSTED, csi_pb2.ControllerPublishVolumeResponse) except (array_errors.NoIscsiTargetsFoundError, ObjectIdError) as ex: return handle_exception(ex, context, grpc.StatusCode.NOT_FOUND, csi_pb2.ControllerPublishVolumeResponse) except array_errors.UnsupportedConnectivityTypeError as ex: return handle_exception(ex, context, grpc.StatusCode.INVALID_ARGUMENT, csi_pb2.ControllerPublishVolumeResponse)
def ControllerUnpublishVolume(self, request, context): set_current_thread_name(request.volume_id) logger.info("ControllerUnpublishVolume") utils.validate_unpublish_volume_request(request) try: volume_id_info = utils.get_volume_id_info(request.volume_id) system_id = volume_id_info.system_id array_type = volume_id_info.array_type volume_id = volume_id_info.object_id node_id_info = NodeIdInfo(request.node_id) node_name = node_id_info.node_name initiators = node_id_info.initiators logger.debug( "node name for this unpublish operation is : {0}".format( node_name)) array_connection_info = utils.get_array_connection_info_from_secrets( request.secrets, system_id=system_id) with get_agent(array_connection_info, array_type).get_mediator() as array_mediator: array_mediator.unmap_volume_by_initiators( volume_id, initiators) logger.info("finished ControllerUnpublishVolume") return csi_pb2.ControllerUnpublishVolumeResponse() except ObjectIdError as ex: return handle_exception(ex, context, grpc.StatusCode.INVALID_ARGUMENT, array_errors.VolumeAlreadyUnmappedError) except array_errors.VolumeAlreadyUnmappedError: logger.debug("Idempotent case. volume is already unmapped.") return csi_pb2.ControllerUnpublishVolumeResponse() except array_errors.ObjectNotFoundError: logger.debug("Idempotent case. volume is already deleted.") return csi_pb2.ControllerUnpublishVolumeResponse()
def ControllerPublishVolume(self, request, context): set_current_thread_name(request.volume_id) logger.info("ControllerPublishVolume") try: utils.validate_publish_volume_request(request) volume_id_info = utils.get_volume_id_info(request.volume_id) system_id = volume_id_info.system_id array_type = volume_id_info.array_type volume_id = volume_id_info.object_id node_id_info = NodeIdInfo(request.node_id) node_name = node_id_info.node_name initiators = node_id_info.initiators logger.debug( "node name for this publish operation is : {0}".format( node_name)) array_connection_info = utils.get_array_connection_info_from_secrets( request.secrets, system_id=system_id) with get_agent(array_connection_info, array_type).get_mediator() as array_mediator: lun, connectivity_type, array_initiators = array_mediator.map_volume_by_initiators( volume_id, initiators) logger.info("finished ControllerPublishVolume") res = utils.generate_csi_publish_volume_response( lun, connectivity_type, self.cfg, array_initiators) return res except array_errors.VolumeMappedToMultipleHostsError as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.FAILED_PRECONDITION) return csi_pb2.ControllerPublishVolumeResponse() except array_errors.PermissionDeniedError as ex: context.set_code(grpc.StatusCode.PERMISSION_DENIED) context.set_details(ex.message) return csi_pb2.ControllerPublishVolumeResponse() except (array_errors.LunAlreadyInUseError, array_errors.NoAvailableLunError) as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.RESOURCE_EXHAUSTED) return csi_pb2.ControllerPublishVolumeResponse() except (array_errors.HostNotFoundError, array_errors.ObjectNotFoundError, array_errors.NoIscsiTargetsFoundError, ObjectIdError) as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.NOT_FOUND) return csi_pb2.ControllerPublishVolumeResponse() except (ValidationException, array_errors.IllegalObjectID, array_errors.UnsupportedConnectivityTypeError) as ex: logger.exception(ex) context.set_details(ex.message) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) return csi_pb2.ControllerPublishVolumeResponse() except Exception as ex: logger.debug("an internal exception occurred") logger.exception(ex) context.set_code(grpc.StatusCode.INTERNAL) context.set_details( 'an internal exception occurred : {}'.format(ex)) return csi_pb2.ControllerPublishVolumeResponse()