Skip to content

Commit

Permalink
Merge pull request #39 from Cray-HPE/bugfix/CASMHMS-5039
Browse files Browse the repository at this point in the history
Power Capping for Bard Peak Nodes CSM v1.2
  • Loading branch information
alvarez3-hpe authored Sep 8, 2021
2 parents b795809 + 5525f2c commit 2d017e5
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.30.15
1.30.16
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.30.16] - 2021-09-07

### Added

- CASMHMS-5039 - Added support for power capping for Bard Peak nodes.
- Workaround for discovery for Bard Peak to correctly discover node BMCs.

### Fixed

- Bulk postgres operations trying to operate on the same row multiple times.

### Changed

- CASMHMS-5041 - Set the 'Name' field in the power control struct for Apollo 6500.

## [1.30.15] - 2021-08-24

### Changed
Expand Down
113 changes: 96 additions & 17 deletions internal/hmsds/hmsds-tx-postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,21 @@ func (t *hmsdbPgTx) InsertComponentsTx(comps []*base.Component) ([]string, error
if !t.IsConnected() {
return []string{}, ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(compTable).
Columns(compColsDefault...)

for _, c := range comps {
// Normalize key
normID := base.NormalizeHMSCompID(c.ID)
// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[normID]; ok {
continue
} else {
valueMap[normID] = true
}
// If NID is not a valid number (e.g. empty string), set to -1.
var rawNID int64
if num, err := c.NID.Int64(); err != nil {
Expand All @@ -761,9 +771,6 @@ func (t *hmsdbPgTx) InsertComponentsTx(comps []*base.Component) ([]string, error
enabledFlg = *c.Enabled
}

// Normalize key
normID := base.NormalizeHMSCompID(c.ID)

// Set fields for the INSERT
query = query.Values(
normID,
Expand Down Expand Up @@ -1384,6 +1391,7 @@ func (t *hmsdbPgTx) BulkUpdateCompNIDTx(comps []base.Component) error {
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

idColAlias := compTableJoinAlias + "." + compIdCol
idFromCol := compTableSubAlias + "." + compIdCol
Expand All @@ -1399,6 +1407,14 @@ func (t *hmsdbPgTx) BulkUpdateCompNIDTx(comps []base.Component) error {
args := make([]interface{}, 0, 1)
valStr := ""
for i, c := range comps {
// Normalize key
normID := base.NormalizeHMSCompID(c.ID)
// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[normID]; ok {
continue
} else {
valueMap[normID] = true
}
// NID must be given. DB uses value for -1 for no NID, client should
// send negative value to unset NID.
var rawNID int64
Expand All @@ -1409,8 +1425,6 @@ func (t *hmsdbPgTx) BulkUpdateCompNIDTx(comps []base.Component) error {
} else {
rawNID = num
}
// Normalize key
normID := base.NormalizeHMSCompID(c.ID)
// Add the values to our values table
if i == 0 {
valStr += "(?,?::BIGINT)"
Expand Down Expand Up @@ -2064,11 +2078,23 @@ func (t *hmsdbPgTx) BulkInsertHWInvByLocTx(hls []*sm.HWInvByLoc) error {
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(hwInvLocTable).
Columns(hwInvLocCols...)

for _, hl := range hls {
// Normalize key
normID := base.NormalizeHMSCompID(hl.ID)

// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[normID]; ok {
continue
} else {
valueMap[normID] = true
}

// If a location is empty, the fru_id field will be NULL.
if hl.PopulatedFRU != nil {
if hl.PopulatedFRU.FRUID == "" {
Expand All @@ -2084,8 +2110,6 @@ func (t *hmsdbPgTx) BulkInsertHWInvByLocTx(hls []*sm.HWInvByLoc) error {
t.LogAlways("Error: BulkInsertHWInvByLocTx(): EncodeLocationInfo: %s", err)
return err
}
// Normalize key
normID := base.NormalizeHMSCompID(hl.ID)

// Get the parent node xname for use with partition queries. Components under nodes
// (processors, memory, etc.) get the parent_node set to the node above them. For
Expand Down Expand Up @@ -2174,11 +2198,20 @@ func (t *hmsdbPgTx) BulkInsertHWInvByFRUTx(hfs []*sm.HWInvByFRU) error {
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(hwInvFruTable).
Columns(hwInvFruTblCols...)

for _, hf := range hfs {
// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[hf.FRUID]; ok {
continue
} else {
valueMap[hf.FRUID] = true
}

infoJSON, err := hf.EncodeFRUInfo()
if err != nil {
t.LogAlways("Error: BulkInsertHWInvByFRUTx(): EncodeLocationInfo: %s", err)
Expand Down Expand Up @@ -2754,19 +2787,26 @@ func (t *hmsdbPgTx) InsertRFEndpointsTx(eps []*sm.RedfishEndpoint) error {
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(rfEPsTable).
Columns(rfEPsAllCols...)

for _, ep := range eps {
// Ensure endpoint name is normalized and valid
normID := base.VerifyNormalizeCompID(ep.ID)
// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[normID]; ok {
continue
} else {
valueMap[normID] = true
}
discInfoJSON, err := json.Marshal(ep.DiscInfo)
if err != nil {
// This should never fail
t.LogAlways(" InsertRFEndpointsTx: decode DiscoveryInfo: %s", err)
}
// Ensure endpoint name is normalized and valid
normID := base.VerifyNormalizeCompID(ep.ID)
if normID == "" {
t.LogAlways("InsertRFEndpointsTx(%s): %s", ep.ID, ErrHMSDSArgBadID)
return ErrHMSDSArgBadID
Expand Down Expand Up @@ -2878,6 +2918,7 @@ func (t *hmsdbPgTx) UpdateRFEndpointsTx(eps []*sm.RedfishEndpoint) ([]*sm.Redfis
if !t.IsConnected() {
return newEPs, ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
// Make the column name a sq.Sqlizer so sq will set it as a column name and not a value.
Expand Down Expand Up @@ -2905,13 +2946,20 @@ func (t *hmsdbPgTx) UpdateRFEndpointsTx(eps []*sm.RedfishEndpoint) ([]*sm.Redfis
args := make([]interface{}, 0, 1)
valStr := ""
for i, ep := range eps {
// Normalized key
normID := base.NormalizeHMSCompID(ep.ID)
// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[normID]; ok {
continue
} else {
valueMap[normID] = true
}

discInfoJSON, err := json.Marshal(ep.DiscInfo)
if err != nil {
// This should never fail
t.LogAlways("UpdateRFEndpointsTx: decode DiscoveryInfo: %s", err)
}
// Normalized key
normID := base.NormalizeHMSCompID(ep.ID)
// Add the values to our values table
if i == 0 {
valStr += "(?,?,?,?,?,?,?::BOOL,?,?,?,?::BOOL,?::BOOL,?,?,?::BOOL,?,?::JSON)"
Expand Down Expand Up @@ -3332,23 +3380,33 @@ func (t *hmsdbPgTx) UpsertCompEndpointsTx(ceps *sm.ComponentEndpointArray) error
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(compEPsTable).
Columns(compEPsAllCols...)

for _, cep := range ceps.ComponentEndpoints {
compInfoJSON, err := cep.EncodeComponentInfo()
if err != nil {
// This should never fail
t.LogAlways("UpsertCompEndpointTx: decode CompInfo: %s", err)
}
// Ensure endpoint name is normalized and valid
normID := base.VerifyNormalizeCompID(cep.ID)
if normID == "" {
t.LogAlways("UpsertCompEndpointTx(%s): %s", normID, ErrHMSDSArgBadID)
return ErrHMSDSArgBadID
}

// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[normID]; ok {
continue
} else {
valueMap[normID] = true
}

compInfoJSON, err := cep.EncodeComponentInfo()
if err != nil {
// This should never fail
t.LogAlways("UpsertCompEndpointTx: decode CompInfo: %s", err)
}

// Set fields for the INSERT
query = query.Values(
normID,
Expand Down Expand Up @@ -3654,6 +3712,7 @@ func (t *hmsdbPgTx) UpsertServiceEndpointsTx(seps *sm.ServiceEndpointArray) erro
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(serviceEPsTable).
Expand All @@ -3666,7 +3725,13 @@ func (t *hmsdbPgTx) UpsertServiceEndpointsTx(seps *sm.ServiceEndpointArray) erro
}
// Normalize key
normRFID := base.NormalizeHMSCompID(sep.RfEndpointID)

// Take out duplicates so that we don't get errors for modifying a row multiple times.
key := normRFID + sep.RedfishType
if _, ok := valueMap[key]; ok {
continue
} else {
valueMap[key] = true
}
// Set fields for the INSERT
query = query.Values(
normRFID,
Expand Down Expand Up @@ -3861,6 +3926,7 @@ func (t *hmsdbPgTx) InsertCompEthInterfacesTx(ceis []*sm.CompEthInterfaceV2) err
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(compEthTable).
Expand All @@ -3872,6 +3938,12 @@ func (t *hmsdbPgTx) InsertCompEthInterfacesTx(ceis []*sm.CompEthInterfaceV2) err
if cei.ID == "" {
return ErrHMSDSArgBadArg
}
// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[cei.ID]; ok {
continue
} else {
valueMap[cei.ID] = true
}
if cei.CompID != "" {
cei.CompID = base.VerifyNormalizeCompID(cei.CompID)
if cei.CompID == "" {
Expand Down Expand Up @@ -3972,6 +4044,7 @@ func (t *hmsdbPgTx) InsertCompEthInterfacesCompInfoTx(ceis []*sm.CompEthInterfac
if !t.IsConnected() {
return ErrHMSDSPtrClosed
}
valueMap := make(map[string]bool)

// Generate query
query := sq.Insert(compEthTable).
Expand All @@ -3983,6 +4056,12 @@ func (t *hmsdbPgTx) InsertCompEthInterfacesCompInfoTx(ceis []*sm.CompEthInterfac
if cei.ID == "" {
return ErrHMSDSArgBadArg
}
// Take out duplicates so that we don't get errors for modifying a row multiple times.
if _, ok := valueMap[cei.ID]; ok {
continue
} else {
valueMap[cei.ID] = true
}
if cei.CompID != "" {
cei.CompID = base.VerifyNormalizeCompID(cei.CompID)
if cei.CompID == "" {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/cray-hms-smd/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
description: "Kubernetes resources for cray-hms-smd"
name: "cray-hms-smd"
home: "HMS/hms-smd"
version: 1.30.15
version: 1.30.16
22 changes: 21 additions & 1 deletion pkg/redfish/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type StateRF string
type StatusRF struct {
Health HealthRF `json:"Health"`
HealthRollUp HealthRF `json:"HealthRollUp,omitempty"`
State StateRF `json:"State"`
State StateRF `json:"State,omitempty"`
}

// JSON decoded struct returned from Redfish for a particular set of
Expand Down Expand Up @@ -131,6 +131,10 @@ type SerialInterfaceCollection GenericCollection
// Example: /redfish/v1/Chassis/<chassis_id>/NetworkAdapters
type NetworkAdapterCollection GenericCollection

// JSON decoded collection struct returned from Redfish "Controls"
// Example: /redfish/v1/Chassis/<chassis_id>/Controls
type ControlCollection GenericCollection

type ServiceRoot struct {
OContext string `json:"@odata.context"`
Oid string `json:"@odata.id"`
Expand Down Expand Up @@ -283,6 +287,7 @@ type Chassis struct {
Power ResourceID `json:"Power"`
Assembly ResourceID `json:"Assembly"`
Thermal ResourceID `json:"Thermal"`
Controls ResourceID `json:"Controls"`

Links ChassisLinks `json:"Links"`

Expand Down Expand Up @@ -352,6 +357,21 @@ type HPEPowerLimit struct {
MaximumPowerLimit int `json:"MaximumPowerLimit"`
MinimumPowerLimit int `json:"MinimumPowerLimit"`
} `json:"PowerLimitRanges"`
Name string `json:"Name"`
}

type RFControl struct {
ControlDelaySeconds int `json:"ControlDelaySeconds"`
ControlMode string `json:"ControlMode"`
ControlType string `json:"ControlType"`
Id string `json:"Id"`
Name string `json:"Name"`
PhysicalContext string `json:"PhysicalContext"`
SetPoint int `json:"SetPoint"`
SetPointUnits string `json:"SetPointUnits"`
SettingRangeMax int `json:"SettingRangeMax"`
SettingRangeMin int `json:"SettingRangeMin"`
Status StatusRF `json:"Status"`
}

// Location-specific Redfish properties to be stored in hardware inventory
Expand Down
Loading

0 comments on commit 2d017e5

Please sign in to comment.