Skip to content

Commit

Permalink
fix(service): update add-blade\host error handling (#71)
Browse files Browse the repository at this point in the history
Remove the adding of a blade\host to the service's internal map and datastore when the backend create session fails.  This code was inadvertently allowing blades\hosts to be added that were not real.
  • Loading branch information
scott-howe-1 authored Dec 18, 2024
1 parent 9f172e8 commit 8fceb5e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 63 deletions.
32 changes: 0 additions & 32 deletions pkg/manager/appliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package manager
import (
"context"
"fmt"
"strings"

"github.com/google/uuid"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -97,37 +96,6 @@ func (a *Appliance) AddBlade(ctx context.Context, c *openapi.Credentials) (*Blad
if err != nil || response == nil {
newErr := fmt.Errorf("create session failure at [%s:%d] using interface [%s]: %w", c.IpAddress, c.Port, backendName, err)
logger.Error(newErr, "failure: add blade")

bladeId := c.CustomId
if bladeId == "" { // Order CustomeId > BladeSN > UUID
bladeId = response.ChassisSN
if bladeId == "" {
// Generate default id using last N digits of a randomly generated uuid combined with the default prefix
// Example uuid: ee0328d9-258a-4e81-976e-b75aa4a2d8f5
uuid := uuid.New().String()
uuid = strings.ReplaceAll(uuid, "-", "")
bladeId = fmt.Sprintf("%s-%s", ID_PREFIX_BLADE_DFLT, uuid[(len(uuid)-common.NumUuidCharsForId):])
}
c.CustomId = bladeId
}

// Continue adding the failed blade to the datastore, but update the connection status to unavailable
newBlade := &Blade{
Id: c.CustomId,
Uri: GetCfmUriBladeId(a.Id, c.CustomId),
Status: common.UNAVAILABLE,
ApplianceId: a.Id,
backendOps: ops,
creds: c,
}
a.Blades[newBlade.Id] = newBlade

applianceDatum, _ := datastore.DStore().GetDataStore().GetApplianceDatumById(newBlade.ApplianceId)
applianceDatum.AddBladeDatum(c)
unavailabelBlade, _ := applianceDatum.GetBladeDatumById(ctx, c.CustomId)
unavailabelBlade.ConnectionStatus = common.UNAVAILABLE
datastore.DStore().Store()

return nil, &common.RequestError{StatusCode: common.StatusBladeCreateSessionFailure, Err: newErr}
}

Expand Down
31 changes: 0 additions & 31 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ package manager
import (
"context"
"fmt"
"strings"

"github.com/google/uuid"
"k8s.io/klog/v2"

"cfm/pkg/backend"
Expand Down Expand Up @@ -282,35 +280,6 @@ func AddHost(ctx context.Context, c *openapi.Credentials) (*Host, error) {
if err != nil || response == nil {
newErr := fmt.Errorf("create session failure at [%s:%d] using interface [%s]: %w", c.IpAddress, c.Port, backendName, err)
logger.Error(newErr, "failure: add host")

hostId := c.CustomId
if hostId == "" { // Order CustomeId > HostSN > UUID
hostId = response.ChassisSN
if hostId == "" {
// Generate default id using last N digits of the session id combined with the default prefix
// Example uuid: ee0328d9-258a-4e81-976e-b75aa4a2d8f5
uuid := uuid.New().String()
uuid = strings.ReplaceAll(uuid, "-", "")
hostId = fmt.Sprintf("%s-%s", ID_PREFIX_HOST_DFLT, uuid[(len(uuid)-common.NumUuidCharsForId):])
}
c.CustomId = hostId
}

// Continue adding the failed host to the datastore, but update the connection status to unavailable
host := &Host{
Id: c.CustomId,
Uri: GetCfmUriHostId(c.CustomId),
Status: common.UNAVAILABLE,
backendOps: ops,
creds: c,
}
deviceCache.AddHost(host, false)

datastore.DStore().GetDataStore().AddHostDatum(c)
unavailableHost, _ := datastore.DStore().GetDataStore().GetHostDatumById(c.CustomId)
unavailableHost.ConnectionStatus = common.UNAVAILABLE
datastore.DStore().Store()

return nil, &common.RequestError{StatusCode: common.StatusHostCreateSessionFailure, Err: newErr}
}

Expand Down

0 comments on commit 8fceb5e

Please sign in to comment.