Bug 1119688

Summary: [RFE] subscription-manager better usability for scripts
Product: Red Hat Enterprise Linux 7 Reporter: Daniel Horák <dahorak>
Component: subscription-managerAssignee: Chris "Ceiu" Rog <crog>
Status: CLOSED ERRATA QA Contact: John Sefler <jsefler>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: crog, mbukatov, sgraf, stbenjam, wpoteat
Target Milestone: rcKeywords: FutureFeature
Target Release: 7.1   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-03-05 13:17:37 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:    
Bug Blocks: 1005618    

Description Daniel Horák 2014-07-15 09:48:01 UTC
Description of problem:
  There are few missing features in subscription-manager which will increase the usability in scripts.
  * alternative for rhn_check - if you want to check if machine is registered to cdn, you have to grep output from "subscription-manager status" (and similarly for other states)
  * same as previous point - is subscribed to pool
  * output from subscription-manager repos --list is not easily processable, because it is on multiple lines (I know that there is empty line as separator...)
  All previous features should return proper exit code.

Version-Release number of selected component (if applicable):
# subscription-manager version
  server type: Red Hat Subscription Management
  subscription management server: 0.9.20.1-1
  subscription-manager: 1.9.11-1.el6
  python-rhsm: 1.9.7-1.el6_5

Additional info:
 See also Bug 1119648.

Comment 2 Bryan Kearney 2014-08-13 18:55:08 UTC
Acking 7.1

Comment 3 Chris "Ceiu" Rog 2014-11-03 18:27:57 UTC
commit 066c0651fd3117fbd0d9cfb5bf03eb788d00420f
Merge: 0e75982 df95529
Author: Adrian Likins <alikins>
Date:   Fri Oct 31 10:29:53 2014 -0400

    Merge pull request #1044 from candlepin/crog/1119688
    
    1119688: Improved error code usage in subman.


- Standardized most print & sys.exit calls with the system_exit
  abstraction.

- Standardized error code usage, using os.EX_* constants where appropriate:
  - EX_USAGE for improper usage of command options
  - EX_DATAERR for proper command usage with invalid provided data
  - EX_UNAVAILABLE for command options which are unsupported by the
    current server
  - EX_SOFTWARE for internal fatal errors
  - Others used somewhat liberally where seemingly appropriate

- Added error output to the status command:
  - 0 when the system is registered and no errors occur during the check
  - 1 when the system is not registered

Comment 4 Chris "Ceiu" Rog 2014-11-03 19:33:08 UTC
(In reply to Daniel Horák from comment #0)
> Description of problem:
>   There are few missing features in subscription-manager which will increase
> the usability in scripts.
>   * alternative for rhn_check - if you want to check if machine is
> registered to cdn, you have to grep output from "subscription-manager
> status" (and similarly for other states)

"status" may be the wrong module here -- it's intended to be used to check the status of products and subscriptions, not registration. "identity" may be better in this case.
Error codes have been added to the status command (as stated in the previous post), but will be changing in the near future to better indicate the system's overall subscription status.


>   * same as previous point - is subscribed to pool
>   * output from subscription-manager repos --list is not easily processable,
> because it is on multiple lines (I know that there is empty line as
> separator...)

The format here hasn't been changed.


>   All previous features should return proper exit code.

Error code output, in general, has been modified to be more standard across the board.

Comment 6 John Sefler 2014-11-21 22:30:13 UTC
Verifying Version...
[root@jsefler-os7 ~]# rpm -q subscription-manager
subscription-manager-1.13.9-1.el7.x86_64

>   * alternative for rhn_check - if you want to check if machine is
> registered to cdn, you have to grep output from "subscription-manager
> status" (and similarly for other states)
subscription-manager status is NOT a good command to check if a machine is registered (has a consumer cert).  A better call for this query is subscription-manager identity.

[root@jsefler-os7 ~]# ls /etc/pki/consumer
cert.pem  key.pem
[root@jsefler-os7 ~]# subscription-manager identity
system identity: fe276cb2-76a2-4285-98ce-c8bad57fd1b0
name: jsefler-os7.usersys.redhat.com
org name: Quality Assurance
org ID: 711497
[root@jsefler-os7 ~]# echo $?
0
^ VERIFIED: an exit code of 0 was returned for a system with consumer cert.

[root@jsefler-os7 ~]# subscription-manager unregister
System has been unregistered.
[root@jsefler-os7 ~]# ls /etc/pki/consumer
[root@jsefler-os7 ~]# subscription-manager identity
This system is not yet registered. Try 'subscription-manager register --help' for more information.
[root@jsefler-os7 ~]# echo $?
1
^ VERIFIED: an exit code of 1 was returned for a system without a consumer cert.


A more accurate replacement for rhn_check is /usr/libexec/rhsmcertd-worker


>   * same as previous point - is subscribed to pool
Nothing new has been implemented to address this query.  However, RFE bug 1146125 may be useful.


>   * output from subscription-manager repos --list is not easily processable,
> because it is on multiple lines (I know that there is empty line as
> separator...)
Nothing new has been implemented to address this request.  However, RFE bug 1119648 may be useful


>   All previous features should return proper exit code.
As indicated in comment 3, many many many changes have been made to the exitCodes returned by subscription-manager and the chosen output stream for feedback (stdout vs stderr).  It's impossible to demonstrate all the changes here.  Prior to this bug, the exitCodes returned by subscription manager were either 0,1,2, or 255 where 0 indicated success, 1 indicated that something did not happen (e.g. no entitlement was granted by autosubscribe), 2 indicated a python error, and 255 indicated an bad error.  The exitCode for errors are now subdivided by new exit code constants defined by python: 

78 EX_CONFIG
65 EX_DATAERR
70 EX_SOFTWARE
64 EX_USAGE
69 EX_UNAVAILABLE

Here is one example...
[root@jsefler-os7 ~]# subscription-manager orgs --username=foo --password=bar
Invalid username or password. To create a login, please visit https://www.redhat.com/wapps/ugc/register.html
[root@jsefler-os7 ~]# echo $?
70


Moving to VERIFIED

Comment 7 John Sefler 2014-12-01 17:17:09 UTC
(In reply to Chris Rog from comment #4)
> Error codes have been added to the status command (as stated in the previous
> post), but will be changing in the near future to better indicate the
> system's overall subscription status.

I believe the near future occurred in subscription-manager commit 13fe8ffd8f876d27079b961fb6675424e65b9a10 which will be available in subscription-manager-1.13.10-1.

Comment 8 William Poteat 2015-01-16 14:56:50 UTC
*** Bug 1171602 has been marked as a duplicate of this bug. ***

Comment 10 errata-xmlrpc 2015-03-05 13:17:37 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.

https://rhn.redhat.com/errata/RHBA-2015-0502.html