Bug 1566147

Summary: Untranslated "HTTP error (%s - %s)" or "HTTP error (%s - %s): %s" is prefixed to the STDERR in some cases
Product: Red Hat Enterprise Linux 7 Reporter: Shwetha Kallesh <skallesh>
Component: subscription-managerAssignee: candlepin-bugs
Status: CLOSED NOTABUG QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: low Docs Contact:
Priority: medium    
Version: 7.5CC: jsefler, khowell, redakkan
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-02-08 15:15:58 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:

Description Shwetha Kallesh 2018-04-11 15:50:30 UTC
Description of problem:

"HTTP error code 400:" is prefixed to the STDERR when you try to auto-attach with an invalid service-level

Version-Release number of selected component (if applicable):
[root@hp-dl380pgen8-02-vm-3 ~]# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 2.3.4-1
subscription management rules: 5.26
subscription-manager: 1.21.2-3.git.33.c63a48b.el7


How reproducible:


Steps to Reproduce:
[root@hp-dl380pgen8-02-vm-3 ~]# subscription-manager register --serverurl shwetha-candlepin.usersys.redhat.com:8443/candlepin
Registering to: shwetha-candlepin.usersys.redhat.com:8443/candlepin
Username: admin
Password: 
Organization: admin
The system has been registered with ID: 6aea353c-6448-41c8-9ef0-c09ea9f64af4
The registered system name is: hp-dl380pgen8-02-vm-3.lab.bos.redhat.com
[root@hp-dl380pgen8-02-vm-3 ~]# subscription-manager subscribe --auto --servicelevel=FOO
HTTP error code 400: Service level "FOO" is not available to units of organization admin.


Actual results:
HTTP error code 400: Service level "FOO" is not available to units of organization admin.

Expected results:
Service level "foo" is not available to units of organization admin.


Additional info:

2018-04-11 11:45:01,681 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=200, requestUuid=cab86b7b-a2cf-4fac-bd9c-2a7722a73ad4, request="GET /candlepin/status"
2018-04-11 11:45:03,374 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=200, requestUuid=7304dadb-afac-41f7-89eb-9b94095b1a91, request="GET /candlepin/consumers/6aea353c-6448-41c8-9ef0-c09ea9f64af4"
2018-04-11 11:45:04,678 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=200, requestUuid=925ff1ac-1276-4815-b5d1-1d7a4e843b1c, request="GET /candlepin/"
2018-04-11 11:45:05,949 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=200, requestUuid=861dfa7e-5a8b-4c0d-8f59-5f29af4409d9, request="GET /candlepin/consumers/6aea353c-6448-41c8-9ef0-c09ea9f64af4/content_overrides"
2018-04-11 11:45:05,954 [INFO] subscription-manager:29653:MainThread @repolib.py:474 - repos updated: Repo updates

Total repo updates: 0
Updated
    <NONE>
Added (new)
    <NONE>
Deleted
    <NONE>
2018-04-11 11:45:05,959 [WARNING] subscription-manager:29653:MainThread @config.py:118 - /etc/ostree/remotes.d does not exist, so unable to save /etc/ostree/remotes.d/redhat.conf
2018-04-11 11:45:05,990 [INFO] subscription-manager:29653:MainThread @dmiinfo.py:75 - Using dmidecode dump file: /dev/mem
2018-04-11 11:45:06,055 [INFO] subscription-manager:29653:MainThread @cache.py:411 - Server does not support packages, skipping profile upload.
2018-04-11 11:45:07,405 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=200, requestUuid=2b1eef0d-9ad4-4d4f-a549-7b426e5b991e, request="GET /candlepin/consumers/6aea353c-6448-41c8-9ef0-c09ea9f64af4/compliance"
2018-04-11 11:45:07,411 [INFO] subscription-manager:29653:MainThread @cert_sorter.py:205 - Product status: valid_products= partial_products= expired_products= unentitled_producs=100000000000060, 1000000000000023, 100000000000011, 27060, 69, 5050, 5051, 917571, 1, 37069, 37068, 213412341237, 37065, 37067, 213412341234, 37062, 100000000000006, 100000000000005, 100000000000002, 100000000000003, 100000000000000, 100000000000001, 213412341236, 100000000000069, 98121, 213412341235, 100000000000020, 37080, 32060, 806, 88888, 900, 908, 37060, 37090, 37091, 801, 6051, 6050, and 37070 future_products= valid_until=None
2018-04-11 11:45:09,129 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=200, requestUuid=01d24264-3942-4532-b743-b4326f12a14d, request="GET /candlepin/consumers/6aea353c-6448-41c8-9ef0-c09ea9f64af4"
2018-04-11 11:45:11,281 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=200, requestUuid=af68f21f-9bc1-49a9-8ba1-887a8416f99b, request="GET /candlepin/consumers/6aea353c-6448-41c8-9ef0-c09ea9f64af4"
2018-04-11 11:45:12,598 [INFO] subscription-manager:29653:MainThread @connection.py:588 - Response: status=400, requestUuid=8c6be8f5-083c-459d-82bf-0058b5835e6f, request="PUT /candlepin/consumers/6aea353c-6448-41c8-9ef0-c09ea9f64af4"
2018-04-11 11:45:12,599 [ERROR] subscription-manager:29653:MainThread @managercli.py:182 - Unable to attach: HTTP error (400 - Bad Request): Service level "FOO" is not available to units of organization admin.
2018-04-11 11:45:12,599 [ERROR] subscription-manager:29653:MainThread @managercli.py:183 - HTTP error (400 - Bad Request): Service level "FOO" is not available to units of organization admin.
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/subscription_manager/managercli.py", line 1596, in _do_command
    attach_service.attach_auto(self.options.service_level)
  File "/usr/lib64/python2.7/site-packages/rhsmlib/services/attach.py", line 31, in attach_auto
    self.cp.updateConsumer(self.identity.uuid, service_level=service_level)
  File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 1051, in updateConsumer
    ret = self.conn.request_put(method, params)
  File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 702, in request_put
    return self._request("PUT", method, params, headers=headers)
  File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 719, in _request
    info=info, headers=headers)
  File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 597, in _request
    self.validateResponse(result, request_type, handler)
  File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 656, in validateResponse
    raise RestlibException(response['status'], error_msg, response.get('headers'))
RestlibException: HTTP error (400 - Bad Request): Service level "FOO" is not available to units of organization admin.

Comment 2 John Sefler 2018-04-11 17:07:06 UTC
This is new behavior as introduced by post subscription-manager commit 630e1a2eb06e6bfacac669ce11f38e228c907ea9 1507030: RestlibExceptions should show they originate server-side

Comment 3 John Sefler 2018-04-11 21:14:17 UTC
Something that we might want to fix....

exceptions.py has a translated message for RESTLIB_MESSAGE = _(u"HTTP error code %s: %s"), but there are other messages from commit 630e1a2eb06e6bfacac669ce11f38e228c907ea9 that are surfacing to the CLI too that are not translated.  e.g. "HTTP error (%s - %s): %s" as demonstrated in the stderr from...

201804111700:19.491 - FINE: ssh root.redhat.com subscription-manager repo-override --repo=label --add=param:value_7890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
201804111700:21.158 - FINE: Stdout: 
201804111700:21.158 - FINE: Stderr: HTTP error (400 - Bad Request): value: size must be between 0 and 255

Comment 4 Alex Wood 2018-04-12 14:32:50 UTC
Note that there are two strings.  "HTTP error (%s - %s)" is in RestlibException.  "HTTP error code %s: %s" is assigned to the constant "RESTLIB_MESSAGE" and marked for translation. and is what is meant to be displayed on the console.  The __str__ on RestlibException is only meant to appear in logs.

There are two solutions here:
1. Mark the string in RestlibException's __str__ as translatable and be done with it.
2. Figure out why the __str__ from RestlibException is bubbling up to the console instead of being displayed using RESTLIB_MESSAGE

Comment 6 Rehana 2021-02-08 15:15:58 UTC
The original request in the bug was not bug , it was change intentionally as per comment 3 . 
The additional request made in comment 4 is a backlog item.

thanks,
Rehana