def create_iscsi_target(self, name, tid, lun, path, chap_auth=None, **kwargs): # NOTE (jdg): Address bug: 1175207 kwargs.pop('old_name', None) self._new_target(name, tid, **kwargs) self._new_logicalunit(tid, lun, path, **kwargs) if chap_auth is not None: (type, username, password) = chap_auth.split() self._new_auth(tid, type, username, password, **kwargs) conf_file = self.iet_conf if os.path.exists(conf_file): try: volume_conf = """ Target %s %s Lun 0 Path=%s,Type=%s """ % (name, chap_auth, path, self._iotype(path)) with utils.temporary_chown(conf_file): f = open(conf_file, 'a+') f.write(volume_conf) f.close() except putils.ProcessExecutionError as e: vol_id = name.split(':')[1] LOG.error(_("Failed to create iscsi target for volume " "id:%(vol_id)s: %(e)s") % {'vol_id': vol_id, 'e': e}) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) return tid
def create_iscsi_target(self, name, tid, lun, path, chap_auth=None, **kwargs): # tid and lun are not used vol_id = name.split(':')[1] LOG.info(_('Creating iscsi_target for volume: %s') % vol_id) # rtstool requires chap_auth, but unit tests don't provide it chap_auth_userid = 'test_id' chap_auth_password = '******' if chap_auth is not None: (chap_auth_userid, chap_auth_password) = chap_auth.split(' ')[1:] extra_args = [] if self.lio_initiator_iqns: extra_args.append(self.lio_initiator_iqns) try: command_args = [ 'cinder-rtstool', 'create', path, name, chap_auth_userid, chap_auth_password ] if extra_args: command_args.extend(extra_args) self._execute(*command_args, run_as_root=True) except putils.ProcessExecutionError as e: LOG.error( _("Failed to create iscsi target for volume " "id:%s.") % vol_id) LOG.error("%s" % e) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) iqn = '%s%s' % (self.iscsi_target_prefix, vol_id) tid = self._get_target(iqn) if tid is None: LOG.error( _("Failed to create iscsi target for volume " "id:%s.") % vol_id) raise exception.NotFound() return tid
def create_iscsi_target(self, name, tid, lun, path, chap_auth=None, **kwargs): # Note(jdg) tid and lun aren't used by TgtAdm but remain for # compatibility fileutils.ensure_tree(self.volumes_dir) vol_id = name.split(':')[1] write_cache = kwargs.get('write_cache', 'on') if chap_auth is None: volume_conf = self.VOLUME_CONF % (name, path, write_cache) else: volume_conf = self.VOLUME_CONF_WITH_CHAP_AUTH % (name, path, chap_auth, write_cache) LOG.info(_('Creating iscsi_target for: %s') % vol_id) volumes_dir = self.volumes_dir volume_path = os.path.join(volumes_dir, vol_id) f = open(volume_path, 'w+') f.write(volume_conf) f.close() LOG.debug('Created volume path %(vp)s,\n' 'content: %(vc)s' % {'vp': volume_path, 'vc': volume_conf}) old_persist_file = None old_name = kwargs.get('old_name', None) if old_name is not None: old_persist_file = os.path.join(volumes_dir, old_name) try: # with the persistent tgts we create them # by creating the entry in the persist file # and then doing an update to get the target # created. (out, err) = self._execute('tgt-admin', '--update', name, run_as_root=True) LOG.debug("StdOut from tgt-admin --update: %s", out) LOG.debug("StdErr from tgt-admin --update: %s", err) # Grab targets list for debug # Consider adding a check for lun 0 and 1 for tgtadm # before considering this as valid (out, err) = self._execute('tgtadm', '--lld', 'iscsi', '--op', 'show', '--mode', 'target', run_as_root=True) LOG.debug("Targets after update: %s" % out) except putils.ProcessExecutionError as e: LOG.warning(_("Failed to create iscsi target for volume " "id:%(vol_id)s: %(e)s") % {'vol_id': vol_id, 'e': e}) #Don't forget to remove the persistent file we created os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) iqn = '%s%s' % (self.iscsi_target_prefix, vol_id) tid = self._get_target(iqn) if tid is None: LOG.error(_("Failed to create iscsi target for volume " "id:%(vol_id)s. Please ensure your tgtd config file " "contains 'include %(volumes_dir)s/*'") % { 'vol_id': vol_id, 'volumes_dir': volumes_dir, }) raise exception.NotFound() # NOTE(jdg): Sometimes we have some issues with the backing lun # not being created, believe this is due to a device busy # or something related, so we're going to add some code # here that verifies the backing lun (lun 1) was created # and we'll try and recreate it if it's not there if not self._verify_backing_lun(iqn, tid): try: self._recreate_backing_lun(iqn, tid, name, path) except putils.ProcessExecutionError: os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) # Finally check once more and if no go, fail and punt if not self._verify_backing_lun(iqn, tid): os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) if old_persist_file is not None and os.path.exists(old_persist_file): os.unlink(old_persist_file) return tid
def create_iscsi_target(self, name, tid, lun, path, chap_auth=None, **kwargs): # Note(jdg) tid and lun aren't used by TgtAdm but remain for # compatibility fileutils.ensure_tree(CONF.volumes_dir) vol_id = name.split(':')[1] if chap_auth is None: volume_conf = """ <target %s> backing-store %s </target> """ % (name, path) else: volume_conf = """ <target %s> backing-store %s %s </target> """ % (name, path, chap_auth) LOG.info(_('Creating iscsi_target for: %s') % vol_id) volumes_dir = CONF.volumes_dir volume_path = os.path.join(volumes_dir, vol_id) f = open(volume_path, 'w+') f.write(volume_conf) f.close() old_persist_file = None old_name = kwargs.get('old_name', None) if old_name is not None: old_persist_file = os.path.join(volumes_dir, old_name) try: (out, err) = self._execute('tgt-admin', '--update', name, run_as_root=True) except putils.ProcessExecutionError as e: LOG.error( _("Failed to create iscsi target for volume " "id:%(vol_id)s: %(e)s") % { 'vol_id': vol_id, 'e': str(e) }) #Don't forget to remove the persistent file we created os.unlink(volume_path) raise exception.ISCSITargetCreateFailed(volume_id=vol_id) iqn = '%s%s' % (CONF.iscsi_target_prefix, vol_id) tid = self._get_target(iqn) if tid is None: LOG.error( _("Failed to create iscsi target for volume " "id:%(vol_id)s. Please ensure your tgtd config file " "contains 'include %(volumes_dir)s/*'") % { 'vol_id': vol_id, 'volumes_dir': volumes_dir, }) raise exception.NotFound() if old_persist_file is not None and os.path.exists(old_persist_file): os.unlink(old_persist_file) return tid