Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions python/understack-workflows/understack_workflows/bmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,26 @@ def session_request(
)
if r.text:
token = r.headers["X-Auth-Token"]
if "Location" in r.headers:
location = r.headers["Location"].split(self.ip_address)[1]
data = r.json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if JSON parsing fails?
Shouldn’t we use a try - catch block here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the BMC response is invalid JSON then an Exception will be raised, causing the workflow to fail. While the resulting error won't be especially user-friendly, I think the behaviour is broadly correct. If we are looking to move the needle on "user friendly" for an argo workflow, this is probably not the low-hanging fruit :)


if not token:
raise RedfishRequestError("No token from BMC: %s", r.text)

if "@odata.id" in data:
location = data["@odata.id"]
elif "Location" in r.headers:
location_header = r.headers["Location"]
_parts = location_header.split(self.ip_address)
if len(_parts) < 2:
raise RedfishRequestError(
"Can't parse Location Header %s HTTP %s: %s",
url,
r.status_code,
location_header,
)
location = _parts[1]
else:
location = r.json()["@odata.id"]
raise RedfishRequestError("No location from BMC: %s", r.text)

return (token, location)
else:
Expand Down
Loading