Skip to content

Commit

Permalink
Merge pull request #76 from Cray-HPE/CASMTRIAGE-3430
Browse files Browse the repository at this point in the history
ChassisBMC discovery can't identify child mountain components.
  • Loading branch information
alvarez3-hpe authored Jun 3, 2022
2 parents 6b1ba58 + 928fafc commit a5ad997
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.51.0
1.52.0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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.52.0] - 2022-06-03

### Changed

- HSM now uses the 'Class' from SLS

## [1.51.0] - 2022-05-10

### Changed
Expand Down
25 changes: 19 additions & 6 deletions cmd/smd/components.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// (C) Copyright [2018-2021] Hewlett Packard Enterprise Development LP
// (C) Copyright [2018-2022] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -103,7 +103,15 @@ func (s *SmD) DiscoverComponentChassis(chEP *rf.EpChassis) *base.Component {
comp.Class = base.ClassMountain.String()
// Just incase our redfish endpoint didn't exist when our child
// components were discovered, update them to be Mountain too.
children, err := s.db.GetComponentsQuery(nil, hmsds.FLTR_ID_ONLY, []string{comp.ID})
f := hmsds.ComponentFilter{
Type: []string{
base.NodeBMC.String(),
base.NodeEnclosure.String(),
base.Node.String(),
base.RouterBMC.String(),
},
}
children, err := s.db.GetComponentsQuery(&f, hmsds.FLTR_ID_ONLY, []string{comp.ID})
if err != nil {
s.LogAlways("DiscoverComponentChassis: Could not get child components for %s: %s", comp.ID, err)
} else {
Expand Down Expand Up @@ -174,9 +182,9 @@ func (s *SmD) DiscoverComponentSystem(sysEP *rf.EpSystem) *base.Component {
comp.Subtype = sysEP.Subtype
comp.Arch = sysEP.Arch
comp.NetType = sysEP.NetType
comp.Class = sysEP.DefaultClass

newNID, defRole, defSubRole := s.GetCompDefaults(comp.ID, sysEP.DefaultRole, sysEP.DefaultSubRole)
newNID, defRole, defSubRole, defClass := s.GetCompDefaults(comp.ID, sysEP.DefaultRole, sysEP.DefaultSubRole, sysEP.DefaultClass)
comp.Class = defClass
comp.Role = defRole
comp.SubRole = defSubRole
comp.NID = json.Number(strconv.FormatUint(newNID, 10))
Expand Down Expand Up @@ -328,11 +336,12 @@ func (s *SmD) DiscoverComponentOutlet(outEP *rf.EpOutlet) *base.Component {
}

// Get default NID and Role from SLS or the uploaded NodeMaps in priority order.
func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole string) (uint64, string, string) {
func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole, defaultClass string) (uint64, string, string, string) {
var (
nid uint64
role string
subRole string
class string
)
if s.sls != nil {
nodeInfo, err := s.sls.GetNodeInfo(xname)
Expand All @@ -342,6 +351,7 @@ func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole string) (uint64
nid = uint64(nodeInfo.NID)
role = nodeInfo.Role
subRole = nodeInfo.SubRole
class = nodeInfo.Class
}
}
if nid == 0 || len(role) == 0 {
Expand All @@ -368,7 +378,10 @@ func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole string) (uint64
role = defaultRole
subRole = defaultSubRole
}
return nid, role, subRole
if class == "" {
class = defaultClass
}
return nid, role, subRole, class
}

// Get a bogus nid for an xname
Expand Down
14 changes: 10 additions & 4 deletions cmd/smd/smd-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ func (s *SmD) doComponentsPost(w http.ResponseWriter, r *http.Request) {
// Get the nid and role defaults for all node types
for _, comp := range compsIn.Components {
if comp.Type == base.Node.String() {
if len(comp.Role) == 0 || len(comp.NID) == 0 {
newNID, defRole, defSubRole := s.GetCompDefaults(comp.ID, base.RoleCompute.String(), "")
if len(comp.Role) == 0 || len(comp.NID) == 0 || len(comp.Class) == 0 {
newNID, defRole, defSubRole, defClass := s.GetCompDefaults(comp.ID, base.RoleCompute.String(), "", "")
if len(comp.Role) == 0 {
comp.Role = defRole
}
Expand All @@ -517,6 +517,9 @@ func (s *SmD) doComponentsPost(w http.ResponseWriter, r *http.Request) {
if len(comp.NID) == 0 {
comp.NID = json.Number(strconv.FormatUint(newNID, 10))
}
if len(comp.Class) == 0 {
comp.Class = defClass
}
}
}
}
Expand Down Expand Up @@ -1048,8 +1051,8 @@ func (s *SmD) doComponentPut(w http.ResponseWriter, r *http.Request) {
}
// Get the nid and role defaults for all node types
if component.Type == base.Node.String() {
if len(component.Role) == 0 || len(component.NID) == 0 {
newNID, defRole, defSubRole := s.GetCompDefaults(component.ID, base.RoleCompute.String(), "")
if len(component.Role) == 0 || len(component.NID) == 0 || len(component.Class) == 0 {
newNID, defRole, defSubRole, defClass := s.GetCompDefaults(component.ID, base.RoleCompute.String(), "", "")
if len(component.Role) == 0 {
component.Role = defRole
}
Expand All @@ -1059,6 +1062,9 @@ func (s *SmD) doComponentPut(w http.ResponseWriter, r *http.Request) {
if len(component.NID) == 0 {
component.NID = json.Number(strconv.FormatUint(newNID, 10))
}
if len(component.Class) == 0 {
component.Class = defClass
}
}
}
changeMap, err := s.db.UpsertComponents([]*base.Component{component}, compIn.Force)
Expand Down
33 changes: 24 additions & 9 deletions internal/slsapi/slsapi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// (C) Copyright [2019-2021] Hewlett Packard Enterprise Development LP
// (C) Copyright [2019-2022] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -64,6 +64,13 @@ type ComptypeNode struct {
SubRole string `json:"SubRole"`
}

type NodeInfo struct {
NID int `json:"NID,omitempty"`
Role string `json:"Role"`
SubRole string `json:"SubRole"`
Class string `json:"Class"`
}

var serviceName string

// Allocate and initialize new SLS struct.
Expand Down Expand Up @@ -125,38 +132,46 @@ func (sls *SLS) IsReady() (bool, error) {

// Query SLS for node information. This just picks up the ExtraProperties
// struct for nodes from SLS.
func (sls *SLS) GetNodeInfo(id string) (ComptypeNode, error) {
func (sls *SLS) GetNodeInfo(id string) (NodeInfo, error) {
var nh NodeHardware
// Validate inputs
if sls.Url == nil {
return ComptypeNode{}, fmt.Errorf("SLS struct has no URL")
return NodeInfo{}, fmt.Errorf("SLS struct has no URL")
}
if len(id) == 0 {
return ComptypeNode{}, fmt.Errorf("Id is missing")
return NodeInfo{}, fmt.Errorf("Id is missing")
}

// Construct a GET to /hardware/<xname> for SLS to get the node info
uri := sls.Url.String() + "/hardware/" + id
req, err := http.NewRequest(http.MethodGet, uri, nil)
if err != nil {
return ComptypeNode{}, err
return NodeInfo{}, err
}
body, err := sls.doRequest(req)
if err != nil {
return ComptypeNode{}, err
return NodeInfo{}, err
}

// SLS returns null if the component was not found
if body == nil {
return ComptypeNode{}, nil
return NodeInfo{}, nil
}

err = json.Unmarshal(body, &nh)
if err != nil {
return ComptypeNode{}, err
return NodeInfo{}, err
}

// Grab the fields we care about
nodeInfo := NodeInfo{
NID: nh.ExtraProperties.NID,
Role: nh.ExtraProperties.Role,
SubRole: nh.ExtraProperties.SubRole,
Class: nh.Class,
}

return nh.ExtraProperties, nil
return nodeInfo, nil
}

// doRequest sends a HTTP request to SLS
Expand Down

0 comments on commit a5ad997

Please sign in to comment.