Bug 1202684

Summary: spacecmd returns incorrect return codes in some instances
Product: [Community] Spacewalk Reporter: Miroslav Suchý <msuchy>
Component: ClientsAssignee: Tomáš Kašpárek <tkasparek>
Status: CLOSED CURRENTRELEASE QA Contact: Red Hat Satellite QA List <satqe-list>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 2.2CC: devnull, eherget, extras-qa, msuchy
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: noarch   
OS: Linux   
Whiteboard:
Fixed In Version: spacecmd-2.7.6-1 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1202582
: 1428862 (view as bug list) Environment:
Last Closed: 2017-09-27 19:00:14 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:
Bug Depends On: 1202582    
Bug Blocks: 1428862, 1484117    

Description Miroslav Suchý 2015-03-17 08:23:01 UTC
+++ 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

Comment 1 Tomáš Kašpárek 2017-03-03 14:17:52 UTC
spacewalk.git(master): 7cf35f12fc770328889b99f8119d838ae5def60b

Comment 2 Eric Herget 2017-09-27 19:00:14 UTC
Spacewalk 2.7 has been released.

https://github.com/spacewalkproject/spacewalk/wiki/ReleaseNotes27