Bug 1428862 - spacecmd returns incorrect return codes in some instances
Summary: spacecmd returns incorrect return codes in some instances
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Satellite 5
Classification: Red Hat
Component: Client
Version: 580
Hardware: noarch
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Tomáš Kašpárek
QA Contact: Pavel Studeník
URL:
Whiteboard:
Depends On: 1202582 1202684
Blocks: sat580-low
TreeView+ depends on / blocked
 
Reported: 2017-03-03 14:23 UTC by Tomáš Kašpárek
Modified: 2017-06-21 12:17 UTC (History)
3 users (show)

Fixed In Version: spacecmd-2.5.0-10-sat
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1202684
Environment:
Last Closed: 2017-06-21 12:17:27 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Tomáš Kašpárek 2017-03-03 14:23:15 UTC
+++ This bug was initially created as a clone of Bug #1202684 +++

+++ This bug was initially created as a clone of Bug #1202582 +++

Description of problem:
When spacecmd is used in non-interactive mode, it returns '0' error code in some instances when it should be returning 1 (eg. if the Spacewalk server cannot be contacted).


Version-Release number of selected component (if applicable):

Tested in both the following versions (EPEL and latest nightly rpm build):
spacecmd-1.9.4-1.el6.noarch.rpm
spacecmd-2.3.18-1.el6.noarch.rpm


How reproducible:
100%

Steps to Reproduce:
1. Connect to a invalid host using spacecmd in non-interactive mode (ie. passing a command in quotes)
#spacecmd -s fakehostname.local -u spacewalk -p password "runsomecommand"
ERROR: Failed to connect to https://fakehostname.local/rpc/api

2. Display exit code
#echo $?
0

Actual results:
Exit code '0' is returned.

Expected results:
Exit code '1' should be returned

Additional info:

When running in interactive mode the correct exit code is produced:

#spacecmd -s fakehostname.local -u spacewalk -p password
Welcome to spacecmd, a command-line interface to Spacewalk.

Type: 'help' for a list of commands
      'help <cmd>' for command-specific help
      'quit' to quit

ERROR: Failed to connect to https://fakehostname.local/rpc/api

#echo $?
1

--- Additional comment from PixelDrift.NET Support on 2015-03-16 20:06:03 EDT ---

It appears the error code _is_ returned correctly in latest release (spacecmd-2.3.18-1.el6.noarch.rpm) apologies.

#spacecmd -s fakehostname.local -u spacewalk -p password "runsomecommand"
ERROR: [Errno -2] Name or service not known

#echo $?
1


But there appears to be some regression in the error handling (error doesn't appear to be caught) when using interactive mode (compare to output in original bug).


#spacecmd -s fakehostname.local -u spacewalk -p password
Welcome to spacecmd, a command-line interface to Spacewalk.

Type: 'help' for a list of commands
      'help <cmd>' for command-specific help
      'quit' to quit

Traceback (most recent call last):
  File "/usr/bin/spacecmd", line 165, in <module>
    if not shell.do_login(''):
  File "/usr/lib/python2.6/site-packages/spacecmd/misc.py", line 298, in do_login
    self.api_version = self.client.api.getVersion()
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1235, in request
    self.send_content(h, request_body)
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1349, in send_content
    connection.endheaders()
  File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/usr/lib64/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/usr/lib64/python2.6/httplib.py", line 1112, in connect
    sock = socket.create_connection((self.host, self.port), self.timeout)
  File "/usr/lib64/python2.6/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known

--- Additional comment from Tomáš Kašpárek on 2017-03-03 09:17:52 EST ---

spacewalk.git(master): 7cf35f12fc770328889b99f8119d838ae5def60b

Comment 3 Pavel Studeník 2017-03-23 12:00:00 UTC
>> spacecmd -s fakehostname.local -u spacewalk -p password "runsomecommand"
ERROR: Failed to connect to https://fakehostname.local/rpc/api
>> echo $?
1

>> spacecmd -s localhost -u spacewalk -p password "runsomecommand"
INFO: Spacewalk Username: spacewalk
ERROR: Invalid credentials
>> echo $?
1

>> spacecmd -s localhost -u admin -p correct_pass "runsomecommand"
INFO: Spacewalk Username: admin
INFO: Connected to https://localhost/rpc/api as admin
*** Unknown syntax: runsomecommand
>> echo $?
0

I suppose that correct behaviour is that spacecmd returns non-zero value when fails.

Comment 4 Tomáš Kašpárek 2017-03-24 13:43:57 UTC
spacewalk.git(master): e21ab42fd175da7b32949acbbf360c335f3f3745

Comment 7 Pavel Studeník 2017-04-07 10:08:21 UTC
Verified with spacecmd-2.5.0-11.el6sat.noarch


Note You need to log in before you can comment on or make changes to this bug.