diff --git a/redfish/heatermetrics.go b/redfish/heatermetrics.go index 7cec0ec2..bfa3bff4 100644 --- a/redfish/heatermetrics.go +++ b/redfish/heatermetrics.go @@ -96,9 +96,9 @@ func GetHeaterMetrics(c common.Client, uri string) (*HeaterMetrics, error) { return &heatermetrics, nil } -// ListReferencedHeaterMetricss gets the collection of HeaterMetrics from +// ListReferencedHeaterMetrics gets the collection of HeaterMetrics from // a provided reference. -func ListReferencedHeaterMetricss(c common.Client, link string) ([]*HeaterMetrics, error) { +func ListReferencedHeaterMetrics(c common.Client, link string) ([]*HeaterMetrics, error) { var result []*HeaterMetrics if link == "" { return result, nil diff --git a/redfish/thermalmetrics.go b/redfish/thermalmetrics.go index 47c59627..4a6d1bc8 100644 --- a/redfish/thermalmetrics.go +++ b/redfish/thermalmetrics.go @@ -136,7 +136,7 @@ func GetThermalMetrics(c common.Client, uri string) (*ThermalMetrics, error) { // ListReferencedThermalMetricss gets the collection of ThermalMetrics from // a provided reference. -func ListReferencedThermalMetricss(c common.Client, link string) ([]*ThermalMetrics, error) { +func ListReferencedThermalMetrics(c common.Client, link string) ([]*ThermalMetrics, error) { var result []*ThermalMetrics if link == "" { return result, nil diff --git a/redfish/thermalsubsystem.go b/redfish/thermalsubsystem.go index 6fb97a52..5613925e 100644 --- a/redfish/thermalsubsystem.go +++ b/redfish/thermalsubsystem.go @@ -24,27 +24,27 @@ type ThermalSubsystem struct { CoolantConnectorRedundancy []RedundantGroup // CoolantConnectors shall contain a link to a resource collection of type CoolantConnectorCollection that contains // the coolant connectors for this equipment. - coolantConnectors []string + coolantConnectors string // Description provides a description of this resource. Description string // FanRedundancy shall contain redundancy information for the groups of fans in this subsystem. FanRedundancy []RedundantGroup // Fans shall contain a link to a resource collection of type FanCollection. - fans []string + fans string // Heaters shall contain a link to a resource collection of type HeaterCollection. - heaters []string + heaters string // LeakDetection shall contain a link to a resource collection of type LeakDetection. - leakDetection []string + leakDetection string // Oem shall contain the OEM extensions. All values for properties that this object contains shall conform to the // Redfish Specification-described requirements. OEM json.RawMessage `json:"Oem"` // Pumps shall contain a link to a resource collection of type PumpCollection that contains details for the pumps // included in this equipment. - pumps []string + pumps string // Status shall contain any status or health properties of the resource. Status common.Status // ThermalMetrics shall contain a link to a resource collection of type ThermalMetrics. - thermalMetrics []string + thermalMetrics string } // UnmarshalJSON unmarshals a ThermalSubsystem object from the raw JSON. @@ -52,12 +52,12 @@ func (thermalsubsystem *ThermalSubsystem) UnmarshalJSON(b []byte) error { type temp ThermalSubsystem var t struct { temp - CoolantConnectors common.LinksCollection - Fans common.LinksCollection - Heaters common.LinksCollection - LeakDetection common.LinksCollection - Pumps common.LinksCollection - ThermalMetrics common.LinksCollection + CoolantConnectors common.Link + Fans common.Link + Heaters common.Link + LeakDetection common.Link + Pumps common.Link + ThermalMetrics common.Link } err := json.Unmarshal(b, &t) @@ -68,140 +68,47 @@ func (thermalsubsystem *ThermalSubsystem) UnmarshalJSON(b []byte) error { *thermalsubsystem = ThermalSubsystem(t.temp) // Extract the links to other entities for later - thermalsubsystem.coolantConnectors = t.CoolantConnectors.ToStrings() - thermalsubsystem.fans = t.Fans.ToStrings() - thermalsubsystem.heaters = t.Heaters.ToStrings() - thermalsubsystem.leakDetection = t.LeakDetection.ToStrings() - thermalsubsystem.pumps = t.Pumps.ToStrings() - thermalsubsystem.thermalMetrics = t.ThermalMetrics.ToStrings() + thermalsubsystem.coolantConnectors = t.CoolantConnectors.String() + thermalsubsystem.fans = t.Fans.String() + thermalsubsystem.heaters = t.Heaters.String() + thermalsubsystem.leakDetection = t.LeakDetection.String() + thermalsubsystem.pumps = t.Pumps.String() + thermalsubsystem.thermalMetrics = t.ThermalMetrics.String() return nil } // CoolantConnectors gets the coolant connectors for this equipment. func (thermalsubsystem *ThermalSubsystem) CoolantConnectors() ([]*CoolantConnector, error) { - var result []*CoolantConnector - - collectionError := common.NewCollectionError() - for _, uri := range thermalsubsystem.coolantConnectors { - item, err := GetCoolantConnector(thermalsubsystem.GetClient(), uri) - if err != nil { - collectionError.Failures[uri] = err - } else { - result = append(result, item) - } - } - - if collectionError.Empty() { - return result, nil - } - - return result, collectionError + return ListReferencedCoolantConnectors(thermalsubsystem.GetClient(), thermalsubsystem.coolantConnectors) } // Fans gets the fans for this equipment. func (thermalsubsystem *ThermalSubsystem) Fans() ([]*Fan, error) { - var result []*Fan - - collectionError := common.NewCollectionError() - for _, uri := range thermalsubsystem.fans { - item, err := GetFan(thermalsubsystem.GetClient(), uri) - if err != nil { - collectionError.Failures[uri] = err - } else { - result = append(result, item) - } - } - - if collectionError.Empty() { - return result, nil - } - - return result, collectionError + return ListReferencedFans(thermalsubsystem.GetClient(), thermalsubsystem.fans) } // Heaters gets the heaters within this subsystem. func (thermalsubsystem *ThermalSubsystem) Heaters() ([]*Heater, error) { - var result []*Heater - - collectionError := common.NewCollectionError() - for _, uri := range thermalsubsystem.heaters { - item, err := GetHeater(thermalsubsystem.GetClient(), uri) - if err != nil { - collectionError.Failures[uri] = err - } else { - result = append(result, item) - } - } - - if collectionError.Empty() { - return result, nil - } - - return result, collectionError + return ListReferencedHeaters(thermalsubsystem.GetClient(), thermalsubsystem.heaters) } // LeakDetection gets the leak detection system within this chassis. func (thermalsubsystem *ThermalSubsystem) LeakDetection() ([]*LeakDetection, error) { - var result []*LeakDetection - - collectionError := common.NewCollectionError() - for _, uri := range thermalsubsystem.leakDetection { - item, err := GetLeakDetection(thermalsubsystem.GetClient(), uri) - if err != nil { - collectionError.Failures[uri] = err - } else { - result = append(result, item) - } - } - - if collectionError.Empty() { - return result, nil - } - - return result, collectionError + return ListReferencedLeakDetections(thermalsubsystem.GetClient(), thermalsubsystem.leakDetection) } // Pumps gets the pumps for this equipment. func (thermalsubsystem *ThermalSubsystem) Pumps() ([]*Pump, error) { - var result []*Pump - - collectionError := common.NewCollectionError() - for _, uri := range thermalsubsystem.pumps { - item, err := GetPump(thermalsubsystem.GetClient(), uri) - if err != nil { - collectionError.Failures[uri] = err - } else { - result = append(result, item) - } - } - - if collectionError.Empty() { - return result, nil - } - - return result, collectionError + return ListReferencedPumps(thermalsubsystem.GetClient(), thermalsubsystem.pumps) } // ThermalMetrics gets the summary of thermal metrics for this subsystem. -func (thermalsubsystem *ThermalSubsystem) ThermalMetrics() ([]*ThermalMetrics, error) { - var result []*ThermalMetrics - - collectionError := common.NewCollectionError() - for _, uri := range thermalsubsystem.thermalMetrics { - item, err := GetThermalMetrics(thermalsubsystem.GetClient(), uri) - if err != nil { - collectionError.Failures[uri] = err - } else { - result = append(result, item) - } - } - - if collectionError.Empty() { - return result, nil +func (thermalsubsystem *ThermalSubsystem) ThermalMetrics() (*ThermalMetrics, error) { + if thermalsubsystem.thermalMetrics == "" { + return nil, nil } - - return result, collectionError + return GetThermalMetrics(thermalsubsystem.GetClient(), thermalsubsystem.thermalMetrics) } // GetThermalSubsystem will get a ThermalSubsystem instance from the service. diff --git a/redfish/thermalsubsystem_test.go b/redfish/thermalsubsystem_test.go new file mode 100644 index 00000000..8487ee1b --- /dev/null +++ b/redfish/thermalsubsystem_test.go @@ -0,0 +1,65 @@ +// +// SPDX-License-Identifier: BSD-3-Clause +// + +package redfish + +import ( + "encoding/json" + "strings" + "testing" +) + +var thermalSubsystemBody = `{ + "@odata.context": "/redfish/v1/$metadata#ThermalSubsystem.ThermalSubsystem", + "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem", + "@odata.type": "#ThermalSubsystem.v1_2_0.ThermalSubsystem", + "Description": "Represents the properties of a Thermal Subsystem of the Chassis", + "Name": "Thermal Subsystem for Chassis", + "FanRedundancy": [ + { + "RedundancyType": "NPlusM", + "MaxSupportedInGroup": null, + "MinNeededInGroup": null, + "RedundancyGroup": [], + "RedundancyGroup@odata.count": 0, + "Status": { + "State": "Enabled", + "Health": "OK" + } + } + ], + "Fans": { + "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem/Fans" + }, + "ThermalMetrics": { + "@odata.id": "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem/ThermalMetrics" + }, + "Status": { + "State": "Enabled", + "Health": "OK" + }, + "Id": "ThermalSubsystem" + }` + +// TestThermalSubsystem tests the parsing of ThermalSubsystem objects. +func TestThermalSubsystem(t *testing.T) { + var result ThermalSubsystem + err := json.NewDecoder(strings.NewReader(thermalSubsystemBody)).Decode(&result) + + if err != nil { + t.Errorf("Error decoding JSON: %s", err) + } + + if result.ID != "ThermalSubsystem" { + t.Errorf("Received invalid ID: %s", result.ID) + } + + if result.Name != "Thermal Subsystem for Chassis" { + t.Errorf("Received invalid name: %s", result.Name) + } + + if result.fans != "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem/Fans" { + t.Errorf("Invalid fans link: %s", result.fans) + } +}