Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 957041

Summary: targetcli does not restore configuration after reboot.
Product: Red Hat Enterprise Linux 7 Reporter: Bruno Goncalves <bgoncalv>
Component: targetcliAssignee: Andy Grover <agrover>
Status: CLOSED NOTABUG QA Contact: Bruno Goncalves <bgoncalv>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: max_allan, murahman, prabhat.rishi, socketpair
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-04-26 15:28:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Bruno Goncalves 2013-04-26 08:46:03 UTC
Description of problem:
after server is restarted the targetcli setting is lost. "targetcli ls" shows empty configuration.

It is necessary to run "tagetcli restoreconfig <backup file>" to have the configuration back.

I think targetcli should have its current configuration stored in an specific location and restore it when targetcli service starts.

Version-Release number of selected component (if applicable):
targetcli-2.1.fb23-1.el7.noarch

uname -r
3.9.0-0.rc8.54.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Add some configuration to targetcli
2.reboot server
3.all configuration is lost.
  

Expected results:
targetcli service should restore configuration automatically.

Comment 1 Andy Grover 2013-04-26 14:52:17 UTC
is there configuration info in /etc/target/saveconfig.json?

Is targetcli service set to run on boot?

Comment 2 Bruno Goncalves 2013-04-26 15:28:10 UTC
Correct, configuring the process to start on boot solves the problem.

chkconfig targetcli on

systemctl list-unit-files | grep targetcli
targetcli.service                           enabled

Comment 3 Prabhat 2016-04-01 14:18:18 UTC
The solution to restore from back is as follows:

Select the backup file and then execute the following command

Backup file selected: saveconfig-20160401-04\:52\:04.json

[root@server0 ~]# /usr/bin/targetctl restore saveconfig-20160401-04\:52\:04.json

[root@server0 ~]# targetcli
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_block ..................................................... [/dev/iscsi_vg/iscsi_block (1.0GiB) write-thru activated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2014-08.com.example.network0:system1 .......................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2014-08.com.example.network0:system3 ............................................................. [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ........................................................................... [lun0 block/iscsi_block (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 .................................................................. [block/iscsi_block (/dev/iscsi_vg/iscsi_block)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 172.25.0.11:3260 ................................................................................................. [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server0 ~]#


This restoration worked even after rebooting the server

[root@server0 ~]# reboot
[root@server0 ~]# targetcli
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_block ..................................................... [/dev/iscsi_vg/iscsi_block (1.0GiB) write-thru activated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2014-08.com.example.network0:system1 .......................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2014-08.com.example.network0:system3 ............................................................. [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ........................................................................... [lun0 block/iscsi_block (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 .................................................................. [block/iscsi_block (/dev/iscsi_vg/iscsi_block)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 172.25.0.11:3260 ................................................................................................. [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/>

Comment 4 Prabhat 2016-04-01 14:29:43 UTC
(In reply to Bruno Goncalves from comment #2)
> Correct, configuring the process to start on boot solves the problem.
> 
> chkconfig targetcli on
> 
> systemctl list-unit-files | grep targetcli
> targetcli.service                           enabled


I can't see any such service:

[root@server0 ~]# systemctl enable targetcli
Failed to issue method call: No such file or directory
[root@server0 ~]#
[root@server0 ~]# systemctl list-unit-files | grep targetcli
[root@server0 ~]#

However, iscsi and target as service is available:

[root@server0 ~]# systemctl list-unit-files | grep iscsi
iscsi.service                               enabled
iscsid.service                              disabled
iscsiuio.service                            disabled
iscsid.socket                               enabled
iscsiuio.socket                             enabled
[root@server0 ~]#

[root@server0 ~]# systemctl list-unit-files | grep target
target.service                              enabled

Comment 5 Коренберг Марк 2017-03-15 12:05:47 UTC
Exactly the same problem

Comment 6 Bruno Goncalves 2017-03-15 12:09:51 UTC
targetcli service has been renamed to target.

# chkconfig target on
Note: Forwarding request to 'systemctl enable target.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.

Comment 7 Max Allan 2019-04-16 16:09:34 UTC
What excuse do you have for this not being a bug?? Wiping out good config because the service is not enabled is surely the very definition of a bug?

the man page states :
Other Commands
saveconfig
Save the current configuration settings to a file, from which settings will be restored if the system is rebooted. By default, this will save the configuration to /etc/target/saveconfig.json.

Nothing about "except if the service is disabled, in which case the disabled service will wipe your config"

Comment 8 Mushfiqur Rahman 2020-04-08 00:11:33 UTC
My problem WAS: 
--------------------------------------------------------------
/> saveconfig 
Traceback (most recent call last):
  File "/usr/bin/targetcli", line 122, in <module>
    main()
  File "/usr/bin/targetcli", line 112, in main
    shell.run_interactive()
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 905, in run_interactive
    self._cli_loop()
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 734, in _cli_loop
    self.run_cmdline(cmdline)
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 848, in run_cmdline
    self._execute_command(path, command, pparams, kparams)
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 823, in _execute_command
    result = target.execute_command(command, pparams, kparams)
  File "/usr/lib/python2.7/site-packages/configshell_fb/node.py", line 1406, in execute_command
    return method(*pparams, **kparams)
  File "/usr/lib/python2.7/site-packages/targetcli/ui_root.py", line 138, in ui_command_saveconfig
    self.rtsroot.save_to_file(savefile)
  File "/usr/lib/python2.7/site-packages/rtslib_fb/root.py", line 388, in save_to_file
    saveconf = self.dump()
  File "/usr/lib/python2.7/site-packages/rtslib_fb/root.py", line 272, in dump
    d['storage_objects'] = [so.dump() for so in self.storage_objects]
  File "/usr/lib/python2.7/site-packages/rtslib_fb/tcm.py", line 797, in dump
    d = super(BlockStorageObject, self).dump()
  File "/usr/lib/python2.7/site-packages/rtslib_fb/tcm.py", line 317, in dump
    d['alua_tpgs'] = [tpg.dump() for tpg in self.alua_tpgs]
  File "/usr/lib/python2.7/site-packages/rtslib_fb/alua.py", line 309, in dump
    d[param] = getattr(self, param, None)
  File "/usr/lib/python2.7/site-packages/rtslib_fb/alua.py", line 126, in _get_alua_access_type
    return alua_types.index(alua_type)
ValueError: 'Implict and Explict' is not in list
-----------------------------------------
Issue Fixed by running: 

[root@iscsi-server ~]# systemctl start target
[root@iscsi-server ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@iscsi-server ~]# targetcli version
targetcli version 2.1.fb49

So just start and enable the service target