Add Id and Name properties to Redfish resources.
This change adds the `Id` and `Name` properties to the `Task`, `UpdateService`, and `SoftwareInventory` resources. It also refactors error handling in `task_service.cc` to use `SetToInternalError`.
Id and Name are required fields in Redfish.
#bmc-bloom
PiperOrigin-RevId: 805046269
Change-Id: If68e2c6f28b565a6ea78e883b195b87efa737938
diff --git a/tlbmc/redfish/routes/task_service.cc b/tlbmc/redfish/routes/task_service.cc
index e5f7cfb..86623f7 100644
--- a/tlbmc/redfish/routes/task_service.cc
+++ b/tlbmc/redfish/routes/task_service.cc
@@ -30,6 +30,8 @@
resp.SetKeyInJsonBody("/@odata.type", "#Task.v1_4_2.Task");
resp.SetKeyInJsonBody("/@odata.id",
"/redfish/v1/TaskService/Tasks/FirmwareBundleUpdate");
+ resp.SetKeyInJsonBody("/Id", "FirmwareBundleUpdate");
+ resp.SetKeyInJsonBody("/Name", "Firmware Bundle Update");
// Set default values for the task state and percent completed.
resp.SetKeyInJsonBody("/TaskState", "New");
@@ -42,15 +44,15 @@
std::string content((std::istreambuf_iterator<char>(status_file)),
std::istreambuf_iterator<char>());
if (!status_file.good()) {
- resp.SetToAbslStatus(absl::InternalError(absl::StrCat(
- "Failed to read status file: ", status_file_path.c_str())));
+ resp.SetToInternalError(absl::StrCat(
+ "Failed to read status file: ", status_file_path.c_str()));
return;
}
nlohmann::json status_json = nlohmann::json::parse(content, nullptr, false);
if (status_json.is_discarded()) {
- resp.SetToAbslStatus(absl::InternalError(absl::StrCat(
- "Failed to parse status file as JSON: ", kProgressStatusPath)));
+ resp.SetToInternalError(absl::StrCat(
+ "Failed to parse status file as JSON: ", kProgressStatusPath));
return;
}
diff --git a/tlbmc/redfish/routes/update_service.cc b/tlbmc/redfish/routes/update_service.cc
index b5b0a88..572d764 100644
--- a/tlbmc/redfish/routes/update_service.cc
+++ b/tlbmc/redfish/routes/update_service.cc
@@ -25,6 +25,8 @@
void HandleUpdateService(const RedfishRequest& req, RedfishResponse& resp) {
resp.SetKeyInJsonBody("/@odata.id", "/redfish/v1/UpdateService");
resp.SetKeyInJsonBody("/@odata.type", "#UpdateService.v1_8_0.UpdateService");
+ resp.SetKeyInJsonBody("/Id", "UpdateService");
+ resp.SetKeyInJsonBody("/Name", "Update Service");
resp.SetKeyInJsonBody("/ServiceEnabled", true);
resp.SetKeyInJsonBody("/FirmwareInventory/@odata.id",
"/redfish/v1/UpdateService/FirmwareInventory");
@@ -42,6 +44,7 @@
"/@odata.type",
"#SoftwareInventoryCollection.SoftwareInventoryCollection");
resp.SetKeyInJsonBody("/Name", "SoftwareInventoryCollection");
+ resp.SetKeyInJsonBody("/Id", "FirmwareInventory");
resp.SetKeyInJsonBody("/Description", "Firmware Inventory Collection.");
const std::filesystem::path inventory_root =
@@ -83,6 +86,8 @@
absl::StrCat("/redfish/v1/UpdateService/FirmwareInventory/", member));
resp.SetKeyInJsonBody("/@odata.type",
"#SoftwareInventory.v1_2_2.SoftwareInventory");
+ resp.SetKeyInJsonBody("/Id", member);
+ resp.SetKeyInJsonBody("/Name", member);
std::filesystem::path inventory_file_path = std::filesystem::path(root_path) /
"run/install/inventory" / member /
"inventory.json";
@@ -143,6 +148,8 @@
resp.SetKeyInJsonBody("/@odata.type", "#Task.v1_4_2.Task");
resp.SetKeyInJsonBody("/TaskState", "New");
resp.SetKeyInJsonBody("/PercentComplete", 0);
+ resp.SetKeyInJsonBody("/Id", "FirmwareBundleUpdate");
+ resp.SetKeyInJsonBody("/Name", "Firmware Bundle Update");
}
} // namespace internal