def test_choose_connectivity_types(self): res = utils.choose_connectivity_type(["iscsi"]) self.assertEqual(res, "iscsi") res = utils.choose_connectivity_type(["fc"]) self.assertEqual(res, "fc") res = utils.choose_connectivity_type(["iscsi", "fc"]) self.assertEqual(res, "fc")
def map_volume(user, password, array_addresses, array_type, vol_id, initiators): with ArrayConnectionManager(user, password, array_addresses, array_type) as array_mediator: host_name, connectivity_types = array_mediator.get_host_by_host_identifiers( initiators) logger.debug("hostname : {}, connectivity_types : {}".format( host_name, connectivity_types)) connectivity_type = utils.choose_connectivity_type(connectivity_types) if FC_CONNECTIVITY_TYPE == connectivity_type: array_initiators = array_mediator.get_array_fc_wwns(host_name) else: array_initiators = array_mediator.get_array_iqns() mappings = array_mediator.get_volume_mappings(vol_id) if len(mappings) >= 1: logger.debug( "{0} mappings have been found for volume. the mappings are: {1}" .format(len(mappings), mappings)) if len(mappings) == 1: mapping = list(mappings)[0] if mapping == host_name: logger.debug( "idempotent case - volume is already mapped to host.") return mappings[ mapping], connectivity_type, array_initiators raise controller_errors.VolumeMappedToMultipleHostsError(mappings) logger.debug( "no mappings were found for volume. mapping vol : {0} to host : {1}" .format(vol_id, host_name)) try: lun = array_mediator.map_volume(vol_id, host_name) logger.debug("lun : {}".format(lun)) except controller_errors.LunAlreadyInUseError as ex: logger.warning( "Lun was already in use. re-trying the operation. {0}".format( ex)) for i in range(array_mediator.max_lun_retries - 1): try: lun = array_mediator.map_volume(vol_id, host_name) break except controller_errors.LunAlreadyInUseError as inner_ex: logger.warning( "re-trying map volume. try #{0}. {1}".format( i, inner_ex)) else: # will get here only if the for statement is false. raise ex return lun, connectivity_type, array_initiators
def test_choose_connectivity_types(self): nvme = NVME_OVER_FC_CONNECTIVITY_TYPE fc = FC_CONNECTIVITY_TYPE iscsi = ISCSI_CONNECTIVITY_TYPE expected_chosen_by_connectivities_found = { (nvme, fc, iscsi): nvme, (fc, iscsi): fc, (nvme, ): nvme, (fc, ): fc, (iscsi, ): iscsi } for connectivities_found, expected_chosen_connectivity in expected_chosen_by_connectivities_found.items( ): actual_chosen = utils.choose_connectivity_type( list(connectivities_found)) self.assertEqual(actual_chosen, expected_chosen_connectivity)
def map_volume_by_initiators(self, vol_id, initiators): host_name, connectivity_types = self.get_host_by_host_identifiers(initiators) logger.debug("hostname : {}, connectivity_types : {}".format(host_name, connectivity_types)) connectivity_type = utils.choose_connectivity_type(connectivity_types) if NVME_OVER_FC_CONNECTIVITY_TYPE == connectivity_type: array_initiators = [] elif FC_CONNECTIVITY_TYPE == connectivity_type: array_initiators = self.get_array_fc_wwns(host_name) elif ISCSI_CONNECTIVITY_TYPE == connectivity_type: array_initiators = self.get_iscsi_targets_by_iqn(host_name) else: raise UnsupportedConnectivityTypeError(connectivity_type) mappings = self.get_volume_mappings(vol_id) if len(mappings) >= 1: logger.debug( "{0} mappings have been found for volume. the mappings are: {1}".format(len(mappings), mappings)) if len(mappings) == 1: mapping = list(mappings)[0] if mapping == host_name: logger.debug("idempotent case - volume is already mapped to host.") return mappings[mapping], connectivity_type, array_initiators raise array_errors.VolumeMappedToMultipleHostsError(mappings) logger.debug("no mappings were found for volume. mapping volume : {0} to host : {1}".format(vol_id, host_name)) try: lun = self.map_volume(vol_id, host_name, connectivity_type) logger.debug("lun : {}".format(lun)) except array_errors.LunAlreadyInUseError as ex: logger.warning("Lun was already in use. re-trying the operation. {0}".format(ex)) for i in range(self.max_lun_retries - 1): try: lun = self.map_volume(vol_id, host_name, connectivity_type) break except array_errors.LunAlreadyInUseError as inner_ex: logger.warning( "re-trying map volume. try #{0}. {1}".format(i, inner_ex)) else: # will get here only if the for statement is false. raise ex return lun, connectivity_type, array_initiators
def unmap_volume_by_initiators(self, vol_id, initiators): host_name, connectivity_types = self.get_host_by_host_identifiers(initiators) connectivity_type = utils.choose_connectivity_type(connectivity_types) if connectivity_type == NVME_OVER_FC_CONNECTIVITY_TYPE: vol_id = convert_scsi_id_to_nguid(vol_id) self.unmap_volume(vol_id, host_name)