+++ 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
>> 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.
spacewalk.git(master): e21ab42fd175da7b32949acbbf360c335f3f3745
Verified with spacecmd-2.5.0-11.el6sat.noarch