Extract Redfish Model as the FRU name for Fast-Sanity GetAllFrus RPC
#tlbmc-fast-sanity
PiperOrigin-RevId: 783128300
Change-Id: I8fe389aeb26a8f2788e6a594457a429d88138a56
diff --git a/tlbmc/service/fru_service.cc b/tlbmc/service/fru_service.cc
index f80ce21..30af4f7 100644
--- a/tlbmc/service/fru_service.cc
+++ b/tlbmc/service/fru_service.cc
@@ -141,12 +141,24 @@
return FruComponent::STATUS_OK;
}
+// Returning empty string here is intentional, which will be used as the
+// `short_name` when there is no model name.
+std::string ExtractFruModelName(const nlohmann::json &fru) {
+ if (!fru.contains("Model")) {
+ return "";
+ }
+ return fru["Model"];
+}
+
FruComponent BuildFruComponent(absl::string_view devpath,
+ absl::string_view model_name,
FruComponentStatus status) {
FruComponent fru;
fru.mutable_primary_identifier()->set_value(devpath);
fru.mutable_primary_identifier()->set_type(
UniqueIdentifierType::UNIQUE_IDENTIFIER_TYPE_LOCAL_DEVPATH);
+ fru.mutable_primary_identifier()->mutable_short_names()->Add(
+ std::string(model_name));
fru.set_status(status);
return fru;
}
@@ -164,8 +176,6 @@
"Invalid location info in the Redfish response.");
}
- FruComponentStatus status = ExtractFruStatus(json);
-
const auto &res_member_location = json["Location"];
std::string service_label =
res_member_location["PartLocation"]["ServiceLabel"];
@@ -199,12 +209,15 @@
kLocalRootChassisLocationCode.length());
}
+ FruComponentStatus status = ExtractFruStatus(json);
+ std::string model_name = ExtractFruModelName(json);
+
return BuildFruComponent(
absl::StrFormat(
"/%s/%s%s", kLocalRootChassisLocationCode,
(!part_location_context.empty() ? part_location_context + "/" : ""),
service_label),
- status);
+ model_name, status);
}
void GenerateFruComponentsFromRedfishObject(
@@ -361,7 +374,7 @@
// corresponding FRU into the list, as some platforms do not have a root
// chassis location code to be identified as a devpath.
FruComponent root_fru_component =
- BuildFruComponent(absl::StrCat("/", kLocalRootChassisLocationCode),
+ BuildFruComponent(absl::StrCat("/", kLocalRootChassisLocationCode), "",
FruComponent::STATUS_OK);
fru_components->AddFruComponent(std::move(root_fru_component));