From e74245f3351106f317912152667af7a1513fe3d0 Mon Sep 17 00:00:00 2001 From: Leslie Qi Wang Date: Mon, 19 Oct 2020 17:19:45 -0700 Subject: [PATCH] expose manager's Links object to allow caller to further process Signed-off-by: Leslie Qi Wang --- common/types.go | 11 ++++++- redfish/manager.go | 8 ++++++ redfish/manager_test.go | 64 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/common/types.go b/common/types.go index f102ece3..488ac083 100644 --- a/common/types.go +++ b/common/types.go @@ -60,7 +60,16 @@ func (e *Entity) Update(originalEntity reflect.Value, currentEntity reflect.Valu fieldName := originalEntity.Type().Field(i).Name originalValue := originalEntity.Field(i).Interface() currentValue := currentEntity.Field(i).Interface() - if originalValue != currentValue { + if originalValue == nil && currentValue == nil { + continue + } else if originalValue == nil { + payload[fieldName] = currentValue + } else if reflect.TypeOf(originalValue).Kind() != reflect.Map { + if originalValue != currentValue { + // TODO: Handle JSON name being different than field name + payload[fieldName] = currentValue + } + } else if !reflect.DeepEqual(originalValue, currentValue) { // TODO: Handle JSON name being different than field name payload[fieldName] = currentValue } diff --git a/redfish/manager.go b/redfish/manager.go index f706c677..10f07772 100644 --- a/redfish/manager.go +++ b/redfish/manager.go @@ -217,6 +217,10 @@ type Manager struct { // ManagerNetworkProtocol which represents the network services for this // manager. networkProtocol string + // OEMData are all OEM data under top level manager section + OEMData map[string]interface{} + // OEMLinks are all OEM data under link section + OEMLinks map[string]interface{} // PartNumber shall contain a part number assigned by the organization that // is responsible for producing or manufacturing the manager. PartNumber string @@ -304,6 +308,7 @@ func (manager *Manager) UnmarshalJSON(b []byte) error { ManagerForSwitches common.Links ManagerForSwitchesCount int `json:"ManagerForSwitches@odata.count"` ManagerInChassis common.Link + OEM map[string]interface{} `json:"Oem"` } var t struct { temp @@ -315,6 +320,7 @@ func (manager *Manager) UnmarshalJSON(b []byte) error { VirtualMedia common.Link Links linkReference Actions actions + OEM map[string]interface{} `json:"Oem"` } err := json.Unmarshal(b, &t) @@ -327,6 +333,8 @@ func (manager *Manager) UnmarshalJSON(b []byte) error { manager.ethernetInterfaces = string(t.EthernetInterfaces) manager.logServices = string(t.LogServices) manager.networkProtocol = string(t.NetworkProtocol) + manager.OEMData = t.OEM + manager.OEMLinks = t.Links.OEM manager.remoteAccountService = string(t.RemoteAccountService) manager.serialInterfaces = string(t.SerialInterfaces) manager.virtualMedia = string(t.VirtualMedia) diff --git a/redfish/manager_test.go b/redfish/manager_test.go index 77872867..99c12546 100644 --- a/redfish/manager_test.go +++ b/redfish/manager_test.go @@ -6,12 +6,46 @@ package redfish import ( "encoding/json" + "github.com/stmcginnis/gofish/common" + "reflect" "strings" "testing" - - "github.com/stmcginnis/gofish/common" ) +var oemLinksBody = ` + { + "Dell": { + "DellAttributes": [ + { + "@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/Attributes" + }, + { + "@odata.id": "/redfish/v1/Managers/System.Embedded.1/Attributes" + }, + { + "@odata.id": "/redfish/v1/Managers/LifecycleController.Embedded.1/Attributes" + } + ], + "DellAttributes@odata.count": 3, + "DellTimeService": { + "@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/DellTimeService" + } + } + } +` +var oemDataBody = ` + { + "Dell": { + "DelliDRACCard": { + "@odata.context": "/redfish/v1/$metadata#DelliDRACCard.DelliDRACCard", + "@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/DelliDRACCard/iDRAC.Embedded.1-1_0x23_IDRACinfo", + "@odata.type": "#DelliDRACCard.v1_1_0.DelliDRACCard", + "IPMIVersion": "2.0", + "URLString": "https://10.5.1.83:443" + } + } + } +` var managerBody = `{ "@Redfish.Copyright": "Copyright 2014-2019 DMTF. All rights reserved.", "@odata.context": "/redfish/v1/$metadata#Manager.Manager", @@ -92,8 +126,10 @@ var managerBody = `{ ], "ManagerInChassis": { "@odata.id": "/redfish/v1/Chassis/Chassis-1" - } - }, + }, + "Oem": +` + oemLinksBody + +` }, "Actions": { "#Manager.Reset": { "target": "/redfish/v1/Managers/BMC-1/Actions/Manager.Reset", @@ -102,8 +138,10 @@ var managerBody = `{ "GracefulRestart" ] } - } - }` + }, + "Oem": +` + oemDataBody + +` }` // TestManager tests the parsing of Manager objects. func TestManager(t *testing.T) { @@ -146,6 +184,20 @@ func TestManager(t *testing.T) { if result.resetTarget != "/redfish/v1/Managers/BMC-1/Actions/Manager.Reset" { t.Errorf("Invalid Reset target: %s", result.resetTarget) } + + var expectedOEM map[string]interface{} + if err := json.Unmarshal([]byte(oemLinksBody), &expectedOEM); err != nil { + t.Errorf("Failed to unmarshall link body: %v", err) + } + if !reflect.DeepEqual(result.OEMLinks, expectedOEM) { + t.Errorf("Invalid OEM Links: %+v", result.OEMLinks) + } + if err := json.Unmarshal([]byte(oemDataBody), &expectedOEM); err != nil { + t.Errorf("Failed to unmarshall data body: %v", err) + } + if !reflect.DeepEqual(result.OEMData, expectedOEM) { + t.Errorf("Invalid OEM Data: %+v", result.OEMData) + } } // TestManagerUpdate tests the Update call.