Bug 1391362

Summary: [RFE] The return code of 'subscription-manager status' should be 0 when the command is executed successfully
Product: Red Hat Enterprise Linux 7 Reporter: qianzhan
Component: subscription-managerAssignee: candlepin-bugs
Status: CLOSED DEFERRED QA Contact: John Sefler <jsefler>
Severity: low Docs Contact:
Priority: low    
Version: 7.5CC: csnyder, dahorak, kladiv, redakkan, skallesh, wpoteat
Target Milestone: pre-dev-freezeKeywords: FutureFeature, Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1551413 1598042 (view as bug list) Environment:
Last Closed: 2021-01-12 15:58:17 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:
Bug Depends On:    
Bug Blocks: 1551413, 1598042    

Description qianzhan 2016-11-03 07:46:13 UTC
Description of problem:
The return code of 'subscription-manager status' should be 0 when the command is executed successfully

Version-Release number of selected component (if applicable):
subscription-manager: 1.18.3-1.el6
python-rhsm: 1.18.4-1.el6


How reproducible:
always

Steps to Reproduce:
1. Install RHEL-6.9-20161102.n.0

2. Run sub-man status command:

[root@dhcp-128-11 ~]# subscription-manager identity
This system is not yet registered. Try 'subscription-manager register --help' for more information.

[root@dhcp-128-11 ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Unknown

[root@dhcp-128-11 ~]# echo $?
1

3. Register and run sub-man status command:

[root@dhcp-128-11 ~]# subscription-manager register
Registering to: subscription.rhsm.stage.redhat.com:443/subscription
Username: new_test
Password: 
The system has been registered with ID: dd5e85e8-7956-4463-bfa5-e1fbf0a2f952 

[root@dhcp-128-11 ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Invalid

Red Hat Enterprise Linux Server:
- Not supported by a valid subscription.

[root@dhcp-128-11 ~]# echo $?
1

4. Auto-attach and run sub-man status command:

[root@dhcp-128-11 ~]# subscription-manager attach


Installed Product Current Status:
Product Name: Red Hat Enterprise Linux Server
Status:       Subscribed

[root@dhcp-128-11 ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Current

[root@dhcp-128-11 ~]# echo $?
0

Actual results:
As step 2 and 3, the return code is 1.

Expected results:
The return code should be 0.

Additional info:

Comment 3 Chris Snyder 2016-11-07 16:16:01 UTC
The request here is to provide a different error code for failure to run status. The issue now is an exit code of 1 can mean two things: invalid status or failure to complete the status command.

Comment 4 John Sefler 2016-11-07 19:53:57 UTC
As part of the work done on Bug 1119688 to improve script-ability, this commit was implemented...

commit 7957b8df95c575e6e8713c2f1a0f8f754e32aed3
https://github.com/candlepin/subscription-manager/pull/1061/files

    1119688: Improved output of the status module
    
    - The status module will now output a non-zero error code if the
      system status cannot be determined or is otherwise not current.


The problem with this implementation as indicated in comment 3 is that we can not distinguish between a status of not "Valid" and failure to execute the status request because both cases return an exit code of 1.


When implementing this RFE, it is my opinion that we should see graduated exit codes for all the different status values.  For example:
0 = "Current"        system.entitlements_valid="valid"
1 = "Invalid"        system.entitlements_valid="invalid"
2 = "Insufficient"   system.entitlements_valid="partial"
3 = "Unknown"        system.entitlements_valid="unknown"

Plus other cases like these which are already implemented:
64 = EX_USAGE - when asking for status ondate yesterday
65 = EX_DATAERR - when asking for status ondate with wrong format

Comment 7 Jan Kurik 2017-12-06 11:38:49 UTC
Red Hat Enterprise Linux 6 is in the Production 3 Phase. During the Production 3 Phase, Critical impact Security Advisories (RHSAs) and selected Urgent Priority Bug Fix Advisories (RHBAs) may be released as they become available.

The official life cycle policy can be reviewed here:

http://redhat.com/rhel/lifecycle

This issue does not meet the inclusion criteria for the Production 3 Phase and will be marked as CLOSED/WONTFIX. If this remains a critical requirement, please contact Red Hat Customer Support to request a re-evaluation of the issue, citing a clear business justification. Note that a strong business justification will be required for re-evaluation. Red Hat Customer Support can be contacted via the Red Hat Customer Portal at the following URL:

https://access.redhat.com/

Comment 10 Claudio 2021-01-11 10:57:03 UTC
+1

Comment 11 Rehana 2021-01-12 15:58:17 UTC
Thank you for opening the bug . We understand the need of improving the return code in the status scenario. We also think that it is a larger issue to solve and not limited to "status" module alone. We will be working with our stakeholders to plan and prioritise the work needed to have a more precise return codes across the tooling in the future . We will be providing more information in the bug when the plan for update in ready .

Closing this bug as part of stale bug policy review and clean up . 

thanks ,
Rehana