Sushy Json Parsing Error while using Basic Authentication

Bug #1757464 reported by keerthivasan selvaraj
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sushy
Invalid
Undecided
Unassigned

Bug Description

I am trying to use sushy for getting the basic hardware health.

Tried using basic authentication ( with ssl verification false ).

Steps to reproduce:
-------------------

Sushy version : 1.3.1

sout = sushy.Sushy('https://x.x.x.x/redfish/v1',
                username='xxxx',
                password='xxxx',verify=False)

print sout
out=sout.get_system('/redfish/v1/Systems/1')
print out

Got below error:
----------------

  File "/usr/local/lib/python2.7/dist-packages/sushy/main.py", line 86, in __init__
    self._auth.authenticate()
  File "/usr/local/lib/python2.7/dist-packages/sushy/auth.py", line 58, in authenticate
    self._do_authenticate()
  File "/usr/local/lib/python2.7/dist-packages/sushy/auth.py", line 215, in _do_authenticate
    super(SessionOrBasicAuth, self)._do_authenticate()
  File "/usr/local/lib/python2.7/dist-packages/sushy/auth.py", line 149, in _do_authenticate
    session_service = self._root_resource.get_session_service()
  File "/usr/local/lib/python2.7/dist-packages/sushy/main.py", line 138, in get_session_service
    redfish_version=self.redfish_version)
  File "/usr/local/lib/python2.7/dist-packages/sushy/resources/sessionservice/sessionservice.py", line 54, in __init__
    connector, identity, redfish_version)
  File "/usr/local/lib/python2.7/dist-packages/sushy/resources/base.py", line 239, in __init__
    self.refresh()
  File "/usr/local/lib/python2.7/dist-packages/sushy/resources/base.py", line 269, in refresh
    self._json = self._conn.get(path=self._path).json()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 884, in json
    self.content.decode(encoding), **kwargs
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 516, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

Actual Result:
---------------

It should give sushy connection object to get various data.

Workaround:
------------

While applying debugger, please find the below snipets

sout = sushy.Sushy('https://x.x.x.x/redfish/v1',
                username='xxxx',
                password='xxxx',verify=False)

> /usr/local/lib/python2.7/dist-packages/sushy/main.py(86)__init__()
-> self._auth.authenticate()
--> ()
HTTP request: GET https://x.x.x.x/redfish/v1/SessionService; headers: {}; body: None
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

<<

HTTP response for GET https://x.x.x.x/redfish/v1/SessionService: status code: 401, error: Base.1.0.0.GeneralError: unknown error

<<

Received access error "HTTP GET https://x.x.x.x/redfish/v1/SessionService returned code 401. Base.1.0.0.GeneralError: unknown error". Unable to refresh SessionService.

HTTP request: POST https://x.x.x.x/redfish/v1/SessionService/Sessions; headers: {'Content-Type': 'application/json', 'X-Auth-Token': None}; body: {"UserName": "x.x.x.x", "Password": "x.x.x.x"}

<<

/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
HTTP response for POST https://x.x.x.x/redfish/v1/SessionService/Sessions: status code: 401, error: Base.1.0.0.GeneralError: unknown error
Received exception "HTTP POST https://x.x.x.x/redfish/v1/SessionService/Sessions returned code 401. Base.1.0.0.GeneralError: unknown error" while attempting to establish a session. Falling back to basic authentication.

After this execution reaches main program

<<
out=sout.get_system('/redfish/v1/Systems/1')
HTTP request: GET https://x.x.x.x/redfish/v1/Systems/1; headers: {}; body: None
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
HTTP response for GET https://x.x.x.x/redfish/v1/Systems/1: status code: 200

Execution completed without any errors

Received representation of System /redfish/v1/Systems/1: {u'SKU': u'Default string', u'BiosVersion': u'xxx', u'PowerState': u'On', u'Processors': {<email address hidden>': u'/redfish/v1/Systems/1/Processors'}, u'SerialNumber': u'', u'Boot': {u'BootSourceOverrideTarget': u'None', <email address hidden>': [u'None', u'Pxe', u'Hdd', u'Diags', u'Cd', u'BiosSetup', u'FloppyRemovableMedia', u'UsbKey', u'UsbHdd', u'UsbFloppy', u'UsbCd', u'UefiUsbKey', u'UefiCd', u'UefiHdd', u'UefiUsbHdd', u'UefiUsbCd'], u'BootSourceOverrideEnabled': u'Disabled'}, u'PartNumber': u'', u'ProcessorSummary': {u'Count': 20, u'Status': {u'State': u'Enabled', u'Health': u'OK'}, u'Model': u'Intel(R) Xeon(R) processor'}, <email address hidden>': u'#ComputerSystem.ComputerSystem', u'Description': u'Description of server', <email address hidden>': u'/redfish/v1/$metadata#ComputerSystem.ComputerSystem', u'Manufacturer': u'Supermicro', u'Status': {u'State': u'Enabled', u'Health': u'OK'}, u'Name': u'System', u'SimpleStorage': {<email address hidden>': u'/redfish/v1/Systems/1/SimpleStorage'}, u'Storage': {<email address hidden>': u'/redfish/v1/Systems/1/Storage'}, <email address hidden>': u'/redfish/v1/Systems/1', u'IndicatorLED': u'Off', u'MemorySummary': {u'Status': {u'State': u'Enabled', u'Health': u'OK'}, u'TotalSystemMemoryGiB': 512}, u'Model': u'xxxxx', u'UUID': u'xxxxx', u'Links': {u'ManagedBy': [{<email address hidden>': u'/redfish/v1/Managers/1'}], u'Chassis': [{<email address hidden>': u'/redfish/v1/Chassis/1'}], u'Oem': {}}, u'SystemType': u'Physical', u'Actions': {u'#ComputerSystem.Reset': {<email address hidden>': [u'On', u'ForceOff', u'GracefulShutdown', u'GracefulRestart', u'ForceRestart', u'Nmi', u'ForceOn'], u'target': u'/redfish/v1/Systems/1/Actions/ComputerSystem.Reset'}}, u'Id': u'1'}

<sushy.resources.system.system.System object at 0x7f0ebfbd9c90>

Tags: redfish sushy
Revision history for this message
deray (debayan-ray) wrote :

>> HTTP response for GET https://x.x.x.x/redfish/v1/SessionService: status code: 401, error: Base.1.0.0.GeneralError: unknown error

this suggests that the SessionService attribute is absent in your server's Redfish version.

There are 2 ways to tackle this scenario:

  - Based on the bug#1754514 we already have a patch (https://review.openstack.org/#/c/552817/) which makes the SessionService attribute as optional (as against to currently being mandatory)

  - When you are already aware of the SessionService attr's absence in your server's Redfish and you only intend to do basic authentication then you can instantiate the Sushy object as:

      import sushy
      from sushy import auth

      basic_auth = auth.BasicAuth(username='xxxx', password='yyyy')
      sout = sushy.Sushy('https://x.x.x.x/redfish/v1', verify=False, auth=basic_auth)

Revision history for this message
keerthivasan selvaraj (keerthiv) wrote :

Thanks deray

Is there any specific reason for the Json Decode Error, while parsing the json output ?

Revision history for this message
Julia Kreger (juliaashleykreger) wrote :

On an error, depending on the BMC, I don't believe a json payload is required. For what it is worth, much of this has received updates over the past few years, so I'm sort of doubtful this issue still exists. The current code path doesn't appear to decode a json payload before evaluating the error type and working to resolve that.

The session auth code path, could potentially encounter an issue on improperly formatted base resource payloads as we do attempt to parse that as a hint where to send the session request, and then only fallback if the value is missing.

Hopefully that provides extra clarity. If there is still an issue on more current sushy as of 2023, please open a new issue.

Changed in sushy:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.