Bug 1432303

Summary: targetcli ls command will fail with 'TERM' not defined in os.enviorn
Product: Red Hat Enterprise Linux 7 Reporter: Wayne Sun <gsun>
Component: python-configshellAssignee: Andy Grover <agrover>
Status: CLOSED ERRATA QA Contact: Martin Hoyer <mhoyer>
Severity: urgent Docs Contact:
Priority: medium    
Version: 7.4CC: agrover, cfeist, dzheng, hliu, jess.calciano, mhoyer, mnovacek, oalbrigt, tgill, xuzhang
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 20:54:35 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:

Description Wayne Sun 2017-03-15 03:32:19 UTC
Description of problem:
targetcli ls command will fail with 'TERM' not defined in os.enviorn

2017-03-14 02:33:52,112 process          L0333 INFO | Running 'targetcli ls /iscsi 1'
2017-03-14 02:33:52,162 process          L0420 DEBUG| [stderr] Traceback (most recent call last):
2017-03-14 02:33:52,162 process          L0420 DEBUG| [stderr]   File "/usr/bin/targetcli", line 24, in <module>
2017-03-14 02:33:52,163 process          L0420 DEBUG| [stderr]     from targetcli import UIRoot
2017-03-14 02:33:52,163 process          L0420 DEBUG| [stderr]   File "/usr/lib/python2.7/site-packages/targetcli/__init__.py", line 18, in <module>
2017-03-14 02:33:52,163 process          L0420 DEBUG| [stderr]     from .ui_root import UIRoot
2017-03-14 02:33:52,163 process          L0420 DEBUG| [stderr]   File "/usr/lib/python2.7/site-packages/targetcli/ui_root.py", line 26, in <module>
2017-03-14 02:33:52,163 process          L0420 DEBUG| [stderr]     from configshell_fb import ExecutionError
2017-03-14 02:33:52,163 process          L0420 DEBUG| [stderr]   File "/usr/lib/python2.7/site-packages/configshell_fb/__init__.py", line 27, in <module>
2017-03-14 02:33:52,163 process          L0420 DEBUG| [stderr]     from .shell import ConfigShell
2017-03-14 02:33:52,164 process          L0420 DEBUG| [stderr]   File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 53, in <module>
2017-03-14 02:33:52,164 process          L0420 DEBUG| [stderr]     oldTerm = os.environ['TERM']
2017-03-14 02:33:52,164 process          L0420 DEBUG| [stderr]   File "/usr/lib64/python2.7/UserDict.py", line 23, in __getitem__
2017-03-14 02:33:52,164 process          L0420 DEBUG| [stderr]     raise KeyError(key)
2017-03-14 02:33:52,164 process          L0420 DEBUG| [stderr] KeyError: 'TERM'

Version-Release number of selected component (if applicable):
# rpm -q targetcli python-configshell kernel
targetcli-2.1.fb46-1.el7.noarch
python-configshell-1.1.fb23-1.el7.noarch
kernel-3.10.0-603.el7.ppc64le


How reproducible:
always in jenkins shell job or when 'TERM' is not in env

Steps to Reproduce:
1.
# python
Python 2.7.5 (default, Mar 13 2017, 12:06:50) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, subprocess
>>> print (os.environ['TERM'])
xterm-256color
>>> del os.environ['TERM']
>>> print (os.environ['TERM'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'TERM'
>>> subprocess.Popen("targetcli ls /iscsi 1", shell=True, stdout=subprocess.PIPE).stdout.read()
Traceback (most recent call last):
  File "/usr/bin/targetcli", line 24, in <module>
    from targetcli import UIRoot
  File "/usr/lib/python2.7/site-packages/targetcli/__init__.py", line 18, in <module>
    from .ui_root import UIRoot
  File "/usr/lib/python2.7/site-packages/targetcli/ui_root.py", line 26, in <module>
    from configshell_fb import ExecutionError
  File "/usr/lib/python2.7/site-packages/configshell_fb/__init__.py", line 27, in <module>
    from .shell import ConfigShell
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 53, in <module>
    oldTerm = os.environ['TERM']
  File "/usr/lib64/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'TERM'
''
>>> 

2.
3.

Actual results:
Fail

Expected results:
Success

Additional info:
This is bring in by commit:
https://github.com/open-iscsi/configshell-fb/commit/82f79eb2f967ecd820d531488d0b64d6015b1aaf

which did not check whether TERM is in env

Comment 3 Jess Calciano 2017-05-12 20:20:06 UTC
I've also recently run into this - any updates on a fix or an official workaround?

It's definitely a problem in Jenkins, like the original description states. To manually reproduce the problem:
1. Run targetcli from a remote host:
   # ssh user@host 'targetcli ls'

2. The Python KeyError and traceback above appears.

Comment 4 michal novacek 2017-05-18 08:37:48 UTC
This breaks HA resource-agents (iSCSITarget and iSCSILogicalUnit) which are using targetcli.

This needs to be fixed in 7.4 timeframe.

Comment 8 Martin Hoyer 2017-06-09 13:53:30 UTC
Reproducible with python-configshell-1.1.fb23-1.el7
Working well with python-configshell-1.1.fb23-2.el7
Regression tests did not found any new issue.

Comment 9 errata-xmlrpc 2017-08-01 20:54:35 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:2031