HewlettPackard / python-ilorest-library

Python library for interacting with devices which support a Redfish Service
Apache License 2.0
187 stars 92 forks source link

Fix logout when using URL with port #134

Closed JohnAZoidberg closed 1 year ago

JohnAZoidberg commented 2 years ago

The following code will fail:

ilo_url = "https://192.168.100.207:443"
client = RedfishClient(base_url=ilo_url, username=username, password=password)
client.login()
client.logout()

with this error:

  File "/home/zoid/cloudhome/hpe/taiwan/venv-GNext/lib/python3.9/site-packages/redfish/rest/v1.py", line 356, in logout
    resp = self.delete(self.session_location)
  File "/home/zoid/cloudhome/hpe/taiwan/venv-GNext/lib/python3.9/site-packages/redfish/rest/v1.py", line 189, in delete
    return self.connection.rest_request(path, method='DELETE',
  File "/home/zoid/cloudhome/hpe/taiwan/venv-GNext/lib/python3.9/site-packages/redfish/rest/connections.py", line 257, in rest_request
    resp = self._conn(method, reqfullpath, **request_args)
  File "/home/zoid/cloudhome/hpe/taiwan/venv-GNext/lib/python3.9/site-packages/urllib3/request.py", line 74, in request
    return self.request_encode_url(
  File "/home/zoid/cloudhome/hpe/taiwan/venv-GNext/lib/python3.9/site-packages/urllib3/request.py", line 96, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "/home/zoid/cloudhome/hpe/taiwan/venv-GNext/lib/python3.9/site-packages/urllib3/poolmanager.py", line 362, in urlopen
    u = parse_url(url)
  File "/home/zoid/cloudhome/hpe/taiwan/venv-GNext/lib/python3.9/site-packages/urllib3/util/url.py", line 394, in parse_url
    return six.raise_from(LocationParseError(source_url), None)
  File "<string>", line 3, in raise_from
urllib3.exceptions.LocationParseError: Failed to parse: https://192.168.100.207:443https:/192.168.100.207/redfish/v1/SessionService/Sessions/admin0000000062b3f0f8b645a1cb/

The reason is that the session URl returned by iLO does not include the port. Therefore the code in the session_location getter:

session_loc = self._session_location.replace(self.base_url, '')

fails to remove the base URL and we end up with a malfored URL as seen above. The fix is to change the session URL based on the base URL.

-----Synopsis of Commits Above-----

Please fill out the following when submitting the PR

Status

Additional High Level Description

A few sentences describing the overall goals of the pull request's commits.

Dependent PRs

List any PRs that must be merged together. (Tool dependent PRs SHOULD NOT occur.)

Before Status can be set to READY I have completed the following:

JohnAZoidberg commented 2 years ago

I care about this because sometimes I use iLO with non-standard port. Or I tunnel access to iLO to https://localhost:4443

rajeevkallur commented 2 years ago

This will be merged in the next release that is 3.6