def _enable_iscsiid(self): HostSession.host_cmd_output(self, 'systemctl enable iscsid iscsi') HostSession.host_cmd_output(self, 'systemctl start iscsid iscsi') output = HostSession.host_cmd_output( self, 'systemctl status iscsid iscsi -l') if not re.findall(r'Active: active', output): ShellSession.test_error(self, 'Failed to start iscsid server.')
def _enable_iscsi_target_server(self): cmd = 'iptables -F' ShellSession.cmd_output(self, cmd) cmd = 'systemctl start target' ShellSession.cmd_output(self, cmd) cmd = 'systemctl enable target' ShellSession.cmd_output(self, cmd) output = ShellSession.cmd_output(self, 'systemctl status target -l') if not re.findall(r'Active: active', output): ShellSession.test_error(self, 'Failed to start target server.')
def create_lun(self, iqn, backend_name, fileio_mode=False, block_mode=False): if not fileio_mode and not block_mode: ShellSession.test_error( self, 'Please specify fileio ' '| block mode for lun.') elif fileio_mode: cmd = 'echo \"iscsi/%s/tpg1/luns/ create /backstores/fileio/%s\" ' \ '| targetcli' % (iqn, backend_name) elif block_mode: cmd = 'echo \"iscsi/%s/tpg1/luns/ create /backstores/block/%s\" ' \ '| targetcli' % (iqn, backend_name) ShellSession.cmd_output(self, cmd)
def create_backstore(self, file_or_dev, backend_name, size, write_back='false'): if re.findall(r'/', file_or_dev): path = '/' for p in file_or_dev.split('/')[0:-1]: path = os.path.join(path, p) self._create_fileio_file(path) else: ShellSession.test_error(self, 'Please specify a path for backstore.') cmd = "echo \"backstores/fileio/ create file_or_dev=%s name=%s size=%s " \ "write_back=%s\" | targetcli" \ % (file_or_dev, backend_name, size, write_back) output = ShellSession.cmd_output(self, cmd) if 'Storage object fileio/%s exists' % backend_name in output: cmd = "echo \"backstores/fileio/ delete %s\" | targetcli" % backend_name ShellSession.cmd_output(self, cmd) cmd = "echo \"backstores/fileio/ create file_or_dev=%s name=%s size=%s " \ "write_back=%s\" | targetcli" % ( file_or_dev, backend_name, size, write_back) ShellSession.cmd_output(self, cmd)
def create_iscsi_target_portal(self, iqn): self.delete_iscsi_target_portal(iqn) if 'This Target already exists in configFS' \ in ShellSession.cmd_output( self, 'echo \"iscsi/ create %s\" | targetcli' % iqn): ShellSession.test_error(self, 'Failed to create target %s' % iqn)
def _install_iscsi_target_tool(self): cmd = 'yum install -y targetcli' status, output = ShellSession.cmd_status_output(self, cmd) if status: ShellSession.test_error(self, 'Failed to install targetcli')