def get_host_by_host_identifiers(self, initiators): logger.debug( "Getting host name for initiators : {0}".format(initiators)) detailed_hosts_list = self._get_detailed_hosts_list() iscsi_host, fc_host = None, None for host in detailed_hosts_list: if initiators.is_array_iscsi_iqns_match(host.iscsi_names): iscsi_host = host.name logger.debug("found iscsi iqn in list : {0} for host : " "{1}".format(initiators.iscsi_iqn, iscsi_host)) if initiators.is_array_wwns_match(host.wwns): fc_host = host.name logger.debug("found fc wwns in list : {0} for host : " "{1}".format(initiators.fc_wwns, fc_host)) if iscsi_host and fc_host: if iscsi_host == fc_host: return fc_host, [ config.ISCSI_CONNECTIVITY_TYPE, config.FC_CONNECTIVITY_TYPE ] raise array_errors.MultipleHostsFoundError(initiators, fc_host) if iscsi_host: logger.debug("found host : {0} with iqn : {1}".format( iscsi_host, initiators.iscsi_iqn)) return iscsi_host, [config.ISCSI_CONNECTIVITY_TYPE] if fc_host: logger.debug("found host : {0} with fc wwn : {1}".format( fc_host, initiators.fc_wwns)) return fc_host, [config.FC_CONNECTIVITY_TYPE] logger.debug( "can not found host by using initiators: {0} ".format(initiators)) raise array_errors.HostNotFoundError(initiators)
def get_host_by_host_identifiers(self, initiators): logger.debug("Getting host id for initiators : {0}".format(initiators)) host_list = self.client.svcinfo.lshost() iscsi_host, fc_host = None, None for host in host_list: host_detail = self.client.svcinfo.lshost( object_id=host.get('id', '')).as_single_element iscsi_names = host_detail.get('iscsi_name', '') wwns_value = host_detail.get('WWPN', []) if not isinstance(wwns_value, list): wwns_value = [wwns_value, ] if initiators.is_array_iscsi_iqns_match([iscsi_names]): iscsi_host = host_detail.get('name', '') logger.debug("found iscsi iqn in list : {0} for host : " "{1}".format(initiators.iscsi_iqn, iscsi_host)) if initiators.is_array_wwns_match(wwns_value): fc_host = host_detail.get('name', '') logger.debug("found fc wwns in list : {0} for host : " "{1}".format(initiators.fc_wwns, fc_host)) if iscsi_host and fc_host: if iscsi_host == fc_host: return fc_host, [config.ISCSI_CONNECTIVITY_TYPE, config.FC_CONNECTIVITY_TYPE] else: raise controller_errors.MultipleHostsFoundError(initiators, fc_host) elif iscsi_host: logger.debug("found host : {0} with iqn : {1}".format(iscsi_host, initiators.iscsi_iqn)) return iscsi_host, [config.ISCSI_CONNECTIVITY_TYPE] elif fc_host: logger.debug("found host : {0} with fc wwn : {1}".format(fc_host, initiators.fc_wwns)) return fc_host, [config.FC_CONNECTIVITY_TYPE] else: logger.debug("can not found host by using initiators: {0} ".format(initiators)) raise controller_errors.HostNotFoundError(initiators)
def get_host_by_host_identifiers(self, initiators): logger.debug("Getting host id for initiators : {0}".format(initiators)) matching_hosts_set = set() port_types = [] host_list = self.client.cmd.host_list().as_list for host in host_list: host_iscsi_ports = string_to_array(host.iscsi_ports, ',') host_fc_ports = string_to_array(host.fc_ports, ',') if initiators.is_array_wwns_match(host_fc_ports): matching_hosts_set.add(host.name) logger.debug("found host : {0}, by fc port : {1}".format( host.name, host_fc_ports)) port_types.append(FC_CONNECTIVITY_TYPE) if initiators.is_array_iscsi_iqns_match(host_iscsi_ports): matching_hosts_set.add(host.name) logger.debug("found host : {0}, by iscsi port : {1}".format( host.name, host_iscsi_ports)) port_types.append(ISCSI_CONNECTIVITY_TYPE) matching_hosts = sorted(matching_hosts_set) if not matching_hosts: raise controller_errors.HostNotFoundError(initiators) elif len(matching_hosts) > 1: raise controller_errors.MultipleHostsFoundError( initiators, matching_hosts) return matching_hosts[0], port_types
def test_unpublish_volume_get_host_by_host_identifiers_exception(self, enter): context = utils.FakeContext() self.mediator.get_host_by_host_identifiers = Mock() self.mediator.get_host_by_host_identifiers.side_effect = [array_errors.MultipleHostsFoundError("", "")] enter.return_value = self.mediator self.servicer.ControllerUnpublishVolume(self.request, context) self.assertTrue("Multiple hosts" in context.details) self.assertEqual(context.code, grpc.StatusCode.INTERNAL) self.mediator.get_host_by_host_identifiers.side_effect = [array_errors.HostNotFoundError("")] enter.return_value = self.mediator self.servicer.ControllerUnpublishVolume(self.request, context) self.assertEqual(context.code, grpc.StatusCode.NOT_FOUND)