Skip to content

Commit

Permalink
Few bug fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Pinto <christian.pinto@ibm.com>
  • Loading branch information
christian-pinto committed Mar 11, 2024
1 parent 78344d8 commit 4a75253
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
7 changes: 5 additions & 2 deletions sunfish/events/redfish_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ def forward_event(self, list, payload):
try:
data = self.core.get_object(path)
# print('send to: ', data["Id"])
requests.post(data['Destination'], json=payload)
except requests.exceptions.ConnectionError as e:
resp = requests.post(data['Destination'], json=payload)
resp.raise_for_status()
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as e:
logger.warning(f"Unable to contact event destination {id} for event , skipping.")
logger.warning(f"Event log: \n{json.dumps(payload, indent=2)}")
list.remove(id)
except ResourceNotFound:
raise ResourceNotFound(path)
Expand Down
3 changes: 3 additions & 0 deletions sunfish/lib/agents_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def _forward_patch_request(self, path: string, payload: dict) -> dict:
logger.debug(f"PATCH request was successful. status code: {r.status_code}, reason {r.reason}")
logger.debug(f"Response payload:\n {json.dumps(r.json(), indent=2)}")
return r.json()
elif r.status_code == 204:
logger.debug(f"PATCH request was successful. status code: {r.status_code}, reason {r.reason}")
return {}
else:
logger.debug(f"PATCH request was unsuccessful. status code: {r.status_code}, reason {r.reason}")
raise AgentForwardingFailure(f"patching object {resource_uri} ", r.status_code, r.reason)
Expand Down
17 changes: 10 additions & 7 deletions sunfish/storage/backend_FS.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ def write(self, payload: dict):
else:
if data[id[index]]:
element = data[id[index]]
if element["@odata.id"] == os.path.join(self.redfish_root, '/'.join(id[:index + 1])):
present = True
else:
element["@odata.id"] = os.path.join(self.redfish_root, '/'.join(id[:index + 1]))
with open(to_check, 'w') as data_json:
json.dump(data, data_json, indent=4, sort_keys=True)
data_json.close()
if type(element) is not list:
continue
for el in element:
if el["@odata.id"] == os.path.join(self.redfish_root, '/'.join(id[:index + 1])):
present = True
else:
el["@odata.id"] = os.path.join(self.redfish_root, '/'.join(id[:index + 1]))
with open(to_check, 'w') as data_json:
json.dump(data, data_json, indent=4, sort_keys=True)
data_json.close()

last_element = len(id) - 1
collection_type = id[last_element - 1]
Expand Down

0 comments on commit 4a75253

Please sign in to comment.