Bug 734533 - exit code for cli subscription-manager import --certificate=FOO should be 1
Summary: exit code for cli subscription-manager import --certificate=FOO should be 1
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: subscription-manager
Version: 6.2
Hardware: Unspecified
OS: Unspecified
unspecified
low
Target Milestone: beta
: 6.3
Assignee: Bryan Kearney
QA Contact: Entitlement Bugs
URL:
Whiteboard:
Depends On:
Blocks: 738066 756082
TreeView+ depends on / blocked
 
Reported: 2011-08-30 17:28 UTC by John Sefler
Modified: 2012-06-20 12:56 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-06-20 12:56:36 UTC


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2012:0804 normal SHIPPED_LIVE subscription-manager bug fix and enhancement update 2012-06-19 19:51:31 UTC

Description John Sefler 2011-08-30 17:28:06 UTC
Description of problem:
For subscription-manager cli consistency, a failed command should return an exitCode of 255 and the error message in stderr


Steps to Reproduce / Actual results:
# subscription-manager import --certificate=FOO 1>/dev/null
# echo $?
0

^^^ THAT EXIT CODE SHOULD BE 255 AND THE ERROR MESSAGE SHOULD BE RETURNED TO STDERR (THE ERROR MESSAGE IS CURRENTLY GOING TO STDOUT)

Expected results:
# subscription-manager import --certificate=FOO 1>/dev/null
FOO is not a valid certificate file. Please use a valid certificate.
# echo $?
255


Version-Release number of selected component (if applicable):
[root@jsefler-onprem-62server ~]# rpm -q subscription-manager
subscription-manager-0.96.7-1.git.14.c203b16.el6.x86_64

Comment 1 Bryan Kearney 2011-09-02 18:46:26 UTC
What commands get you a 255?

Comment 3 John Sefler 2012-01-05 19:06:34 UTC
(In reply to comment #1)
> What commands get you a 255?

Well then...

* an exit code of 1 would probably be more appropriate as suggested by http://www.daniweb.com/software-development/python/threads/31226/163923#post163923

* and the feedback message, "FOO is not a valid certificate file. Please use a valid certificate.", should probably be written to stdout

Comment 4 Alex Wood 2012-01-20 16:35:05 UTC
Committed ddad607b1d46795122c57467f6653918e6b16116

In subscription-manager 0.99.4+

Comment 5 Alex Wood 2012-01-20 17:42:55 UTC
The code should now process all arguments but return a 1 if any of the arguments failed validation.

E.g.


# subscription-manager import --certificate=GOOD --certificate=BAD

Successfully imported certificate GOOD
BAD is not a valid certificate file. Please use a valid certificate.

# echo $?
1

Comment 6 Alex Wood 2012-02-02 18:33:29 UTC
Correction: As of 62c62cc98d2708225444713b61b6067f8555753b (0.99.6+), the code will return a 1 only if *all* arguments fail.  This change was made to make the return code behavior consistent with how subscription-manager subscribe works.

Comment 8 John Sefler 2012-02-13 19:46:46 UTC
Verifying Version...

[root@jsefler-r63-server ~]# rpm -q subscription-manager
subscription-manager-0.99.7-1.git.0.8137c52.el6.x86_64



[root@jsefler-r63-server ~]# subscription-manager import --certificate=FOO 1>/tmp/stdout 2>/tmp/stderr
[root@jsefler-r63-server ~]# echo $?
1
[root@jsefler-r63-server ~]# cat /tmp/stdout
FOO is not a valid certificate file. Please use a valid certificate.
[root@jsefler-r63-server ~]# cat /tmp/stderr
[root@jsefler-r63-server ~]# 

^^^^^^^^
VERIFIED - importing a bad cert throws an exit code of 1 with stdout message 



[root@jsefler-r63-server ~]# subscription-manager import --certificate=/tmp/sm-importEntitlementsDir/6871632671492179691-key.pem --certificate=/tmp/sm-importCertificatesDir/cert.pem --certificate=/tmp/sm-importCertificatesDir/8003202248817161227.pem --certificate=/tmp/nonExistentFile.pem  1>/tmp/stdout 2>/tmp/stderr
[root@jsefler-r63-server ~]# echo $?
0
[root@jsefler-r63-server ~]# cat /tmp/stdout
6871632671492179691-key.pem is not a valid certificate file. Please use a valid certificate.
cert.pem is not a valid certificate file. Please use a valid certificate.
Successfully imported certificate 8003202248817161227.pem
nonExistentFile.pem is not a valid certificate file. Please use a valid certificate.
[root@jsefler-r63-server ~]# cat /tmp/stderr
[root@jsefler-r63-server ~]# 

^^^^^^^^
VERIFIED - importing a mix of good/bad certs throws an exit code of 0 (as designed in comment 6) with stdout messages

Comment 10 errata-xmlrpc 2012-06-20 12:56:36 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.

http://rhn.redhat.com/errata/RHBA-2012-0804.html


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