Bug 689608

Summary: Return error code when auto subscribing doesn't find any subscriptions
Product: Red Hat Enterprise Linux 6 Reporter: Dennis Gregorovic <dgregor>
Component: subscription-managerAssignee: Alex Wood <awood>
Status: CLOSED ERRATA QA Contact: Entitlement Bugs <entitlement-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.1CC: awood, jsefler
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 12:56:17 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 738066, 756082    

Description Dennis Gregorovic 2011-03-21 21:30:54 UTC
"subscription-manager subscribe --auto" can subscribe to zero or more subscriptions.  It should return an error code when the number is zero.

[root@localhost ~]# rpm -qf /usr/sbin/subscription-manager 
subscription-manager-0.95.4-1.el6.x86_64
[root@localhost ~]# subscription-manager list
+-------------------------------------------+
    Installed Product Status
+-------------------------------------------+

ProductName:        	Red Hat Enterprise Linux 6 for Scientific Computing
Status:             	Not Subscribed           
Expires:            	                         
Subscription:       	                         
ContractNumber:     	                         
AccountNumber:      	                         

[root@localhost ~]# subscription-manager subscribe --auto
[root@localhost ~]# echo $?
0
[root@localhost ~]# subscription-manager list
+-------------------------------------------+
    Installed Product Status
+-------------------------------------------+

ProductName:        	Red Hat Enterprise Linux 6 for Scientific Computing
Status:             	Not Subscribed           
Expires:            	                         
Subscription:       	                         
ContractNumber:     	                         
AccountNumber:

Comment 3 Jeff Weiss 2012-01-05 11:58:34 UTC
It's worse than this, subscribe seems to always return 0 no matter what.


[root@katello-client2 ~]# subscription-manager subscribe --pool=BLAHINVALIDPOOL
Subscription pool BLAHINVALIDPOOL does not exist.
[root@katello-client2 ~]# echo $?
0
[root@katello-client2 ~]#

Comment 4 John Sefler 2012-01-05 16:41:53 UTC
Regarding the request in comment 0, I suspect the lack of stdout/stderr feedback was the true cause for opening this bug in the first place.  Feedback has since been added as demonstrated here...

[root@jsefler-stage-6server ~]# subscription-manager subscribe --auto
Installed Product Current Status:

ProductName:         	Red Hat Enterprise Linux 6 Server
Status:               	Not Subscribed           

[root@jsefler-stage-6server ~]# echo $?
0

If this behavior change is sufficient to the bug reporter, I suggest we resolve this bug as a duplicate of bug 717664.



Alternatively the following new exitCode behavior make sense to me...
caseA: return exitCode 0 when at least one entitlement is granted from subscribe
caseB: return exitCode 1 when zero entitlements are granted from subscribe
caseC: return exitCode 255 when code breaks (e.g. traceback) during subscribe

With ^these changes, both comment 0 and comment 3 are addressed by caseB.

Comment 5 Alex Wood 2012-01-27 19:49:07 UTC
Committed 438fd48b01229f521184686ef7f791e7dbd94c65 to subscription-manager

subscription-manager 0.99.4+

The behavior now is for subscription-manager subscribe to return a 0 if any subscription succeeded.

As well, the situation described in comment #3 should return a 0 if any of the subscriptions succeed.

Comment 7 John Sefler 2012-02-20 22:07:07 UTC
Verifying Version...
[root@jsefler-r63-server ~]# rpm -q subscription-manager
subscription-manager-0.99.7-1.git.5.d9e3ff2.el6.x86_64

We will verify that the fix in comment 5 supports the exit codes requested for the three cases in comment 4.



Case A:
[root@jsefler-r63-server ~]# subscription-manager register --username testuser1 --password password --org admin --auto
The system has been registered with id: 1e888192-b1cd-47d4-962a-fc71a132e2e5 
Installed Product Current Status:
ProductName:          	Awesome OS for S390 Bits 
Status:               	Not Subscribed           

ProductName:          	Stackable with Awesome OS for x86_64 Bits
Status:               	Subscribed               

ProductName:          	Awesome OS Developer Basic
Status:               	Not Subscribed           

ProductName:          	Awesome OS for x86_64/i686/ia64/ppc/ppc64/s390x/s390 Bits
Status:               	Subscribed               

ProductName:          	Awesome OS for z80/x86_64 Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for z80/ALL Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for x86_64/ALL Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for x86_64/ALL Bits for ZERO sockets
Status:               	Not Subscribed           

ProductName:          	Awesome OS Workstation Bits
Status:               	Subscribed               

ProductName:          	Multiplier Product Bits  
Status:               	Not Subscribed           

ProductName:          	Awesome OS Developer Bits
Status:               	Not Subscribed           

ProductName:          	Management Bits          
Status:               	Subscribed               

ProductName:          	Large File Support Bits  
Status:               	Subscribed               

ProductName:          	Awesome OS Modifier Bits 
Status:               	Subscribed               

ProductName:          	Clustering Bits          
Status:               	Subscribed               

ProductName:          	Shared Storage Bits      
Status:               	Subscribed               

ProductName:          	Awesome OS Server Bits   
Status:               	Subscribed               

ProductName:          	Awesome OS Premium Architecture Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for ia64 Bits 
Status:               	Not Subscribed           

ProductName:          	Awesome OS for i686/x86_64 Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for z80 Bits  
Status:               	Not Subscribed           

ProductName:          	Awesome OS for i686 Bits 
Status:               	Not Subscribed           

ProductName:          	Awesome OS for x86_64 Bits
Status:               	Subscribed               

ProductName:          	Awesome OS for ppc64 Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for S390X Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for i386 Bits 
Status:               	Not Subscribed           

ProductName:          	Awesome OS for x86 Bits  
Status:               	Not Subscribed           

ProductName:          	Awesome OS for x86/x64_64 Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for Intel x86_64/i686/ia64 Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS for x86_64/s390x Bits
Status:               	Not Subscribed           

ProductName:          	Awesome OS Scalable Filesystem Bits
Status:               	Not Subscribed           

ProductName:          	Load Balancing Bits      
Status:               	Subscribed               

[root@jsefler-r63-server ~]# echo $?
0

^ VERIFIED that register with autosubscribe returns 0 when at least one product successfully binds


[root@jsefler-r63-server ~]# subscription-manager unsubscribe --all
[root@jsefler-r63-server ~]# subscription-manager list --avail | grep PoolId
PoolId:               	8a90f814359ca14501359ca242770264
PoolId:               	8a90f814359ca14501359ca242c20270
PoolId:               	8a90f814359ca14501359ca243330288
PoolId:               	8a90f814359ca14501359ca243770294
PoolId:               	8a90f814359ca14501359ca2444902b7
PoolId:               	8a90f814359ca14501359ca2455202fa
PoolId:               	8a90f814359ca14501359ca24595030c
PoolId:               	8a90f814359ca14501359ca241c40234
PoolId:               	8a90f814359ca14501359ca243f602ac
PoolId:               	8a90f814359ca14501359ca247bf03a7
PoolId:               	8a90f814359ca14501359ca2480f03c7
PoolId:               	8a90f814359ca14501359ca2499d043b
PoolId:               	8a90f814359ca14501359ca249e5044d
PoolId:               	8a90f814359ca14501359ca24a060456
PoolId:               	8a90f814359ca14501359ca24a4b0468
PoolId:               	8a90f814359ca14501359ca24a6b0470
PoolId:               	8a90f814359ca14501359ca24b0404a1
PoolId:               	8a90f814359ca14501359ca24b1d04aa
PoolId:               	8a90f814359ca14501359ca241690228
PoolId:               	8a90f814359ca14501359ca249790432
PoolId:               	8a90f814359ca14501359ca247f103bd
PoolId:               	8a90f814359ca14501359ca242110244
PoolId:               	8a90f814359ca14501359ca247ac039c
PoolId:               	8a90f814359ca14501359ca240aa0222
[root@jsefler-r63-server ~]# subscription-manager subscribe --pool 8a90f814359ca14501359ca24b0404a1
Successfully consumed a subscription from the pool with id 8a90f814359ca14501359ca24b0404a1.
[root@jsefler-r63-server ~]# echo $?
0
[root@jsefler-r63-server ~]# subscription-manager subscribe --pool 8a90f814359ca14501359ca249790432 --pool FOOBAR
Successfully consumed a subscription from the pool with id 8a90f814359ca14501359ca249790432.
Subscription pool FOOBAR does not exist.
[root@jsefler-r63-server ~]# echo $?
0

^ VERIFIED that subscribe --pool returns 0 when at least one product successfully binds



Case B:
[root@jsefler-r63-server ~]# subscription-manager unregister
System has been un-registered.
[root@jsefler-r63-server ~]# subscription-manager config --rhsm.productcertdir=/tmp/FOOBAR
[root@jsefler-r63-server ~]# subscription-manager register --username testuser1 --password password --org admin --auto
The system has been registered with id: 45feaf4c-8803-4542-bb1f-f299ca82c919 
Installed Product Current Status:
[root@jsefler-r63-server ~]# echo $?
1

^ VERIFIED that register with autosubscribe returns 1 when no products successfully bind


[root@jsefler-r63-server ~]# subscription-manager subscribe --pool FOOBAR
Subscription pool FOOBAR does not exist.
[root@jsefler-r63-server ~]# echo $?
1

^ VERIFIED that subscribe --pool returns 1 when no product successfully binds


Case 3:
[root@jsefler-r63-server ~]# subscription-manager config --server.port=000
[root@jsefler-r63-server ~]# subscription-manager subscribe --pool FOOBAR
Network error, unable to connect to server.
Please see /var/log/rhsm/rhsm.log for more information.
[root@jsefler-r63-server ~]# echo $?
255
^ VERIFIED that subscribe --pool returns 255 when an error/traceback occurs


moving to VERIFIED

Comment 9 errata-xmlrpc 2012-06-20 12:56:17 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

Comment 10 John Sefler 2015-03-17 15:13:37 UTC
(In reply to John Sefler from comment #7)
> [root@jsefler-r63-server ~]# subscription-manager register --username
> testuser1 --password password --org admin --auto
> The system has been registered with id: 45feaf4c-8803-4542-bb1f-f299ca82c919 
> Installed Product Current Status:
> [root@jsefler-r63-server ~]# echo $?
> 1
> 
> ^ VERIFIED that register with autosubscribe returns 1 when no products
> successfully bind
> 

Note that the return code for this use case was changed from 1 to 0 in https://bugzilla.redhat.com/show_bug.cgi?id=962545#c7