Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 473069869
  • Loading branch information
Matt Russak authored and copybara-github committed Sep 22, 2022
1 parent 487bf16 commit a83fe27
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
10 changes: 3 additions & 7 deletions ecclesia/lib/redfish/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,13 @@ absl::StatusOr<std::unique_ptr<RedfishObject>> GetManagerForRoot(
}

absl::StatusOr<google::protobuf::Duration> GetUptimeForManager(
std::unique_ptr<RedfishObject> mgr_obj) {
if (mgr_obj == nullptr) {
return absl::InternalError("nullptr was passed as `mgr_obj` parameter.");
}

std::optional<absl::Time> dt = mgr_obj->GetNodeValue<PropertyDateTime>();
const RedfishObject &mgr_obj) {
std::optional<absl::Time> dt = mgr_obj.GetNodeValue<PropertyDateTime>();
if (!dt.has_value()) {
return absl::InternalError(UnableToGetPropertyMessage<PropertyDateTime>());
}
std::optional<absl::Time> last_reset_dt =
mgr_obj->GetNodeValue<PropertyLastResetTime>();
mgr_obj.GetNodeValue<PropertyLastResetTime>();
if (!last_reset_dt.has_value()) {
return absl::InternalError(
UnableToGetPropertyMessage<PropertyLastResetTime>());
Expand Down
2 changes: 1 addition & 1 deletion ecclesia/lib/redfish/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ absl::StatusOr<std::unique_ptr<RedfishObject>> GetManagerForRoot(
// Returns an "uptime" for a Manager resource by calculating the duration
// between the current system time and the last reset time.
absl::StatusOr<google::protobuf::Duration> GetUptimeForManager(
std::unique_ptr<RedfishObject> mgr_obj);
const RedfishObject &mgr_obj);

} // namespace ecclesia

Expand Down
2 changes: 1 addition & 1 deletion ecclesia/lib/redfish/manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TEST(RedfishInterface, GetUptimeForManager) {
GetManagerForRoot(rf_intf->GetRoot());
ASSERT_TRUE(manager.ok());
absl::StatusOr<google::protobuf::Duration> uptime =
GetUptimeForManager(*std::move(manager));
GetUptimeForManager(**manager);
ASSERT_TRUE(uptime.ok());
EXPECT_THAT(*uptime, EqualsProto(R"pb(seconds: 974173)pb"));
}
Expand Down
8 changes: 6 additions & 2 deletions ecclesia/lib/redfish/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ namespace ecclesia {

// Helper functions standardizing status messages for frequently-encountered
// errors.
inline std::string UnableToGetAsFreshObjectMessage(absl::string_view uri) {
return absl::StrCat("Unable to get '", uri, "' as fresh object.");
inline std::string UnableToGetAsFreshObjectMessage(
std::optional<absl::string_view> uri) {
if (!uri.has_value()) {
return absl::StrCat("Unable to get fresh object for unspecified URI.");
}
return absl::StrCat("Unable to get '", *uri, "' as fresh object.");
}
inline std::string UnableToGetAsObjectMessage(absl::string_view property_name) {
return absl::StrCat("Unable to get '", property_name, "' as object.");
Expand Down

0 comments on commit a83fe27

Please sign in to comment.